HPING2(8)

๐Ÿ“ฆ version 2014-12, in nixos 26.05, nixpkgs unstable

๐Ÿ’… HPING2(8) โ€” System Manager's Manual ๐Ÿ’…

๐ŸŒธ NAME ๐ŸŒธ

hping2 โ€” send (almost) arbitrary TCP/IP packets to network hosts. That's the whole flex, bestie ๐Ÿ’–

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

hping2 [ -hvnqVDzZ012WrfxykQbFSRPAUXYjJBuTG ] [ -c count ] [ -i wait ] [ --fast ] [ -I interface ] [ -9 signature ] [ -a host ] [ -t ttl ] [ -N ip id ] [ -H ip protocol ] [ -g fragoff ] [ -m mtu ] [ -o tos ] [ -C icmp type ] [ -K icmp code ] [ -s source port ] [ -p[+][+] dest port ] [ -w tcp window ] [ -O tcp offset ] [ -M tcp sequence number ] [ -L tcp ack ] [ -d data size ] [ -E filename ] [ -e signature ] [ --icmp-ipver version ] [ --icmp-iphlen length ] [ --icmp-iplen length ] [ --icmp-ipid id ] [ --icmp-ipproto protocol ] [ --icmp-cksum checksum ] [ --icmp-ts ] [ --icmp-addr ] [ --tcpexitcode ] [ --tcp-timestamp ] [ --tr-stop ] [ --tr-keep-ttl ] [ --tr-no-rtt ] [ --rand-dest ] [ --rand-source ] [ --beep ] hostname

๐Ÿ’– DESCRIPTION ๐Ÿ’–

okay so bestie, hping2 is a network tool able to send custom TCP/IP packets and to display target replies like the ping program does with ICMP replies. It handle fragmentation, arbitrary packets body and size, and can be used in order to transfer files encapsulated under supported protocols. Using hping2 you are able to perform at least the following stuff:

  • Test firewall rules
  • Advanced port scanning
  • Test net performance using different protocols, packet size, TOS (type of service) and fragmentation.
  • Path MTU discovery
  • Transferring files between even really fascist firewall rules.
  • Traceroute-like under different protocols.
  • Firewalk-like usage.
  • Remote OS fingerprinting.
  • TCP/IP stack auditing.
  • A lot of others.

It's also a good didactic tool to learn TCP/IP. hping2 is developed and maintained by antirez@invece.org and is licensed under GPL version 2. Development is open so you can send me patches, suggestion and affronts without inhibitions. periodt ๐Ÿ’…

๐ŸŒˆ HPING SITE ๐ŸŒˆ

primary site at http://www.hping.org. You can found both the stable release and the instruction to download the latest source code at http://www.hping.org/download.html โœจ

โœจ BASE OPTIONS โœจ

  • -h, --help โ€” Show an help screen on standard output, so you can pipe to less.
  • -v, --version โ€” Show version information and API used to access to data link layer, linux sock packet or libpcap.
  • -c, --count count โ€” Stop after sending (and receiving) count response packets. After last packet was send hping2 wait COUNTREACHED_TIMEOUT seconds target host replies. You are able to tune COUNTREACHED_TIMEOUT editing hping2.h.
  • -i, --interval โ€” Wait the specified number of seconds or micro seconds between sending each packet. --interval X set wait to X seconds, --interval uX set wait to X micro seconds. The default is to wait one second between each packet. Using hping2 to transfer files tune this option is really important in order to increase transfer rate. Even using hping2 to perform idle/spoofing scanning you should tune this option, see HPING2-HOWTO for more information.
  • --fast โ€” Alias for -i u10000. Hping will send 10 packets for second.
  • --faster โ€” Alias for -i u1. Faster then --fast ;) (but not as fast as your computer can send packets due to the signal-driven design).
  • --flood โ€” Sent packets as fast as possible, without taking care to show incoming replies. This is ways faster than to specify the -i u0 option.
  • -n, --numeric โ€” Numeric output only, No attempt will be made to lookup symbolic names for host addresses.
  • -q, --quiet โ€” Quiet output. Nothing is displayed except the summary lines at startup time and when finished.
  • -I, --interface interface name โ€” By default on linux and BSD systems hping2 uses default routing interface. In other systems or when there is no default route hping2 uses the first non-loopback interface. However you are able to force hping2 to use the interface you need using this option. Note: you don't need to specify the whole name, for example -I et will match eth0 ethernet0 myet1 et cetera. If no interfaces match hping2 will try to use lo.
  • -V, --verbose โ€” Enable verbose output. TCP replies will be shown as follows:
