Debian Codegraph @

README

raw
1 /*
2 * hunt
3 *
4 * Copyright (C) 1998 kra
5 * Designed and implemented by kra <[email protected]>
6 *
7 */
8
9
10 DISCLAIMER
11 ----------
12 Authors are not responsible of any damages this software can cause.
13
14
15 READ FIRST
16 ----------
17 Please make sure you KNOW what you are doing before using hunt.
18 It is recommended that you should test how it behaves on some test
19 connections and then use it wisely.
20
21
22 OVERVIEW
23 --------
24 Hunt is a program for intruding into a connection, watching it and resetting
25 it. It has several features, which I didn't find in any product like
26 Juggernaut or T-sight that inspired me in my development.
27 I found Juggernaut not flexible enough for further development so I
28 started from scratch (see FEATURES and DESIGN OVERVIEW).
29 Note that hunt is operating on Ethernet and is best used for connections
30 which can be watched through it. However, it is possible to do something
31 even for hosts on another segments or hosts that are on switched ports.
32 The hunt doesn't distinguish between local network connections and connections
33 going to/from Internet. It can handle all connections it sees.
34
35 Connection hijacking is aimed primarily at the telnet or rlogin traffic but
36 it can be used for another traffic too.
37 The reset, watching, arp, ... features are common to all connections.
38
39
40 FEATURES
41 --------
42 - connection management
43 * setting what connections you are interested in
44 * detecting an ongoing connection (not only SYN started)
45 * Normal active hijacking with the detection of the ACK storm
46 * ARP spoofed/Normal hijacking with the detection of successful
47 ARP spoof
48 * synchronization of the true client with the server after
49 hijacking (so that the connection don't have to be reset)
50 * resetting connection
51 * watching connection
52
53 - daemons
54 * reset daemon for automatic connection resetting
55 * arp spoof/relayer daemon for arp spoofing of hosts with the ability
56 to relay all packets from spoofed hosts.
57 * MAC discovery daemon for collecting MAC addresses
58 * sniff daemon for logging TCP traffic with the ability to search for
59 a particular string
60
61 - host resolving
62 * deferred host resolving through dedicated DNS helper servers.
63
64 - packet engine
65 * extensible packet engine for watching TCP, UDP, ICMP and ARP traffic
66 * collecting TCP connections with sequence numbers and the ACK storm
67 detection.
68 - misc.
69 * determining which hosts are up
70
71 - switched environment
72 * hosts on switched ports can be spoofed, sniffed and hijacked too
73
74
75 -------------------------------------------------------------------------------
76 TECHNICAL EXPLANATION
77 -------------------------------------------------------------------------------
78 Let me explain some technical issues which I use in hunt and which are
79 essential for understanding how it works and what you should expect.
80 The important terms are IP spoofing, ARP spoofing and ACK storm.
81 Even if you are familiar with them, you can get some new information.
82
83 IP spoofing - you set the packet source address to the IP address of
84 the host you pretend to be.
85
86 ARP spoofing - you set the packet source hardware address
87 (source MAC address) to the address of the host you pretend to be.
88
89 Simple Active Attack against TCP connections - It is a well known type
90 of attack in which you send a packet with spoofed IP addresses and possibly
91 also with spoofed ARP addresses (true MAC addresses of client and server - not
92 fake ones as explained further). In this way, you can force a command to the
93 stream but you are likely to receive the ACK storm (as explained further)
94 unless the original client host of the connection is running Linux.
95
96 ARP spoofing - I use this term also for forcing the remote host
97 to think that the host I want to be has a different MAC address so the remote
98 host sends replies to that MAC address and the original client host is not
99 able to receive them (but hunt is watching carefully and handles all
100 consequences) (Explaining how to force a host on the network to think that
101 the other host has a different MAC I leave as an exercise - I encourage you
102 to read the source code). Please note that I use the term ARP spoofing
103 instead of the term ARP forcing or something like that. So don't be confused,
104 if I say ARP spoofing, I mean using some MAC address of a host or just some
105 fake MAC address. Note that ARP spoofing (with my meaning to force some MAC)
106 doesn't work on Solaris2.5 because it has expiration timers on ARP entries
107 so you can't easily force Solaris to drop an ARP entry. The entry usually
108 expires after 20min or less (but you have a chance to force it and hunt
109 supports this mode). The expiration timers on Solaris are set by:
110
111 ndd -set /dev/ip ip_ire_flush_interval 60000 /* 1 min */
112 ndd -set /dev/arp arp_cleanup_interval 60 /* 1 min */
113
114 and I encourage you to ask your netadmin to set the above values on all
115 Solaris machines. The Win95/NT4sp3, Linux2.0, OSF1 V4.0, HP-UX10.20 are not
116 protected in this way so you can easily use the described technique on them
117 (actually, they have timers, but they are not operating like in Solaris;
118 in fact, only Solaris is the exception). Actually, hunt uses this technique
119 such that it wants to force a fake MAC of the server to the client and a fake
120 MAC of the client to the server. Then both the server and the client are
121 sending packets to that faked MACs (and hunt can of course handle them).
122 However, it is sufficient that only one host has a fake MAC of the other host.
123 The ACK storm can't occur in this situation either. So you can use this
124 technique even if one end is Solaris and the other isn't. You will just
125 succeed in the other host and that is enough. So the only problem is when the
126 connection is between two Solaris machines. However, if there is any root
127 connection ongoing you can easily push the commands suggested above without
128 ARP spoofing to the connection and alter the expiration timers of the ARP
129 cache.
130
131
132 ACK Storm - The ACK storm is caused by majority of TCP stacks (!!!
133 Linux2.0 is an exception !!!). Let's imagine that you send some data to an
134 ongoing connection to the server (as if sent by the client - with expected seq.
135 numbers, ... ). The server responds with the acknowledgment of the data you
136 sent but this acknowledgment is received by the original client too. But
137 from the original client point of view, the server has acknowledged data
138 that doesn't exist on the client. So something strange occurred and the
139 original client sends the "right" sequence number with ACK to the server.
140 But the TCP rules say that it is required to generate an immediate
141 acknowledgment when an out-of-order segment is received. This ACK should not
142 be delayed. So the server sends the acknowledgment of non-existent data to the
143 client again. And the client responses, ...
144 Only if the source host of the connection is Linux then the ACK storm
145 doesn't occur. Note that if you use ARP spoofing (forcing) then the ACK
146 storm can't come because one or both ends will send packets with fake
147 MACs and those packets are received by hunt rather than by the other host.
148
149 Connection Reset - with a single properly constructed packet
150 you can reset the connection (RST flag in TCP header). Of course, you have
151 to know the sequence number but it is not a problem for hunt which is watching
152 all the time. You can reset server, client, or both. When you reset
153 only one end the other end is reset when it tries to send data to the
154 first host which will response with RST because of the connection
155 reset on it.
156
157 Connection sniffing/watching - the simplest thing you can do is to
158 silently sit in you chair and watch hunt output about any connection which
159 you choose from the list.
160
161 Connection Synchronization - well, that's one of the main features of
162 hunt. If you put some data to the TCP stream (through simple active attack or
163 ARP spoofing), you desynchronize the stream from the server/original client
164 point of view. After some work done on that connection you can just reset it
165 or you can try to synchronize both original ends again. That is not an
166 easy task. The user on the client is prompted to type some chars and some chars
167 are sent to the client and server. The main goal of all stuff
168 is to synchronize the sequence numbers on both client and server again.
169
170 Switch/Segment traffic rerouting - With ARP spoofing you can
171 even force switch so that it will send you the traffic for hosts
172 on another segment/switched port. This is because a switch will think that
173 the MAC belongs to your port. Be careful if your switch has some security
174 policy and MACs have been explicitly set up on a per port basis - but in
175 fact I don't ever see such a configuration on "ordinary" network.
176
177 ARP-relay daemon - Don't be confused. I use this term for hunt daemon
178 which is responsible for inserting packets to the network (rerouting)
179 of all data it receives from ARP spoofed hosts.
180
181 Switched environment - Well, the hunt is now capable of watching
182 and hijacking hosts that are on switched ports. In common you can't watch
183 the hosts traffic on switched ports but if you first ARP spoof them (with
184 ARP spoof daemon menu) you are able to look at the connections that
185 are between that hosts. First you do arp spoof and the hosts will send you
186 the traffic and from that time you can list the connections between them, then
187 you can watch and hijack them. It is commonly accepted that the switches
188 protect your connections again inside intruders and spoofers. Well, that
189 is still true for carefully setuped switches. The switches that are
190 plugged to the LAN without any port security configuration are useless in
191 the job to protect your LAN.
192
193
194 DESIGN OVERVIEW
195 ---------------
196 The development model is based on a packet engine (hunt.c) which runs
197 in its own thread and captures packets from the network. The packet engine
198 collects information of TCP connections/starting/termination, sequence
199 numbers, and MAC addresses. It collects the MACs and seq. numbers from the
200 server point of view and separate MACs and seq. numbers from the client point
201 of view. So it is prepared for hijacking. This information (seq. num., MAC,
202 ...) is available to modules so they don't have to analyze and collect it.
203
204 Modules can register functions with the packet engine which are then invoked
205 when new packets are received. A module function determines if the module is
206 interested in a packet or not and can place the packet in a module specific
207 list of packets. A module function can also send some packet to the network
208 if it is desirable to do it very fast. The module (usually in some other
209 thread so it needs to be scheduled to be run) then gets packets from the list
210 and analyzes them. In this way, you can easily develop modules which perform
211 various activities.
212
213 Packets to be sent as a response to the network are described by structures
214 so you don't have to care about some default fields or checksums. At this time,
215 functions for TCP, ICMP and ARP traffic are already prepared. (UDP is missing
216 because I don't use it in any module)
217
218 A separate set of daemons is used for host resolving (DNS). That is because
219 the gethostbyname/gethostbyname_r function is protected by mutex
220 (As far as I know - it was so two years ago - I didn't try it now) so you
221 can't run it truly parallel in a multithreaded environment. Therefore, the
222 commonly used workaround is to fire up some helper daemons through fork which
223 will run gethostbyname.
224
225
226 -----------------------------------------------------------------------------
227 USER ENVIRONMENT
228 -----------------------------------------------------------------------------
229
230 Command line parameters
231 -----------------------
232 -V print version
233 -v verbose (print pids of created threads)
234 -i interface listen on this interface. Default is eth0
235
236
237 Well, the user environment isn't graphical but I believe that you will like
238 it.
239
240 In the title of all menus is some status information about hunt.
241 First, there is an indication with which menu you are working. Second, the
242 number of packets received by hunt is shown. Hunt pre-allocates some buffers
243 for packets; the status of free and allocated buffers is displayed as
244 the third value. The number of free buffers is low for a high loaded network
245 or the ACK storm or if you have poor hardware. In my case, for example,
246 the numbers 63/64 were normally indicated meaning that only one buffer was
247 used, but after the ACK storm, I have something like 322/323. Note that the
248 buffers once allocated are not freed. The low number of free buffers can also
249 mean some bug in hunt but I think I carefully debugged all modules to this
250 kind of bug. The last indicator reports which daemons (actually threads)
251 are running. They are: R - reset daemon, Y - arp relayer, S - sniffer,
252 M - MAC discoverer. If you switch on the verbose option you get additional
253 information about how many packets were dropped - they were fragments
254 (see the bugs) or were malformed, and how many packets belong to other
255 protocols than TCP, UDP, ICMP and ARP.
256 In the prompt for user input is indicator that will tell you through '*' char
257 that hunt added new connection(s) to the connection list since last connection
258 listening.
259
260 General interface
261 -----------------
262 In all menus the x key works as escape.
263 The network mask is denoted by the ip_address/mask notation where mask is the
264 number of 1's on the left side of the network mask. For example, 0.0.0.0/0
265 means everything and 192.168.32.10/32 means only that host.
266
267 For most modules is used:
268 l) list items
269 a) add item
270 m) modify item
271 d) delete item
272 They will be referred in this text as l) a) m) d)
273
274
275 List/Watch/Reset connection
276 ---------------------------
277 You can obtain the list of connections tracked by the hunt packet engine.
278 Which connections are tracked is specified in the options menu. You can
279 interactively watch or reset these connections. You can also perform
280 hijacking on them (next two menu items).
281
282 ARP/Simple hijack
283 -----------------
284 ARP/Simple hijack offers you an interactive interface for the insertion of data
285 to the selected connection. You can perform ARP spoofing for both connection
286 ends, for only one end or you can not to do it at all. If you don't do ARP
287 spoofing then you probably receive the ACK storm after typing the first char.
288 When you do ARP spoofing, it is checked if it succeeds. If not, you are
289 prompted if you want to wait until it succeeds (you can interrupt this
290 waiting through CTRL-C of course). After inserting some data to the connection
291 you type CTRL-] and then you can synchronize or reset the connection.
292 If you choose synchronization, the user is prompted to type some chars and
293 after he does so the connection will be in the synchronous state. You can
294 interrupt the synchronization process with CTRL-C and then you can reset
295 the connection. Note that CTRL-C is used widely for interrupting an ongoing
296 process. The CTRL-] (like telnet) is used for finishing the interactive
297 insertion of data to the connection. The ARP/Simple hijack doesn't
298 automatically reset the connection after it detects the ACK storm so you have
299 to do it yourself. Note also that ARP/Simple hijack works with the ARP relayer
300 (as described further) so that other connections are not affected. Normally,
301 if you ARP spoof two servers then the ARP/Simple hijack handles only one
302 selected connection between these two hosts but other connections between
303 these two hosts look like they freeze. If you start the ARP relayer,
304 then these other connections are handled and rerouted through. So other
305 connections from one spoofed host to the other are not affected at all. It is
306 recommended to run ARP relayer if you do ARP hijacking of two servers.
307 Note that if you ARP spoof (force) some client MAC to the server
308 then only connections going from the server to that client are affected. Other
309 connections from the server to other machines are untouched.
310
311 Simple hijack
312 -------------
313 Simple hijack allows you to insert a command to the data stream of the
314 connection. When you insert the command, hunt waits for it to complete up to
315 a certain timeout and if the ACK storm doesn't occur, you are prompted for
316 the next command. After that, you can synchronize or reset the connection.
317 Note that you can use the interactive interface to simple hijack when you use
318 ARP/simple hijack without ARP spoofing but if you use full interactive
319 interface of ARP/simple hijack without ARP spoofing you are likely to get the
320 ACK storm immediately after typing the first char. So this mode of hijacking
321 is useful when you have to deal with the ACK storm because it sends your data
322 to the connection in a single packet. When the ACK storm is in progress it is
323 very hard to deliver other packets from hunt to the server as the network
324 and server are congested.
325
326
327 DAEMONS
328 -------
329 I call them daemons but they are actually threads.
330 All daemons can be started and stooped. Don't be surprised when you
331 insert or modify some rule in a daemon and it does nothing. The daemon is
332 not running - you have to start it. All daemons are by default stopped
333 even though you can alter the configuration. Common commands in the daemons
334 menu are:
335 s) start the daemon
336 k) stop the daemon
337 l) list configuration items
338 a) add config. item
339 m) modify config. item
340 d) delete config. item
341
342
343 Reset daemon
344 ------------
345 This daemon can be used to perform automatic resets of ongoing connections
346 that hunt can see. You can describe which connections should be terminated
347 by giving src/dst host/mask and src/dst ports. The SYN flag off means that
348 all specified connections should be terminated (even ongoing). The SYN
349 flag on means that only newly started connections are reset. So the
350 connections that are in progress are not affected. Don't forget to start the
351 daemon.
352
353 ARP daemon
354 ----------
355 Here you can do ARP spoofing of hosts. You enter src and dst addresses and
356 desired srcMAC. The dst is then forced to think that src has srcMAC. You can
357 use some fake MAC or better MAC of host that is currently down. You just want
358 that the hosts will send you all the data (so you can even look at packets
359 that are on a different segment or switched port that you will not normally
360 see) The ARP module looks carefully for packets which will break ARP spoofing
361 of hosts and handle them but you can even specify the refresh interval for ARP
362 spoofing but it is not necessary to do it. Set the refresh interval only if
363 you are experienced with some bad or strange behavior of spoofed hosts.
364 Also there is the possibility to test the hosts for successful spoof with
365 the ability to force that spoof - it is recommended to test the ARP spoof
366 if something looks like it is wrong or the computer doesn't send the traffic
367 to the hunt. The force option is handful if the first spoofing packets
368 are discarded with switch so if you are running hunt against hosts on
369 switched ports you can try to run the force mode by example for 10s and
370 then break it with CTRL-C if the spoof continues to fail.
371 The ARP relayer daemon is used to perform ARP relaying of ARP spoofed
372 connections. When you insert some ARP spoof of hosts the ARP spoofing is
373 performed immediately even if the relayer isn't running!!!. But if the ARP
374 spoofing succeeds, the connections will look like they freeze. For rerouting
375 (not IP routing !) these connections through your hunt you need to start
376 the ARP relayer. The relayer works well with ARP/simple hijack so once you
377 have hosts ARP spoofed with ARP relaying you can easily do ARP/simple
378 hijack which will detect that the hosts are already ARP spoofed and takes
379 over the connection immediately. With this technique you can easily become
380 man in the middle from the beginning of the connection even though your
381 host with hunt isn't an IP gateway. I encourage you to write other
382 application specific protocol handlers for the man in the middle attack as it
383 is really simple with this framework.
384
385 Sniff daemon
386 ------------
387 The purpose of the sniff daemon is to log specified packets.
388 The sniff daemon can also search for a simple pattern (string) in the data
389 stream (see the bugs section). You can specify which connection you are
390 interested in, where to search (src, dst, both), what do you want to search,
391 how many bytes you want to log, from what direction (src, dst, both) and to
392 what file should the daemon write. All logged files are stored in the .sniff
393 directory. The default file name for logging is composed of the host and port
394 names. In the options submenu you can set how to log new lines (\r,\n)
395 (as new-lines or as hex num.).
396
397 MAC discovery daemon
398 --------------------
399 This daemon is used to collect MAC addresses corresponding to the specified
400 IP range. You can enter the time after which the daemon will try collecting
401 again (default is 5min).
402
403
404 Host up menu
405 ------------
406 The host up module determines which hosts are up (with TCP/IP stack).
407 You just specify the IP range and that space is then searched for running
408 hosts.
409 It is capable to determine which hosts have network interface in
410 promiscuous mode. The promiscuous mode usually shows that the host is
411 running some kind of sniffer/network analyzer.
412
413 Options menu
414 ------------
415 In the options menu you can tune different things:
416
417 l) a) m) d) list/add/mod/del connection policy entry
418 First of all you can select which connections should be tracked. The
419 default setting is to look at telnet connections from all hosts but
420 you can adjust this behavior by the specification of src/dst
421 address/mask src/dst port pairs. With commands: l) a) m) d) you set
422 what you are interested in.
423
424 c) connection listening properties
425 You can set whether the sequence numbers and MACs of ongoing
426 connections will be displayed during connection listening.
427
428 h) host resolving
429 You can turn on resolving of hosts to their names. As the resolving
430 is deferred you don't get the names of hosts immediately.
431 Just try to list connections several times and you will
432 see the hosts names. (I used this deferred approach because I
433 didn't want any delay of interface that the resolving can cause).
434
435 r) reset ACK storm timeout
436 This timeout is used in simple hijack to automatically reset the
437 connection after the ACK storm is detected. Note that you can receive
438 the ACK storm even in arp/simple hijack in case you don't perform
439 ACK spoofing of any host.
440
441 s) simple hijack timeout for next cmd
442 Simple hijack has not an interactive connection interface. That
443 means you write the whole command which will be inserted into
444 the connection data stream. If no data is transferred through the
445 connection up to this timeout, you are prompted for the next command.
446
447 q) ARP request/reply packets
448 Number of request or reply packets hunt will send when it is doing
449 arp spoofing.
450
451 t) ARP request spoof through request
452 Option whether hunt will send ARP spoof request or ARP spoof reply
453 when it receives broadcasted ARP request which will break ARP spoof.
454
455 w) switched environment
456 Some optimization for switched environment. It works perfectly for non
457 switched environment also.
458
459 y) ARP spoof with my MAC
460 Set the originating MAC address of sent spoofed ARP to my (hunt)
461 ethernet MAC - sometimes helps in switched environment.
462
463 e) learn MAC from IP traffic
464 You can enable that MAC addresses will be learned from all
465 IP traffic not just from ARP.
466
467 p) number of printed lines per page in listening
468 Self explanatory
469
470 v) verbose on/off
471 Self explanatory
472
473 ----------------------------------------------------------------------------
474 TESTED ENVIRONMENT
475 ----------------------------------------------------------------------------
476 HUNT program requirements:
477 - Linux >= 2.2
478 - Glibc with linuxthreads
479 - Ethernet
480
481 Tested hosts:
482 Linux 2.0, 2.1, 2.2, Solaris.2.5.1, NT4sp3/4, Win95, OSF V4.0D, HPUX 10.20,
483 IRIX 6.2, pSOS
484
485 Tested network equipment:
486 BayNetworks 28115, 28200, 300 switches
487 3Com SuperStack II 3000, 1000 switches
488
489
490 SECURITY NOTES
491 --------------
492 Please note the already known truth that telnet and similar programs which send
493 passwords in clear text are vulnerable to the described attacks. Programs
494 using one time passwords are also easily attacked and in fact they are useless
495 if someone can run a program like hunt. Only full encrypted traffic isn't
496 vulnerable to these attacks but note that you can become a man in the middle
497 if you use ARP spoofing (forcing) without the ACK storm and you can try to do
498 something. Also unconfigured switch doesn't protect you from sniffing or
499 hijacking. It is necessary to carefully configure port security on the switches
500 in order to protect the computers on the switched ports.
501
502 Detecting attacks isn't an easy task. For ARP spoofing there are
503 tools which can detect it. The ACK storm is detectable by some sophisticated
504 network analyzers (you can detect the pattern of the ACK storm or the
505 statistics of ACKs without data). If you run hunt on your network you can
506 detect the ACK storm because the hunt can detect the ACK storm pattern.
507
508
509 PERFORMANCE NOTE
510 ----------------
511 Make sure you are running hunt on idle machine with sufficient power
512 (I used PII-233 with 128MB RAM) and without any other packet
513 analyzer because if you use advanced features like arp spoofing or hijacking
514 hunt needs to reply fast with it's own packets inserted into the traffic on
515 the network.
516
517
518 DOWNLOAD
519 --------
520 This software can be found at
521
522 http://www.gncz.cz/kra/index.html
523
524 or at
525
526 ftp://ftp.gncz.cz/pub/linux/hunt/
527
528
529 KNOWN BUGS
530 ----------
531 - some structures are poorly locked through mutexes
532 - if you watch connection then some escape sequences from that connection
533 can influent your terminal. Note that your terminal is named "Linux"
534 ("xterm" - if you run it from X, ...) but the escape sequences are
535 for the client side terminal which may or may not be Linux so you can get
536 some mess.
537 - sniff is not capable to search for a pattern which crosses the packet
538 boundary. That means it can't search for a pattern of the user typed input
539 as this input is usually transferred with 1B data long packets.
540 - hunt doesn't support defragmentation so the IP fragments have to be dropped.
541
542
543 BUG FIXES, SUGGESTIONS
544 ----------------------
545 Please send bug descriptions, patches, suggestions, new modules or
546 successful stories to [email protected]
547
548
549 ACKNOWLEDGMENTS
550 ---------------
551 I would like to thank Sven Ubik <[email protected]> for his invaluable
552 input and feedback.
553
554
555 --------------------------------------------------------------------------
556 FINAL WORD
557 --------------------------------------------------------------------------
558 Note that this software was written only for my fun in my free time and it
559 was a great exercise of TCP/IP protocols. I am now familiar with seq. numbers,
560 ACKs, timeouts, MACs, checksums, ... to the finest level. As I have some
561 pretty good background this "hunt" challenge made me think that I hadn't
562 known TCP/IP as great as I had thought. You are welcome to read the source
563 code and to try to modify it or write your own modules.