fw-backd.htm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <HTML>
  2. <HEAD>
  3. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
  4. <TITLE>Placing Backdoors Through Firewalls
  5. </TITLE>
  6. </HEAD>
  7. <BODY BGCOLOR="#FFFFFF">
  8. <center>
  9. <h1>
  10. ---[ Placing Backdoors Through Firewalls ]---
  11. <br>
  12. v1.5
  13. </h1>
  14. <br><br>
  15. <table border=3 cellpadding=7 cellspacing=3>
  16. <tr><td>Author: <I><a href="mailto:vh@reptile.rug.ac.be">van Hauser</a> / THC</I><br>
  17. </td></tr>
  18. </table>
  19. </center>
  20. <br><br><br>
  21. ----[ Introduction
  22. <p>
  23. This article describes possible backdoors through different firewall
  24. architectures. However, the material can also be applied to other
  25. environments to describe how hackers (you?) cover their access to a system.
  26. <p>
  27. Hackers often want to retain access to systems they have penetrated
  28. even in the face of obstacles such as new firewalls and patched
  29. vulnerabilities. To accomplish this the attackers must install a
  30. backdoor which a) does it's job and b) is not easily detectable. The
  31. kind of backdoor needed depends on the firewall architecture used.
  32. <p>
  33. As a gimmick and proof-of-concept, a nice backdoor for any kind of
  34. intrusion is included, so have fun.
  35. <p>
  36. <br><br><br>
  37. ----[ Firewall Architectures
  38. <p>
  39. There are two basic firewall architectures and each has an enhanced version.
  40. <p>
  41. Packet Filters:<ul><ul>
  42. This is a host or router which checks each packet against an
  43. allow/deny ruletable before routing it through the correct
  44. interface. There are very simple ones which can only filter
  45. from the origin host, destination host and destination port, as
  46. well as good ones which can also decide based on incoming interface,
  47. source port, day/time and some tcp or ip flags.<br>
  48. This could be a simple router, f.e. any Cisco, or a Linux
  49. machine with firewalling activated (ipfwadm).
  50. </ul></ul><p>
  51. Stateful Filters:
  52. <ul><ul> This is the enhanced version of a packet filter. It
  53. still does the same checking against a rule table and only
  54. routes if permitted, but it also keeps track of the state
  55. information such as TCP sequence numbers. Some pay attention
  56. to application protocols which allows tricks such as only
  57. opening ports to the interiour network for ftp-data channels
  58. which were specified in a permitted ftp session. These
  59. filters can (more or less) get UDP packets (f.e. for DNS and
  60. RPC) securely through the firewall. (Thats because UDP is a
  61. stateless protocol. And it's more difficult for RPC services.)<br>
  62. This could be a great OpenBSD machine with the ip-filter software,
  63. a Cisco Pix, Watchguard, or the (in)famous Checkpoint FW-1.
  64. </ul></ul><p>
  65. Proxies / Circuit Level Gateways:
  66. <ul><ul> A proxy as a firewall host is simply
  67. any server which has no routing activated and instead has
  68. proxy software installe. <br>Examples of proxy servers which may
  69. be used are squid for WWW, a sendmail relay configuration
  70. and/or just a sockd.
  71. </ul></ul><p>
  72. Application Gateways:
  73. <ul><ul> This is the enhanced version of a proxy. Like a proxy, for every
  74. application which should get through the firewall a software must
  75. be installed and running to proxy it. However, the application
  76. gateway is smart and checks every request and answer, f.e. that
  77. an outgoing ftp only may download data but not upload any, and that
  78. the data has got no virus, no buffer overflows are generated in
  79. answers etc. One can argue that squid is an application
  80. gateway, because it does many sanity checks and let you filter
  81. stuff but it was not programmed for the installation in a secure
  82. environment and still has/had security bugs.<br>
  83. A good example for a freeware kit for this kind is the TIS firewall
  84. toolkit (fwtk).
  85. </ul></ul><p>
  86. Most firewalls that vendors sell on the market are hybrid firwalls,
  87. which means they've got more than just one type implemented; for
  88. example the IBM Firewall is a simple packet filter with socks and a
  89. few proxies. I won't discuss which firewall product is the best,
  90. because this is not a how-to-by-a-firewall paper, but I will say this:
  91. application gateways are by far the most secure firewalls,
  92. although money, speed, special protocols, open network policies,
  93. stupidity, marketing hype and bad management might rule them out.
  94. <br><br><br>
  95. ----[ Getting in
  96. <p>
  97. Before we talk about what backdoors are the best for which firewall
  98. architecture we should shed a light on how to get through a firewall
  99. the first time. Note that getting through a firewall is not a plug-n-play
  100. thing for script-kiddies, this has to be carefully planned and done.
  101. <p>
  102. The four main possibilities:
  103. <p>
  104. Insider:
  105. <ul><ul> There's someone inside the company (you, girl/boy-friend, chummer)
  106. who installs the backdoor. This is the easiest way of course.
  107. </ul></ul><p>
  108. Vulnerable Services:
  109. <ul><ul> Nearly all networks offer some kind of services,
  110. such as incoming email, WWW, or DNS. These may be on the
  111. firewall host itself, a host in the DMZ (here: the zone in front
  112. of the firewall, often not protected by a firewall) or on an internal
  113. machine. If an attacker can find a hole in one of those services,
  114. he's got good chances to get in. You'd laugh if you'd see how many
  115. "firewalls" run sendmail for mail relaying ...
  116. </ul></ul><p>
  117. Vulnerable External Server:
  118. <ul><ul> People behind a firewall sometimes work on
  119. external machines. If an attacker can hack these, he can
  120. cause serious mischief such as the many X attacks if the
  121. victim uses it via an X-relay or sshd. The attacker could
  122. also send fake ftp answers
  123. to overflow a buffer in the ftp client software, replace a gif
  124. picture on a web server with one which crashs netscape and
  125. executes a command (I never checked if this actually works, it
  126. crashs, yeah, but I didn't look through this if this is really
  127. an exploitable overflow). There are many possibilities with
  128. this but it needs some knowledge about the company. However,
  129. an external web server of the company is usually a good start.
  130. Some firewalls are configured to allow incoming telnet from
  131. some machines, so anyone can sniff these and get it. This is
  132. particulary true for the US, where academic environments and
  133. industry/military work close together.
  134. </ul></ul><p>
  135. Hijacking Connections:
  136. <ul><ul> Many companies think that if they allow incoming telnet with
  137. some kind of secure authentication like SecureID (secure algo?, he)
  138. they are safe. Anyone can hijack these after the authentication and
  139. get in ... Another way of using hijacked connections is to modify
  140. replies in the protocol implementation to generate a buffer
  141. overflow (f.e. with X).
  142. </ul></ul><p>
  143. Trojans:
  144. <ul><ul> Many things can be done with a trojan horse.
  145. This could be a gzip file which generates a buffer overflow
  146. (well, needs an old gzip to be installed), a tar file which
  147. tampers f.e. ~/.logout to execute something, or an executable
  148. or source code which was modified to get the hacker in somehow.
  149. To get someone running this, mail spoofing could be used or
  150. replacing originals on an external server which internal employees
  151. access to update their software regulary (ftp xfer files and www
  152. logs can be checked to get to know which files these are).
  153. </ul></ul><p>
  154. <br><br><br>
  155. ----[ Placing the Backdoors
  156. <p>
  157. An intelligent hacker will not try to put the backdoors on machines in
  158. the firewall segment, because these machines are usually monitored and
  159. checked regulary. It's the internal machines which are usually unprotected
  160. and without much administration and security checks.
  161. <p>
  162. I will now talk about some ideas of backdoors which could be implemented.
  163. Note that programs which will/would run on an stateful filter will of course
  164. work with a normal packet filter too, same for the proxy. Ideas for an
  165. application gateway backdoor will work for any architecture.<br>
  166. Some of them are "active" and others "passive". "Active" backdoors are those
  167. which can be used by a hacker anytime he wishes, a "passive" one triggers
  168. itself by time/event so an attacker has to wait for this to happen.
  169. <p>
  170. Packet Filters:
  171. <ul><ul> It's hard to find a backdoor which gets through this one but does
  172. not work for any other. The few ones which comes into my mind<br>
  173. is a) the ack-telnet. It works like a normal telnet/telnetd except
  174. it does not work with the normal tcp handshake/protocol but uses
  175. TCP ACK packets only. Because they look like they belong to an
  176. already established (and allowed) connection, they are permitted.
  177. This can be easily coded with the spoofit.h of Coder's Spoofit
  178. project (<A HREF="http://reptile.rug.ac.be/~coder">http://reptile.rug.ac.be/~coder</A>).<br>
  179. b) Loki from Phrack 49/51 could be used too to establish a tunnel
  180. with icmp echo/reply packets. But some coding would be needed to
  181. to be done.<br>
  182. c) daemonshell-udp is a backdoor shell via UDP<br>
  183. (<A HREF="http://www.thc.org">http://www.thc.org</A> look for thc-uht1.tgz)<br>
  184. d) Last but not least, most "firewall systems" with only a screening
  185. router/firewall let any incoming tcp connection from the source port
  186. 20 to a highport (>1023) through to allow the (non-passive) ftp
  187. protocol to work. "netcat -p 20 target port-of-bindshell" is the
  188. fastest solution for this one.
  189. </ul></ul><p>
  190. Stateful Filters:
  191. <ul><ul> Here a hacker must use programs which initiates the connection from
  192. the secure network to his external 0wned server.
  193. There are many out there which could be used:<br>
  194. active:<ul>
  195. tunnel from Phrack 52.<br>
  196. ssh with the -R option (much better than tunnel ... it's
  197. a legtimitate program on a computer and it encrypts the
  198. datastream).
  199. </ul>
  200. passive:<ul>
  201. netcat compiled with the execute option and run with a
  202. time option to connect to the hacker machine (<A HREF="ftp://ftp.avian.org">ftp.avian.org</A>).<br>
  203. reverse_shell from the thc-uht1.tgz package (see above) does the same.
  204. </ul></ul><p>
  205. Proxies / Circuit Level Gateways:
  206. <ul><ul> If socks is used on the firewall, someone can use all those stuff
  207. for the stateful filter and "socksify" them. (<A HREF="www.socks.net.com">www.socks.nec.com</A>)
  208. For more advanced tools you'd should take a look at the application
  209. gateway section.
  210. </ul></ul><p>
  211. Application Gateways:
  212. <ul><ul> Now we get down to the interesting stuff. These beasts can be
  213. intelligent so some brain is needed.<br>
  214. active:<ul>
  215. (re-)placing a cgi-script on the webserver of the company,
  216. which allows remote access. This is unlikely because it's
  217. rare that the webserver is in the network, not monitored/
  218. checked/audited and accessible from the internet. I hope
  219. nobody needs an example on such a thing ;-)<br>
  220. (re-placing) a service/binary on the firewall. This is
  221. dangerous because those are audited regulary and sometimes
  222. even sniffed on permanent ...<br>
  223. Loading a loadable module into the firewall kernel wich
  224. hides itself and gives access to it's master. The best
  225. solution for an active backdoor but still dangerous.
  226. </ul>
  227. passive:<ul>
  228. E@mail - an email account/mailer/reader is configured in a
  229. way to extract hidden commands in an email (X-Headers with
  230. weird stuff) and send them back with output if wanted/needed.<br>
  231. WWW - this is hard stuff. A daemon on an internal machine
  232. does http requests to the internet, but the requests are
  233. in real the answers of commands which were issued by a
  234. rogue www server in a http reply. This nice and easy beast
  235. is presented below (-><A HREF="#example">Backdoor Example: The Reverse WWW Shell</A>)<br>
  236. DNS - same concept as above but with dns queries and
  237. replies. Disadvantage is that it can not carry much data.
  238. (<A HREF="http://www.icon.co.za/~wosp/wosp.dns-tunnel.tar.gz">http://www.icon.co.za/~wosp/wosp.dns-tunnel.tar.gz</A>, this
  239. example needs still much coding to be any effective)
  240. </ul>
  241. </ul></ul><p>
  242. <br><br><br><A NAME="example"></A>
  243. ----[ Backdoor Example: The Reverse WWW Shell
  244. <p>
  245. This backdoor should work through any firewall which has got the security
  246. policy to allow users to surf the WWW (World Wide Waste) for information
  247. for the sake and profit of the company.<br>
  248. For a better understanding take a look at the following picture and try
  249. to remember it onwards in the text:
  250. <pre>
  251. +--------+ +------------+ +-------------+
  252. |internal|--------------------| FIREWALL |--------------|server owned |
  253. | host | internal network +------------+ internet |by the hacker|
  254. +--------+ +-------------+
  255. SLAVE MASTER
  256. </pre>
  257. Well, a program is run on the internal host, which spawns a child every day
  258. at a special time. For the firewall, this child acts like a user, using his
  259. netscape client to surf on the internet. In reality, this child executes
  260. a local shell and connects to the www server owned by the hacker on the
  261. internet via a legitimate looking http request and sends it ready signal.
  262. The legitimate looking answer of the www server owned by the hacker are
  263. in reality the commands the child will execute on it's machine it the
  264. local shell. All traffic will be converted (I'll not call this "encrypted",
  265. I'm not Micro$oft) in a Base64 like structure and given as a value for
  266. a cgi-string to prevent caching.
  267. <pre>
  268. Example of a connection:
  269. Slave
  270. GET /cgi-bin/order?M5mAejTgZdgYOdgIO0BqFfVYTgjFLdgxEdb1He7krj HTTP/1.0
  271. Master replies with
  272. g5mAlfbknz
  273. </pre><p>
  274. The GET of the internal host (SLAVE) is just the command prompt of the
  275. shell, the answer is an encoded "ls" command from the hacker on the
  276. external server (MASTER).
  277. Some gimmicks:<p>
  278. The SLAVE tries to connect daily at a specified time to the MASTER if
  279. wanted; the child is spawned because if the shell hangs for whatever
  280. reason you can check & fix the next day; if an administrator sees connects
  281. to the hacker's server and connects to it himself he will just see a
  282. broken webserver because there's a Token (Password) in the encoded
  283. cgi GET request; WWW Proxies (f.e. squid) are supported; program masks
  284. it's name in the process listing ...
  285. <p>
  286. Best of all: master & slave program are just one 260-lines perl file ...
  287. Usage is simple: edit rwwwshell.pl for the correct values,
  288. execute "rwwwshell.pl slave" on the SLAVE, and just run "rwwwshell.pl"
  289. on the MASTER just before it's time that the slave tries to connect.
  290. <p>
  291. Well, why coding it in perl? a) it was very fast to code, b) it's highly
  292. portable and c) I like it.
  293. If you want to use it on a system which hasn't got perl installed, search
  294. for a similar machine with perl install, get the a3 compiler from the perl
  295. CPAN archives and compile it to a binary. Transfer this to your target
  296. machine and run that one.
  297. <p>
  298. The code for this nice and easy tool is appended in the section THE CODE
  299. after my last words. If you've got updates/ideas/critics for it drop me an
  300. email. If you think this text or program is lame, write me at root@localhost.
  301. Check out <A HREF="http://www.thc.org">http://www.thc.org</A> for updates.
  302. <br><br><br>
  303. ----[ The Source
  304. <p>
  305. Grab it here ...<p>
  306. <ul><A HREF="../releases/rwwwshell-2.0.pl.gz">rwwwshell v2.0</A></ul>
  307. <br><br><br>
  308. ----[ Security
  309. <p>
  310. Now it's an interesting question how to secure a firewall to deny/detect
  311. this. It should be clear that you need a tight application gateway firewall
  312. with a strict policy. email should be put on a centralized mail server,
  313. and DNS resolving only done on the WWW/FTP proxies and access to WWW only
  314. prior proxy authentication. However, this is not enough. An attacker can
  315. tamper the mailreader to execute the commands extracted from the crypted
  316. X-Headers or implement the http authentication into the reverse www-shell
  317. (it's simple). Also checking the DNS and WWW logs/caches regulary with good
  318. tools can be defeated by switching the external servers every 3-20 calls
  319. or use aliases.
  320. <p>
  321. A secure solution would be to set up a second network which is
  322. connected to the internet, and the real one kept seperated - but tell
  323. this the employees ...
  324. A good firewall is a big improvement, and also an Intrusion Detection
  325. Systems can help. But nothing can stop a dedicated attacker.
  326. <p>
  327. <PRE>
  328. ----[ Last Words
  329. Have fun hacking/securing the systems ...
  330. Greets to all guys who like + know me ;-) and especially to those good
  331. chummers I've got, you know who you are.
  332. Ciao...
  333. van Hauser / [THC] - The Hacker's Choice
  334. For further interesting discussions you can email me at
  335. <A HREF="mailto:vh@reptile.rug.be">vh@reptile.rug.ac.be</A> with my public pgp key blow:
  336. Type Bits/KeyID Date User ID
  337. pub 2048/CDD6A571 1998/04/27 van Hauser / THC <vh@reptile.rug.ac.be>
  338. -----BEGIN PGP PUBLIC KEY BLOCK-----
  339. Version: 2.6.3i
  340. mQENAzVE0A4AAAEIAOzKPhKBDFDyeTvMKQ1xx6781tEdIYgrkrsUEL6VoJ8H8CIU
  341. SeXDuCVu3JlMKITD6nPMFJ/DT0iKHgnHUZGdCQEk/b1YHUYOcig1DPGsg3WeTX7L
  342. XL1M4DwqDvPz5QUQ+U+VHuNOUzgxfcjhHsjJj2qorVZ/T5x4k3U960CMJ11eOVNC
  343. meD/+c6a2FfLZJG0sJ/kIZ9HUkY/dvXDInOJaalQc1mYjkvfcPsSzas4ddiXiDyc
  344. QcKX+HAXIdmT7bjq5+JS6yspnBvIZC55tB7ci2axTjwpkdzJBZIkCoBlWsDXNwyq
  345. s70Lo3H9dcaNt4ubz5OMVIvJHFMCEtIGS83WpXEABRG0J3ZhbiBIYXVzZXIgLyBU
  346. SEMgPHZoQHJlcHRpbGUucnVnLmFjLmJlPokAlQMFEDVE0D7Kb9wCOxiMfQEBvpAD
  347. /3UCDgJs1CNg/zpLhRuUBlYsZ1kimb9cbB/ufL1I4lYM5WMyw+YfGN0p02oY4pVn
  348. CQN6ca5OsqeXHWfn7LxBT3lXEPCckd+vb9LPPCzuDPS/zYNOkUXgUQdPo69B04dl
  349. C9C1YXcZjplYso2q3NYnuc0lu7WVD0qT52snNUDkd19ciQEVAwUQNUTQDhLSBkvN
  350. 1qVxAQGRTwgA05OmurXHVByFcvDaBRMhX6pKbTiVKh8HdJa8IdvuqHOcYFZ2L+xZ
  351. PAQy2WCqeakvss9Xn9I28/PQZ+6TmqWUmG0qgxe5MwkaXWxszKwRsQ8hH+bcppsZ
  352. 2/Q3BxSfPege4PPwFWsajnymsnmhdVvvrt69grzJDm+iMK0WR33+RvtgjUj+i22X
  353. lpt5hLHufDatQzukMu4R84M1tbGnUCNF0wICrU4U503yCA4DT/1eMoDXI0BQXmM/
  354. Ygk9bO2Icy+lw1WPodrWmg4TJhdIgxuYlNLIu6TyqDYxjA/c525cBbdqwoE+YvUI
  355. o7CN/bJN0bKg1Y/BMTHEK3mpRLLWxVMRYw==
  356. =MdzX
  357. -----END PGP PUBLIC KEY BLOCK-----
  358. </PRE>
  359. ----[ THE END
  360. </BODY>
  361. </HTML>