len=46 ip=192.168.1.1 flags=RA DF seq=0 ttl=255 id=0 win=0
rtt=0.4 ms tos=0 iplen=40 seq=0 ack=1380893504 sum=2010 urp=0
  • -D, --debug โ€” Enable debug mode, it's useful when you experience some problem with hping2. When debug mode is enabled you will get more information about interface detection, data link layer access, interface settings, options parsing, fragmentation, HCMP protocol and other stuff.
  • -z, --bind โ€” Bind Ctrl+Z to time to live (TTL) so you will able to increment/decrement ttl of outgoing packets pressing Ctrl+Z once or twice.
  • -Z, --unbind โ€” Unbind Ctrl+Z so you will able to stop hping2.
  • --beep โ€” Beep for every matching received packet (but not for ICMP errors).

๐Ÿ”ฅ PROTOCOL SELECTION ๐Ÿ”ฅ

Default protocol is TCP, by default hping2 will send tcp headers to target host's port 0 with a winsize of 64 without any tcp flag on. Often this is the best way to do an 'hide ping', useful when target is behind a firewall that drop ICMP. Moreover a tcp null-flag to port 0 has a good probability of not being logged. no cap ๐Ÿ‘‘

  • -0, --rawip โ€” RAW IP mode, in this mode hping2 will send IP header with data appended with --signature and/or --file, see also --ipproto that allows you to set the ip protocol field.
  • -1, --icmp โ€” ICMP mode, by default hping2 will send ICMP echo-request, you can set other ICMP type/code using --icmptype --icmpcode options.
  • -2, --udp โ€” UDP mode, by default hping2 will send udp to target host's port 0. UDP header tunable options are the following: --baseport, --destport, --keep.
  • -8, --scan โ€” Scan mode, the option expects an argument that describes groups of ports. port groups are comma separated: a number describes just a single port, so 1,2,3 means port 1, 2 and 3. ranges are specified using a start-end notation, like 1-1000, that tell hping to scan ports between 1 and 1000 (included). the special word all is an alias for 0-65535, while the special word known includes all the ports listed in /etc/services.

Groups can be combined, so the following command line will scan ports between 1 and 1000 AND port 8888 AND ports listed in /etc/services:

hping --scan 1-1000,8888,known -S target.host.com

Groups can be negated (subtracted) using a ! character as prefix, so the following command line will scan all the ports NOT listed in /etc/services in the range 1-1024:

hping --scan '1-1024,!known' -S target.host.com

Keep in mind that while hping seems much more like a port scanner in this mode, most of the hping switches are still honored, so for example to perform a SYN scan you need to specify the -S option, you can change the TCP windows size, TTL, control the IP fragmentation as usually, and so on. The only real difference is that the standard hping behaviors are encapsulated into a scanning algorithm.

Tech note: The scan mode uses a two-processes design, with shared memory for synchronization. The scanning algorithm is still not optimal, but already quite fast.

Hint: unlike most scanners, hping shows some interesting info about received packets, the IP ID, TCP win, TTL, and so on, don't forget to look at this additional information when you perform a scan! Sometimes they shows interesting details. iykyk ๐Ÿ‘€

  • -9, --listen signature โ€” HPING2 listen mode, using this option hping2 waits for packet that contain signature and dump from signature end to packet's end. For example if hping2 --listen TEST reads a packet that contain 234-09sdflkjs45-TESThello_world it will display hello_world.

