Set Up an Anonymous FTP Server


SUBMITTED BY: czzylle

DATE: May 27, 2016, 6:51 a.m.

FORMAT: Text only

SIZE: 22.6 kB

HITS: 435

  1. How to set up a Secure Anonymous FTP Site
  2. The following is a FAQ on setting up a secure FTP Site. FTP sites
  3. are known for much abuse by transferring illegal files. They also open many
  4. oppurtunities for intruders to gain access via misconfigured setups. And
  5. lastly many versions of ftp servers have had security holes. This FAQ is
  6. intended to clean up this abuse by allowing administrators to go through this
  7. check list of steps to make sure their FTP is correctly configured and that
  8. they are running the most current ftp daemon.
  9. This is organized in the following fashion, I am breaking into several parts
  10. as follows:
  11. Part 1 - General Description of Setting up an "anonymous" ftp server.
  12. Part 2 - Setting up a chrooted Secure Anonymous ftp server.
  13. Part 3 - OS Specific needed information and suggestions.
  14. Part 4 - Where to get other FTP daemons
  15. Part 5 - How to Know if your Anonymous FTP Server is secure
  16. Part 6 - Archie
  17. Part 7 - Acknowledgements.
  18. Part 1 - General Description of Setting up an "anonymous" ftp server.
  19. How do I setup "anonymous" ftp securely?
  20. PLEASE READ ALL NOTES AND WARNINGS!!!
  21. 1) Create the user ftp in /etc/passwd. Use a misc group. The user's home
  22. directory will be ~ftp where ~ftp is the root you wish anonymous users to
  23. see. Creating this user turns on anonymous ftp.
  24. Use an invalid password and user shell for better security. The entry in the
  25. passwd file should look something like:
  26. ftp:*:400:400:Anonymous FTP:/home/ftp:/bin/true
  27. 2) Create the home directory ~ftp. Make the directory owned by root (NOT ftp)
  28. with the same group as ftp. Thus, owner permissions are for root and group
  29. permissions are for the anonymous users. Set the permissions for ~ftp to 555
  30. (read, nowrite, execute).
  31. *** Some MAN pages recommend making the ~ftp directory owned by ftp.
  32. *** This is a big NO-NO, if you want any type of security on your system.
  33. 3) Create the directory ~ftp/bin. This directory is owned by root (group
  34. e.g. wheel) with permissions 111 (noread, nowrite, execute).
  35. 4) Copy the program ls into ~ftp/bin. ls is owned by root with permissions
  36. 111 (noread, nowrite, execute). Any other commands you put in ~ftp/bin
  37. should have the same permissions as well.
  38. 5) Make the directory ~ftp/etc. This directory is owned by root with
  39. permissions 111.
  40. 6) Create from scratch the files /etc/passwd and /etc/group in ~ftp/etc.
  41. These files should be mode 444. The passwd file should only contain root,
  42. daemon, uucp, and ftp. The group file must contain ftp's group. Use your
  43. /etc/passwd and /etc/group files as a template for creating passwd and group
  44. files going to ~ftp/etc. You may even change the user names in this file,
  45. they are used only for 'ls' command. So for example if all files in your
  46. ~ftp/pub/linux hierarchy will be maintained by a real user 'balon' with
  47. uid=156 you may put
  48. linux:*:156:120:Kazik Balon::
  49. in the ~ftp/etc/passwd file (regardless of his real username). Leave only
  50. these users who will own files under ftp hierarchy (e.g. root, daemon,
  51. ftp...) and definitely remove *ALL* passwords by replacing them with '*' so
  52. the entry looks like:
  53. root:*:0:0:Ftp maintainer::
  54. ftp:*:400:400: Anonymous ftp::
  55. For more security, you can just remove ~ftp/etc/passwd and
  56. ~ftp/etc/group (the effect is that ls -l will not show the directories' group
  57. names). Wuarchive ftp daemon (and some others) have some extensions based on
  58. the contents of the group/passwd files, so read the appropriate documentation.
  59. 7) Make the directory ~ftp/pub. This directory is owned by you and has the
  60. same group as ftp with permissions 555. On most systems (like SunOS) you may
  61. want to make this directory 2555, ie. set-group-id, in order to create new
  62. files with the same group ownership.
  63. Files are left here for public distribution. All folders inside ~ftp/pub
  64. should have the same permissions as 555.
  65. *** Neither the home directory (~ftp) nor any directory below it should be
  66. owned by ftp! No files should be owned by ftp either. Modern ftp daemons
  67. support all kinds of useful commands, such as chmod, that allow outsiders to
  68. undo your careful permission settings. They also have configuration options
  69. like the following (WuFTP) to disable them:
  70. # all the following default to "yes" for everybody
  71. delete no guest,anonymous # delete permission?
  72. overwrite no guest,anonymous # overwrite permission?
  73. rename no guest,anonymous # rename permission?
  74. chmod no anonymous # chmod permission?
  75. umask no anonymous # umask permission?
  76. 8) If you wish to have a place for anonymous users to leave files, create
  77. the directory ~ftp/pub/incoming. This directory is owned by root with
  78. permissions 733. Do a 'chmod +t ~ftp/pub/incoming'. The ftp daemon will
  79. normally not allow an anonymous user to overwrite an existing file, but a
  80. normal user of the system would be able to delete anything. By setting the
  81. mode to '1733' you prevent this from happening. In wuftpd you may configure
  82. the daemon to create new files with permissions '600' owned by root or any
  83. other user. Many times, incoming directories are abused by exchanging pirated
  84. and pornographic material. Abusers often create hidden directories there for
  85. this purpose. Making the incoming directory unreadable by anonymous ftp helps
  86. to some extent. With ordinary ftp severs there is no way to prevent
  87. directories being created in incoming. The WUarchive ftp server can limit
  88. uploads to certain directories and can restrict characters used in file names
  89. like this:
  90. # specify the upload directory information
  91. upload /var/spool/ftp * no
  92. upload /var/spool/ftp /incoming yes ftp staff 0600 nodirs
  93. # path filters # path-filter...
  94. path-filter anonymous /etc/msgs/pathmsg ^[-A-Za-z0-9_\.]*$ ^\. ^-
  95. path-filter guest /etc/msgs/pathmsg ^[-A-Za-z0-9_\.]*$ ^\. ^-
  96. Suggestion: Create an extra file-system for your ftp-area (or at least for
  97. your incoming-area) to prevent a denial-of-service attack by filling your
  98. disk with garbage (inside your incoming directory).
  99. If you have wuftpd you may want to add some ftp extensions like
  100. compression/decompression 'on the fly' or creation of tar files for the
  101. directory hierarchies. Get the appropriate sources (gzip, gnutar, compress),
  102. compile them and link statically, put in the ~ftp/bin directory and edit the
  103. appropriate file containing the definitions of the allowed conversions.
  104. /usr/bin/tar is already statically-linked. You may wish to use gnu tar
  105. anyway.
  106. Gary Mills wrote a small program to support the following:
  107. I got compress from ftp.uu.net, in the root directory, I believe, and compiled
  108. it. To do tar and compress, I wrote a tiny program called `pipe', and
  109. statically-linked it. My /etc/ftpconversions file looks like this:
  110. #strip prefix:strip postfix:addon prefix:addon postfix:external command:
  111. #types:options:description
  112. :.Z: : :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS
  113. :-z: : :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS
  114. : : :.Z:/bin/compress -c %s:T_REG:O_COMPRESS:COMPRESS
  115. : : :.tar:/bin/tar cf - %s:T_REG|T_DIR:O_TAR:TAR
  116. : : :.tar.Z:/bin/pipe /bin/tar cf - %s | /bin/compress -c:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS
  117. : : :.tar:/bin/gtar -c -f - %s:T_REG|T_DIR:O_TAR:TAR
  118. : : :.tar.Z:/bin/gtar -c -Z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS
  119. : : :.tar.gz:/bin/gtar -c -z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+GZIP
  120. Here it is:
  121. -----------------8<-------------cut---------------
  122. /* pipe.c: exec two commands in a pipe */
  123. #define NULL (char *)0
  124. #define MAXA 16
  125. main(argc, argv) int argc; char *argv[]; {
  126. char *av1[MAXA], *av2[MAXA];
  127. int i, n, p[2], cpid;
  128. i = 0; n = 0;
  129. while ( ++i < argc && n < MAXA ) {
  130. if ( *argv[i] == '|' && *(argv[i]+1) == '\0' ) break;
  131. av1[n++] = argv[i];
  132. }
  133. if ( n == 0 ) uexit();
  134. av1[n] = NULL;
  135. n = 0;
  136. while ( ++i < argc && n < MAXA )
  137. av2[n++] = argv[i];
  138. if ( n == 0 ) uexit();
  139. av2[n] = NULL;
  140. if ( pipe(p) != 0 ) exit(1);
  141. if ( ( cpid = fork() ) == (-1) ) exit(1);
  142. else if ( cpid == 0 ) {
  143. (void)close(p[0]);
  144. (void)close(1);
  145. (void)dup(p[1]);
  146. (void)close(p[1]);
  147. (void)execv(av1[0], av1);
  148. _exit(127);
  149. }
  150. else {
  151. (void)close(p[1]);
  152. (void)close(0);
  153. (void)dup(p[0]);
  154. (void)close(p[0]);
  155. (void)execv(av2[0], av2);
  156. _exit(127); }
  157. /*NOTREACHED*/
  158. }
  159. uexit() {
  160. (void)write(2, "Usage: pipe <command> | <command>\n", 34);
  161. exit(1);
  162. }
  163. 9) Other things to do:
  164. as root: touch ~ftp/.rhosts ~ftp/.forward
  165. chmod 400 ~ftp/.rhosts ~ftp/.forward
  166. ie. make these files zero-length and owned by root.
  167. Due to the last /bin/mail bugs in SunOS:
  168. touch /usr/spool/mail/ftp; chmod 400 /usr/spool/mail/ftp
  169. Consider an email-alias for the ftp-admin(s) to provide an email-address for
  170. problems-reports.
  171. If you are mounting some disks from other machines (or even your own) to the
  172. ~ftp hierarchy, mount it read-only. The correct entry for the /etc/fstab (on
  173. the host with ftpd) is something like:
  174. other:/u1/linux /home/ftp/pub/linux nfs ro,noquota,nosuid,intr,bg 1 0
  175. This mounts under /home/ftp/pub/linux the disk from host 'other' with no
  176. quota, no 'suid' programs (just in case), interruptible (in case 'other'
  177. goes down) and 'bg' - so if 'other' is down when you reboot it will not stop
  178. you trying to mount /home/ftp/pub/linux all over again.
  179. Part 2 - Setting up a chrooted Secure Anonymous ftp server.
  180. This part was contributed by Marcus J Ranum <mjr@tis.com>
  181. Steps
  182. -----
  183. 1) Build a statically linked version of ftpd and put it in ~ftp/bin.
  184. Make sure it's owned by root.
  185. 2) Build a statically linked version of /bin/ls if you'll need one.
  186. Put it in ~ftp/bin. If you are on a Sun, and need to build
  187. one, there's a ported version of the BSD net2 ls command
  188. for SunOs on ftp.tis.com: pub/firewalls/toolkit/patches/ls.tar.Z
  189. Make sure it's owned by root.
  190. 3) Chown ~ftp to root and make it mode 755 THIS IS VERY IMPORTANT
  191. 4) Set up copies of ~ftp/etc/passwd and ~ftp/etc/group just as you would normally, EXCEPT make 'ftp's home directory '/' -- make sure
  192. they are owned by root.
  193. 5) Write a wrapper to kick ftpd off and install it in /etc/inetd.conf
  194. The wrapper should look something like: (assuming ~ftp = /var/ftp)
  195. main()
  196. {
  197. if(chdir("/var/ftp")) {
  198. perror("chdir /var/ftp");
  199. exit(1);
  200. }
  201. if(chroot("/var/ftp")) {
  202. perror("chroot /var/ftp");
  203. exit(1);
  204. }
  205. /* optional: seteuid(FTPUID); */
  206. execl("/bin/ftpd","ftpd","-l",(char *)0);
  207. perror("exec /bin/ftpd");
  208. exit(1);
  209. }
  210. Options:
  211. You can use 'netacl' from the toolkit or tcp_wrappers to achieve
  212. the same effect.
  213. We use 'netacl' to switch so that a few machines that connect to
  214. the FTP service *don't* get chrooted first. This makes transferring
  215. files a bit less painful.
  216. You may also wish to take your ftpd sources and find all the places
  217. where it calls seteuid() and remove them, then have the wrapper do
  218. a setuid(ftp) right before the exec. This means that if someone
  219. knows a hole that makes them "root" they still won't be. Relax and
  220. imagine how frustrated they will be.
  221. If you're hacking ftpd sources, I suggest you turn off a bunch of
  222. the options in ftpcmd.y by unsetting the "implemented" flag in
  223. ftpcmd.y. This is only practical if your FTP area is read-only.
  224. 6) As usual, make a pass through the FTP area and make sure that the files
  225. are in correct modes and that there's nothing else in there that
  226. can be executed.
  227. 7) Note, now, that your FTP area's /etc/passwd is totally separated from
  228. your real /etc/passwd. This has advantages and disadvantages.
  229. 8) Some stuff may break, like syslog, since there is no /dev/log. Either
  230. build a version of ftpd with a UDP-based syslog() routine or
  231. run a second syslogd based on the BSD Net2 code, that maintains
  232. a unix-domain socket named ~ftp/dev/log with the -p flag.
  233. REMEMBER:
  234. If there is a hole in your ftpd that lets someone get "root"
  235. access they can do you some damage even chrooted. It's just
  236. lots harder. If you're willing to hack some code, making the
  237. ftpd run without permissions is a really good thing. The
  238. correct operation of your hacked ftpd can be verified by
  239. connecting to it and (while it's still at the user prompt)
  240. do a ps-axu and verify that it's not running as root.
  241. Part 3 - OS Specific needed information and suggestions.
  242. Older SVR2 and SVR3 system, RTU 6.0 (Masscomp, now Concurrent Real Time UNIX),
  243. AT&T 3B1 and 3B2 machines - May need dev/tcp:
  244. [dev/tcp]
  245. These ftpd implementations may require a ~ftp/dev/tcp in order for anonymous
  246. ftp to work.
  247. You have to create a character special device with the appropriate major and
  248. minor device numbers. The appropriate major and minor numbers of ~ftp/dev/tcp
  249. are what the major and minor numbers of /dev/tcp are.
  250. The ~ftp/dev is a directory and ~ftp/dev/tcp is a character special device.
  251. Make them owned and grouped by root. Permissions for ~ftp/dev is root
  252. read/write/exec and other & group read and exec. The permissions for
  253. ~ftp/dev/tcp is root read/write, other & group read.
  254. HPUX
  255. [Logging] If you're using HP's native ftpd, the line in /etc/inetd.conf
  256. should execute ftpd -l, which does extra logging.
  257. SunOS
  258. [Libraries] To set up SunOS to use its shared dynamic libraries, follow these
  259. steps:
  260. 1) Create the directory ~ftp/usr. This directory is owned by root with
  261. permissions 555.
  262. 2) Create the directory ~ftp/usr/lib. This directory is owned by root with
  263. permissions 555.
  264. 3) Copy the runtime loader ld.so into ~ftp/usr/lib for use by ls. ld.so is
  265. owned by root with permissions 555.
  266. 4) Copy the latest version of the shared C library, libc.so.* into
  267. ~ftp/usr/lib for use by ls.
  268. libc.so.* is owned by root with permissions 555.
  269. ***4.1.2(or above) users: you also need to copy /usr/lib/libdl.so.* to
  270. ~ftp/lib.
  271. 5) Create the directory ~ftp/dev. This directory is owned by root with
  272. permissions 111.
  273. 6) ~ftp/dev/zero is needed by the runtime loader. Move into the directory
  274. ~ftp/dev and create it with the command:
  275. mknod zero c 3 12
  276. chown ~ftp/dev/zero to root. Make sure it's readable.
  277. ***For novices: WARNING!! Don't try to copy /dev/zero to ~ftp/dev/zero!!
  278. This is an endless file of zeroes and it will completely fill your filesystem!
  279. 7) If you want to have the local time showing when people connect, create the
  280. directory ~ftp/usr/share/lib/zoneinfo and copy
  281. /usr/share/lib/zoneinfo/localtime
  282. 8) If you are bothered by the need for copying your libraries so that you can
  283. use Sun's 'ls', which is dynamically linked, you can try to get a statically
  284. linked copy of 'ls' instead. The CD-ROM that contains Sun's OS has a
  285. statically-linked version of ls. In this case, you can dispense with steps
  286. #6-8.
  287. Statically linked versions may be available from the following sources:
  288. If you want a statically linked "ls" get the GNU fileutils off a
  289. archive site near you and statically link it.
  290. [Logging] Sun's standard ftpd logs *all* password information. To correct it,
  291. install patch:
  292. 101640-03 SunOS 4.1.3: in.ftpd logs password info when -d option is
  293. used.
  294. In /etc/inetd.conf find the line that starts with "ftp". At the
  295. end of that line, it should read "in.ftpd". Change that to "in.ftpd -dl".
  296. In /etc/syslog.conf, add a line that looks like:
  297. daemon.* /var/adm/daemonlog
  298. The information can be separated, such as:
  299. daemon.info /var/adm/daemon.info
  300. daemon.debug /var/adm/daemon.debug
  301. daemon.err /var/adm/daemon.err
  302. Note that the whitespace between the two columns must include at least one
  303. TAB character, not just spaces, or it won't work. Of course your log file
  304. could be anything you want. Then, create the logfile (touch
  305. /var/adm/daemonlog should do). Finally, restart inetd and syslogd, either
  306. individually, or by rebooting the system. You should be good to go. If you
  307. do not install the patch, make sure the log file is owned by root and mode
  308. 600, as the ftp daemon will log *everything*, including users' passwords.
  309. *** You want to make all logs root only readable for security reasons
  310. *** If a user mistypes his password for his username, it could be compromised
  311. *** if anyone can read the log files.
  312. Part 4 - Where to get other FTP daemons
  313. Wuarchive FTP 2.4- A secure FTP daemon that allows improved access-control,
  314. logging, pre-login banners, and is very configurable:
  315. Can be ftp'd from ftp.uu.net in "/networking/ftp/wuarchive-ftpd"
  316. directory. Be certain to verify the checksum information to confirm that you
  317. have retrieved a valid copy. [Warning: Older versions of Wu-FTP are extremely
  318. insecure and in some cases have been trojaned.]
  319. BSD SVR4
  320. File Checksum Checksum MD5 Digital Signature
  321. ----------------- -------- --------- --------------------------------
  322. wu-ftpd-2.4.tar.Z 38213 181 20337 362 cdcb237b71082fa23706429134d8c32e
  323. patch_2.3-2.4.Z 09291 8 51092 16 5558a04d9da7cdb1113b158aff89be8f
  324. For DECWRL ftpd, sites can obtain version 5.93 via anonymous FTP
  325. from gatekeeper.dec.com in the "/pub/misc/vixie" directory.
  326. BSD SVR4
  327. File Checksum Checksum MD5 Digital Signature
  328. ----------------- -------- --------- --------------------------------
  329. ftpd.tar.gz 38443 60 1710 119 ae624eb607b4ee90e318b857e6573500
  330. For BSDI systems, patch 005 should be applied to version 1.1 of
  331. the BSD/386 software. You can obtain the patch file via
  332. anonymous FTP from ftp.bsdi.com in the "/bsdi/patches-1.1"
  333. directory.
  334. BSD SVR4
  335. File Checksum Checksum MD5 Digital Signature
  336. ----------------- -------- --------- --------------------------------
  337. BU110-005 35337 272 54935 543 1f454d4d9d3e1397d1eff0432bd383cf
  338. Public Domain Sources:
  339. ftp.uu.net ~ftp/systems/unix/bsd-sources/libexec/ftpd
  340. gatekeeper.dec.com ~ftp/pub/DEC/gwtools/ftpd.tar.Z
  341. Part 5 - How to Know if your Anonymous FTP Server is secure
  342. This section is intended for the administrator to go down a small check
  343. list of things to make sure his server is not easily compromised.
  344. a) Check to make sure your ftp server does not have SITE EXEC command by
  345. telneting to port 21 and typing SITE EXEC. If your ftp daemon has SITE EXEC
  346. make sure it is the most current version (ie, Wu-FTP 2.4). In older versions
  347. this allows anyone to gain shell via port 21.
  348. b) Check to make sure no one can log in and make files or directories in the
  349. main directory. If anyone can log in as anonymous FTP and make files such as
  350. .rhosts and .forward, instant access is granted to any intruder.
  351. c) Check to make sure the main directory is NOT owned by ftp. If it is
  352. owned by FTP, an intruder could SITE CHMOD 777 the main directory and then
  353. plant files to give him instant access. SITE CHMOD command should be removed
  354. because anonymous users do not need any extra priviledges.
  355. d) Check to make sure NO files or directories are owned by ftp. If they are,
  356. it is possible an intruder could replace them with his own trojan versions.
  357. e) There were several bugs in old daemons, so it is very important to make
  358. sure you are running the most current ftp daemons.
  359. Part 6 - Archie
  360. Searches FTP sites for programs. Login into these sites as archie
  361. or use client software for faster access. To get your own anonymous
  362. site added to Archie's search list, e-mail archie-updates@bunyip.com.
  363. archie.ac.il 132.65.20.254 (Israel server)
  364. archie.ans.net 147.225.1.10 (ANS server, NY (USA))
  365. archie.au 139.130.4.6 (Australian Server)
  366. archie.doc.ic.ac.uk 146.169.11.3 (United Kingdom Server)
  367. archie.edvz.uni-linz.ac.at 140.78.3.8 (Austrian Server)
  368. archie.funet.fi 128.214.6.102 (Finnish Server)
  369. archie.internic.net 198.49.45.10 (AT&T server, NY (USA))
  370. archie.kr 128.134.1.1 (Korean Server)
  371. archie.kuis.kyoto-u.ac.jp 130.54.20.1 (Japanese Server)
  372. archie.luth.se 130.240.18.4 (Swedish Server)
  373. archie.ncu.edu.tw 140.115.19.24 (Taiwanese server)
  374. archie.nz 130.195.9.4 (New Zealand server)
  375. archie.rediris.es 130.206.1.2 (Spanish Server)
  376. archie.rutgers.edu 128.6.18.15 (Rutgers University (USA))
  377. archie.sogang.ac.kr 163.239.1.11 (Korean Server)
  378. archie.sura.net 128.167.254.195 (SURAnet server MD (USA))
  379. archie.sura.net(1526) 128.167.254.195 (SURAnet alt. MD (USA))
  380. archie.switch.ch 130.59.1.40 (Swiss Server)
  381. archie.th-darmstadt.de 130.83.22.60 (German Server)
  382. archie.unipi.it 131.114.21.10 (Italian Server)
  383. archie.univie.ac.at 131.130.1.23 (Austrian Server)
  384. archie.unl.edu 129.93.1.14 (U. of Nebraska, Lincoln (USA))
  385. archie.uqam.ca 132.208.250.10 (Canadian Server)
  386. archie.wide.ad.jp 133.4.3.6 (Japanese Server)

comments powered by Disqus