Security Testing with Hping at the HOP
Total Page:16
File Type:pdf, Size:1020Kb
COver STOry Hping Michael Röder, Fotolia Röder, Michael Security testing with hping AT THE HOP Don't let intruders crash your dance. We'll show you how to test your hackerish names, such as targa, synful, papa smurf, and netdude, could help firewalls and intrusion detection systems with hping. with the task of generating designer packets, but many of these older applica- BY JAMES STANGER, PHD tions had problems and limitations. For example, some tools could only scan hen it comes to penetration types of the TCP/ IP protocol suite, some Class C IPv4 networks. testing and security audits, users call it a packet-crafting application. Whping is one of your best By manipulating packets, you can What Does hping Do? friends. Currently in its third iteration, scan systems stealthily, generate traffic Hping provides a single, universal solu- hping has become a preferred way to floods, and generally create packets to tion that helps prevent many problems generate IP packets, usually for the pur- your heart’s content. Over the years, of the previous generation. Hping is de- pose of testing firewall and intrusion de- hping has become the de facto packet signed to: tection systems. generator. • scan hosts, Because you can use hping to manipu- Generating custom packets is nothing • assist with penetration testing, late all of the fields, flags, and protocol new. Previous tools with whiz-bang and • test intrusion detection systems, Versions Hping3 is the latest version of hping, and manipulation tool) and idswakeup (an ap- hping3 places you into a session, much like hping2 is the most significant predecessor plication for auditing intrusion detection the old nslookup command. application. Several applications depend systems). Hping3 comes with a new TCL Hping3 lets you create fairly sophisticated upon hping2, which has been around quite scripting engine and is, therefore, quite bit scripts that will help you simulate traffic for a bit longer than hping3. more powerful than a simple command- your firewalls and intrusion detection sys- I install both versions, and I recommend line tool. tems. A less obvious advantage of hping3 that you do the same. I use hping3 as a The original hping and hping2 applications is that Salvatore Sanfilippo, the creator of stand-alone application, but I still have operate as one-time commands – they all things hping, rewrote much of the un- hping2 in case I need it for third-party ap- don’t launch an interactive shell. If you use derlying code. plications, such as scapy (another packet the command without any arguments, 38 ISSUE 99 FEBRUARY 2009 Hping COver story • and send files between Hping's creator, for example, still main- hosts. tains the tool even though he’s collabo- In this article, I will ex- rated for years with Fyodor, the creator plain how to start gener- of Nmap. ating test packets with Third, you can also conduct incremen- hping. tal scans, which means each scan will climb up one port on a system: Installing hping Hping3 is available from sudo hping -S targethost-p ++0 the project website as a source tarball [1]. If This command creates a report that tells you’re using an Ubuntu you what ports are open on the system. or Debian system, you can use either Synaptic A Better Traceroute? Package Manager or apt- One interesting feature of hping3 is that get for the installation. To you can generate a more revealing trace- install hping, enter the route report using any protocol. For ex- following command: ample, suppose you want to determine exactly what happens on each hop of a sudo apt-get U traceroute. To do this, you can specify install hping3. Figure 1: Viewing a packet generated by hping in Wireshark. the use of a TCP SYN packet. The -T op- tion allows you to enable hping3’s You don’t need to enable any additional trusion detection system will treat the traceroute function. In the command repositories. Red Hat or CentOS pack- SYN packet as standard traffic rather shown above, the --ttl option allows you ages are also available online [2]. than as a threat. to specify the number of routers (i.e., Figure 1 shows how to specify a more hops) you want to transmit. Scanning Hosts sophisticated scan that provides a nice If you want to issue a traceroute com- After installing hping, you are ready to little ASCII-based report. mand using UDP, the command shown get started. Suppose you want to send in Listing 2 will suffice. The output two TCP packets to a system named Advantages Over Nmap shows how each router processes the james, and you want those packets to hit You might wonder why you would want UDP packet. port 80 on james. To do this, you would to use hping to look for open ports when Why would you want to do such a issue the command shown (with the ac- you already have Nmap. In some situa- thing? Because many routers block tradi- companying output) in Listing 1. tions, hping offers advantages over tional ICMP packets, even if your latest In Listing 1, notice that the flags= Nmap. system used UDP. field is set to SA, which is hping’s way of First, hping is a light- telling you that port 80 is open on james. weight application; if Listing 2: Tracing UDP If the ports were closed, you’d see RA in you’ve got it installed and 01 sudo hping3 -2 192.168.44.45 -p ++44444 -T -n the flags= field. ready to go, why worry 02 The -S option sends a SYN packet, about installing anything 03 HPING 192.168.44.45 (eth0 192.168.44.45): udp mode which often is used to create scans that more? set, 28 headers + 0 data bytes are hard for intrusion detection systems Second, it’s always good 04 hop=1 TTL 0 during transit from ip=172.16.8.1 to detect and flag as threatening. to know how to do the 05 hop=1 hoprtt=1.7 ms After a system replies to a SYN packet, same thing with more 06 hop=2 TTL 0 during transit from ip=12.155.83.1 you know that a port is listening; the in- than one application. 07 hop=2 hoprtt=2.7 ms 08 hop=3 TTL 0 during transit from ip=12.119.43.49 Listing 1: A Simple Scan 09 hop=3 hoprtt=10.0 ms 01 pink@floyd:~/Desktop$ sudo hping3 -S james -c 2 -p 80 10 hop=4 TTL 0 during transit from ip=12.123.21.30 02 HPING james (eth0 192.168.15.134): S set, 40 headers + 0 data 11 hop=4 hoprtt=13.6 ms bytes 12 hop=5 TTL 0 during transit from ip=12.122.12.21 03 len=46 ip=192.168.15.134 ttl=64 DF id=0 sport=80 flags=SA seq=0 13 hop=5 hoprtt=13.3 ms win=5840 rtt=0.3 ms 14 hop=6 TTL 0 during transit from ip=12.122.17.42 04 len=46 ip=192.168.15.134 ttl=64 DF id=0 sport=80 flags=SA seq=1 win=5840 rtt=0.3 ms 15 hop=6 hoprtt=11.9 ms 05 16 hop=7 TTL 0 during transit from ip=12.122.96.9 06 --- james hping statistic --- 17 hop=7 hoprtt=36.6 ms 07 2 packets transmitted, 2 packets received, 0% packet loss 18 hop=8 TTL 0 during transit from ip=192.205.34.62 08 round-trip min/avg/max = 0.3/0.3/0.3 ms 19 hop=8 hoprtt=13.6 ms 09 pink@floyd:~/Desktop$ 20 hop=9 TTL 0 during transit from ip=4.68.103.46 FEBRUARY 2009 ISSUE 99 39 COver story Hping To analyze one particular hop of a with jitter and traffic con- Listing 3: Analyzing a Hop traceroute packet, you can use the gestion. By determining --tr-keep-ttl option: the MTU and adjusting it 01 hop=3 TTL 0 during transit from ip=12.119.43.61 properly at the router or 02 hop=3 hoprtt=31.7 ms sudo hping3 -S 12.119.80.1 U your individual hosts, you 03 hop=3 TTL 0 during transit from ip=12.119.43.61 -p 80 -T --ttl 3 U can reduce latency and re- 04 hop=3 hoprtt=6.9 ms --tr-keep-ttl -n solve call quality issues 05 hop=3 TTL 0 during transit from ip=12.119.43.61 that would otherwise 06 hop=3 hoprtt=5.0 ms The -n option ensures that numbers prove elusive. 07 hop=3 TTL 0 during transit from ip=12.119.43.49 aren’t resolved. 08 hop=3 hoprtt=5.2 ms Perimeter Testing The preceding command issues TCP- 09 hop=3 TTL 0 during transit from ip=12.119.43.49 based packets to the target host, but Perimeter testing means 10 hop=3 hoprtt=5.2 ms then reports only the third hop. The out- determining exactly what 11 hop=3 TTL 0 during transit from ip=12.119.43.49 put is shown in Listing 3. The informa- your firewall blocks and 12 hop=3 hoprtt=4.9 ms tion in Listing 3 can help you determine what it allows. To conduct 13 hop=3 TTL 0 during transit from ip=12.119.43.61 exactly if and how a particular router is a good test, you can spoof 14 hop=3 hoprtt=5.4 ms altering packets in transit.