Okay bestie, this is where we start messing with the IP layer itself โ€” the whole โ€œwho even sent this packet?โ€ zone ๐Ÿ’….

  • -a, --spoof hostname โ€” Use this when you want a fake IP source address, so the target literally never gets your real address ๐Ÿซถ. But heads up: replies go to the spoofed address, which means you wonโ€™t see them ๐Ÿ˜ญ. If you wanna see how spoofed/idle scanning works, check the HPING2-HOWTO.
  • --rand-source โ€” Turns on random source mode โœจ. hping sends packets with a random source address. This is lowkey interesting for stressing firewall state tables and other per-IP dynamic tables inside TCP/IP stacks and firewall software ๐Ÿ”ฅ.
  • --rand-dest โ€” Random destination mode, activated ๐Ÿฆ‹. hping sends packets to random addresses obtained by following the rule you specify as the target host. You need to give a numerical IP address as the target host, like 10.0.0.x. Every occurrence of x gets replaced with a random number in the range 0-255. So if you want Internet IP addresses across the whole IPv4 space, use something like hping x.x.x.x --rand-dest. If youโ€™re not sure what kind of addresses your rule is generating, try the --debug switch to display every new destination address generated ๐Ÿ‘€. When this option is on, matching packets will be accepted from all the destinations.
โš ๏ธ Warning: when this option is enabled, hping canโ€™t detect the right outgoing interface for the packets, so you should use the --interface option to select the desired outgoing interface. No cap, this one matters.
  • -t, --ttl time to live โ€” Sets the TTL (time to live) of outgoing packets โณ. Youโ€™ll likely use this with --traceroute or --bind. If youโ€™re in doubt, try hping2 some.host.com -t 1 --traceroute.
  • -N, --id โ€” Sets the ip->id field. Default id is random, but if fragmentation is turned on and id isnโ€™t specified it will be getpid() & 0xFF. A better solution is in the TODO list ๐ŸŽ€.
  • -H, --ipproto โ€” Sets the IP protocol in RAW IP mode ๐Ÿงš.
  • -W, --winid โ€” id from Windows* systems before Win2k has a different byte ordering. If this option is enabled, hping2 will properly display id replies from those Windows ๐Ÿ’ป.
  • -r, --rel โ€” Displays id increments instead of id. See the HPING2-HOWTO for more info. Increments arenโ€™t computed as id[N]-id[N-1] but using packet loss compensation. See relid.c for more information ๐Ÿ‘‘.
  • -f, --frag โ€” Splits packets into more fragments. This can be useful to test IP stacks fragmentation performance and to test if some packet filter is so weak that it can be passed using tiny fragments (anachronistic) ๐Ÿ’€. Default โ€˜virtual mtuโ€™ is 16 bytes. See also the --mtu option.
  • -x, --morefrag โ€” Sets the more fragments IP flag. Use this if you want the target host to send an ICMP time-exceeded during reassembly ๐ŸŒˆ.
  • -y, --dontfrag โ€” Sets the donโ€™t fragment IP flag. This can be used to perform MTU path discovery โญ.
  • -g, --fragoff fragment offset value โ€” Sets the fragment offset ๐ŸŒธ.
  • -m, --mtu mtu value โ€” Sets a different โ€˜virtual mtuโ€™ than 16 when fragmentation is enabled. If packet size is greater than โ€˜virtual mtuโ€™, fragmentation is automatically turned on ๐ŸŽ€.
  • -o, --tos hex_tos โ€” Sets Type Of Service (TOS). For more info try --tos help โœจ.
  • -G, --rroute โ€” Record route. Includes the RECORD_ROUTE option in each packet sent and displays the route buffer of returned packets ๐Ÿ—บ๏ธ. Note that the IP header is only large enough for nine such routes. Many hosts ignore or discard this option. Also note that using hping youโ€™re able to use record route even if the target host filters ICMP. Record route is an IP option, not an ICMP option, so you can use record route even in TCP and UDP mode ๐Ÿ’….

ICMP era โ€” the little messages that say โ€œhey, something happenedโ€ ๐Ÿ˜ญโœจ.

  • -C, --icmptype type โ€” Sets ICMP type. Default is ICMP echo request (implies --icmp) ๐Ÿซถ.
  • -K, --icmpcode code โ€” Sets ICMP code. Default is 0 (implies --icmp) ๐ŸŽ€.
  • --icmp-ipver โ€” Sets IP version of the IP header contained into ICMP data. Default is 4 ๐ŸŒˆ.
  • --icmp-iphlen โ€” Sets IP header length of the IP header contained into ICMP data. Default is 5 (5 words of 32 bits) โญ.
  • --icmp-iplen โ€” Sets IP packet length of the IP header contained into ICMP data. Default is the real length ๐Ÿ’œ.
  • --icmp-ipid โ€” Sets IP id of the IP header contained into ICMP data. Default is random ๐ŸŽฒ.
  • --icmp-ipproto โ€” Sets IP protocol of the IP header contained into ICMP data. Default is TCP ๐Ÿ”ฅ.
  • --icmp-cksum โ€” Sets ICMP checksum. Default is the valid checksum โœ….
  • --icmp-ts โ€” Alias for --icmptype 13 (to send ICMP timestamp requests) โฐ.
  • --icmp-addr โ€” Alias for --icmptype 17 (to send ICMP address mask requests) ๐ŸŽญ.

TCP and UDP besties, this is your section โ€” ports, flags, sequence numbers, all the spicy stuff ๐Ÿ”ฅ.

  • -s, --baseport source port โ€” hping2 uses the source port in order to guess the replyโ€™s sequence number. It starts with a base source port number and increases this number for each packet sent. When a packet is received, the sequence number can be computed as replies.dest.port - base.source.port ๐Ÿงฎ. Default base source port is random; using this option you can set a different number. If you need the source port to not be increased for each sent packet, use the -k --keep option ๐Ÿซถ.
  • -p, --destport [+][+]dest port โ€” Sets destination port. Default is 0. If the + character precedes the dest port number (i.e. +1024), the destination port will be increased for each reply received. If double + precedes the dest port number (i.e. ++1024), the destination port will be increased for each packet sent โœจ. By default the destination port can be modified interactively using CTRL+z ๐ŸŽ€.
  • --keep โ€” Keeps still source port. See --baseport for more information ๐Ÿ’œ.
  • -w, --win โ€” Sets TCP window size. Default is 64 ๐ŸชŸ.
  • -O, --tcpoff โ€” Sets fake tcp data offset. Normal data offset is tcphdrlen / 4 ๐Ÿ“.
  • -M, --tcpseq โ€” Sets the TCP sequence number ๐Ÿ”ข.
  • -L, --tcpack โ€” Sets the TCP ack โœ….
  • -Q, --seqnum โ€” This option can be used to collect sequence numbers generated by the target host. Useful when you need to analyze whether the TCP sequence number is predictable ๐Ÿ‘€. Output example:
#hping2 win98 --seqnum -p 139 -S -i u1 -I eth0
HPING uaz (eth0 192.168.4.41): S set, 40 headers + 0 data bytes
2361294848 +2361294848
2411626496 +50331648
2545844224 +134217728
2713616384 +167772160
2881388544 +167772160
3049160704 +167772160
3216932864 +167772160
3384705024 +167772160
3552477184 +167772160
3720249344 +167772160
3888021504 +167772160
4055793664 +167772160
4223565824 +167772160

The first column reports the sequence number, and the second is the difference between the current and last sequence number. As you can see, the target hostโ€™s sequence numbers are predictable ๐Ÿ’€.

  • -b, --badcksum โ€” Sends packets with a bad UDP/TCP checksum ๐Ÿ™ˆ.
  • --tcp-timestamp โ€” Enables the TCP timestamp option, and tries to guess the timestamp update frequency and the remote system uptime โฑ๏ธ.
  • -F, --fin โ€” Sets FIN tcp flag ๐Ÿ.
  • -S, --syn โ€” Sets SYN tcp flag ๐Ÿค.
  • -R, --rst โ€” Sets RST tcp flag ๐Ÿ›‘.
  • -P, --push โ€” Sets PUSH tcp flag ๐Ÿ“ค.
  • -A, --ack โ€” Sets ACK tcp flag โœ….
  • -U, --urg โ€” Sets URG tcp flag ๐Ÿšจ.
  • -X, --xmas โ€” Sets Xmas tcp flag ๐ŸŽ„.
  • -Y, --ymas โ€” Sets Ymas tcp flag ๐ŸŽ.

๐ŸŽ€ COMMON OPTIONS ๐ŸŽ€

The everyday essentials โ€” data, files, safety, traceroute, and exit codes. Basically the main character options ๐Ÿ˜Œโœจ.

  • -d, --data data size โ€” Sets packet body size. Warning: using --data 40 hping2 will not generate 0 byte packets but protocol_header+40 bytes โš ๏ธ. hping2 will display packet size information as the first line of output, like this:
HPING www.yahoo.com (ppp0 204.71.200.67): NO FLAGS are set, 40 headers + 40 data bytes
  • -E, --file filename โ€” Uses the contents of filename to fill the packetโ€™s data ๐Ÿ“„.
  • -e, --sign signature โ€” Fills the first signature length bytes of data with signature. If the signature length is bigger than the data size, an error message will be displayed ๐Ÿšจ. If you donโ€™t specify the data size, hping will use the signature size as the data size. This option can be used safely with the --file filename option; the remainder of the data space will be filled using filename ๐Ÿซถ.
  • -j, --dump โ€” Dumps received packets in hex ๐Ÿ”ข.
  • -J, --print โ€” Dumps received packetsโ€™ printable characters ๐Ÿ”ค.
  • -B, --safe โ€” Enables safe protocol. Using this option, lost packets in file transfers will be resent ๐Ÿ›Ÿ. For example, in order to send file /etc/passwd from host A to host B you may use the following:
[host_a]
# hping2 host_b --udp -p 53 -d 100 --sign signature --safe --file /etc/passwd
[host_b]
# hping2 host_a --listen signature --safe --icmp
  • -u, --end โ€” If you are using the --file filename option, tells you when EOF has been reached ๐Ÿ“ญ. Moreover, prevents the other end from accepting more packets. Please, for more information see the HPING2-HOWTO.
  • -T, --traceroute โ€” Traceroute mode ๐Ÿ—บ๏ธ. Using this option, hping2 will increase TTL for each ICMP time to live 0 during transit received. Try hping2 host --traceroute. This option implies --bind and --ttl 1. You can override the ttl of 1 using the --ttl option. Since 2.0.0 stable it prints RTT information โฑ๏ธ.
  • --tr-keep-ttl โ€” Keeps the TTL fixed in traceroute mode, so you can monitor just one hop in the route ๐Ÿ‘€. For example, to monitor how the 5th hop changes or how its RTT changes you can try hping2 host --traceroute --ttl 5 --tr-keep-ttl.
  • --tr-stop โ€” If this option is specified, hping will exit once the first packet that isnโ€™t an ICMP time exceeded is received. This better emulates the traceroute behavior ๐Ÿ›‘.
  • --tr-no-rtt โ€” Donโ€™t show RTT information in traceroute mode. The ICMP time exceeded RTT information arenโ€™t even calculated if this option is set ๐Ÿ™….
  • --tcpexitcode โ€” Exit with the last received packetโ€™s tcp->th_flag as exit code ๐Ÿšช. Useful for scripts that need, for example, to know if port 999 of some host replies with SYN/ACK or with RST in response to SYN โ€” i.e. whether the service is up or down โœ….

๐Ÿ”ฅ TCP OUTPUT FORMAT ๐Ÿ”ฅ

Okay bestie, when TCP packets come back, the standard output format is literally this:

len=46 ip=192.168.1.1 flags=RA DF seq=0 ttl=255 id=0 win=0 rtt=0.4 ms

Hereโ€™s the field-by-field tea โ˜•:

  • len โ€” the size, in bytes, of the data captured from the data link layer, excluding the data link header size. It may not match the IP datagram size because of low level transport layer padding. No cap.
  • ip โ€” the source ip address.
  • flags โ€” the TCP flags: R for RESET, S for SYN, A for ACK, F for FIN, P for PUSH, U for URGENT, X for not standard 0x40, Y for not standard 0x80.
  • If the reply contains DF, the IP header has the donโ€™t fragment bit set.
  • seq โ€” the sequence number of the packet, obtained using the source port for TCP/UDP packets, the sequence field for ICMP packets.
  • id โ€” the IP ID field.
  • win โ€” the TCP window size.
  • rtt โ€” the round trip time in milliseconds.

If you run hping using the -V command line switch, it will display additional information about the packet, example:

len=46 ip=192.168.1.1 flags=RA DF seq=0 ttl=255 id=0 win=0 rtt=0.4 ms
tos=0 iplen=40 seq=0 ack=1223672061 sum=e61d urp=0
  • tos โ€” the type of service field of the IP header.
  • iplen โ€” the IP total len field.
  • seq and ack โ€” the sequence and acknowledge 32bit numbers in the TCP header.
  • sum โ€” the TCP header checksum value.
  • urp โ€” the TCP urgent pointer value.

๐ŸŒˆ UDP OUTPUT FORMAT ๐ŸŒˆ

The standard output format is:

len=46 ip=192.168.1.1 seq=0 ttl=64 id=0 rtt=6.0 ms

The field meaning is just the same as the TCP output meaning of the same fields. Easy slay, honestly.


๐Ÿฆ‹ ICMP OUTPUT FORMAT ๐Ÿฆ‹

An example of ICMP output is:

ICMP Port Unreachable from ip=192.168.1.1 name=nano.marmoc.net

It is very simple to understand. It starts with the string "ICMP" followed by the description of the ICMP error, Port Unreachable in the example. The ip field is the IP source address of the IP datagram containing the ICMP error, and the name field is just the numerical address resolved to a name (a dns PTR request) or UNKNOWN if the resolution failed.

The ICMP Time exceeded during transit or reassembly format is a bit different:

TTL 0 during transit from ip=192.168.1.1 name=nano.marmoc.net
TTL 0 during reassembly from ip=192.70.106.25 name=UNKNOWN

The only difference is the description of the error โ€” it starts with TTL 0. Thatโ€™s it, thatโ€™s the vibe. ๐Ÿ’…


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Salvatore Sanfilippo <antirez@invece.org>, with the help of the people mentioned in AUTHORS file and at http://www.hping.org/authors.html.


๐Ÿ’€ BUGS ๐Ÿ’€

Even using the --end and --safe options to transfer files, the final packet will be padded with 0x00 bytes. Annoying, but thatโ€™s the truth.

Data is read without care about alignment, but alignment is enforced in the data structures. This will not be a problem under i386 but, while usually the TCP/IP headers are naturally aligned, may create problems with different processors and bogus packets if there is some unaligned access around the code (hopefully none). ๐Ÿซ 

On solaris hping does not work on the loopback interface. This seems a solaris problem, as stated in the tcpdump-workers mailing list, so the libpcap canโ€™t do nothing to handle it properly. Not us trying to be messy โ€” thatโ€™s just whatโ€™s up.


๐ŸŒธ SEE ALSO ๐ŸŒธ

ping(8), traceroute(8), ifconfig(8), nmap(1)


And thatโ€™s the whole page, bestie โ€” source/version tag HPING2(8), dated 2001 Aug 14. Iconic manual page behavior, honestly. ๐ŸŽ€โœจ๐Ÿซถ

๐Ÿ“ฆ where this page comes from