HPING3(8)

πŸ“¦
version 3.a2.ds2 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

okay so hi bestie πŸ’– you just opened the manual page for HPING3(8) β€” like, from the System Manager's Manual β€” and honestly? you're about to have a good time.

hping3 β€” send (almost) arbitrary TCP/IP packets to network hosts. yes. almost arbitrary. we're not fully unhinged, we're just mostly unhinged πŸ¦‹


✨ SYNOPSIS ✨

hping3 [ -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-mss ] [ --tcp-timestamp ] [ --tr-stop ] [ --tr-keep-ttl ] [ --tr-no-rtt ] [ --rand-dest ] [ --rand-source ] [ --beep ] hostname

like, yeah, that's a lot of letters. she's versatile. she contains multitudes. πŸ’…


🫢 DESCRIPTION 🫢

hping3 is a network tool that's able to send custom TCP/IP packets and then show you the target's replies, kind of the way ping does it with ICMP replies β€” except hping3 has main character energy and way more options.

She handles fragmentation, arbitrary packet bodies and sizes, and yes, you can use her to transfer files encapsulated under the protocols she supports. iconic

Using hping3 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, genuinely, a great didactic tool to learn TCP/IP β€” no cap, this is how you actually internalize how packets work. πŸ“š

hping3 is developed and maintained by antirez@invece.org and is licensed under GPL version 2. Development is open, so you can send patches, suggestions and affronts without inhibitions. she's not sensitive. she can take it. 😌


πŸ¦‹ HPING SITE πŸ¦‹

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


πŸ‘‘ BASE OPTIONS πŸ‘‘

  • -h, --help β€” Shows you a help screen on standard output, so yes you can pipe it to less. chef's kiss for long help output.
  • -v, --version β€” Shows version information and the API used to access the data link layer: linux sock packet or libpcap.
  • -c, --count count β€” Stop after sending (and receiving) count response packets. After the last packet was sent, hping3 waits COUNTREACHED_TIMEOUT seconds for the target host to reply. You are able to tune COUNTREACHED_TIMEOUT by editing hping2.h. (yes. the header file. go touch it. ✨)
  • -i, --interval β€” Wait the specified number of seconds or micro seconds between sending each packet. --interval X sets the wait to X seconds, --interval uX sets the wait to X micro seconds. The default is to wait one second between each packet. If you're using hping3 to transfer files, tuning this option is really important in order to increase transfer rate. Even when using hping3 to perform idle/spoofing scanning you should tune this option β€” see HPING3-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). she's honest about her limits πŸ₯²
  • --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 hping3 uses the default routing interface. In other systems, or when there is no default route, hping3 uses the first non-loopback interface. However you are able to force hping3 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, hping3 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 hping3. 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 hping3.
  • --beep β€” Beep for every matching received packet (but not for ICMP errors). πŸ””

🌈 PROTOCOL SELECTION 🌈

Default protocol is TCP. By default hping3 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 the target is behind a firewall that drops ICMP. Moreover a tcp null-flag to port 0 has a good probability of not being logged. stealth queen behavior, honestly. 🀫

  • -0, --rawip β€” RAW IP mode. In this mode hping3 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 hping3 will send ICMP echo-request, you can set other ICMP type/code using --icmptype --icmpcode options.
  • -2, --udp β€” UDP mode. By default hping3 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 to scan. 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. πŸ‘€

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

  • -a --spoof hostname β€” bestie this is the disguise option πŸ’… you set a fake IP source address so the target literally never learns your real address, no cap. BUT the replies get sent to that spoofed address instead, so you won't see them 😭. Want to know how people pull off spoofed/idle scanning anyway? Go read the HPING3-HOWTO.
  • --rand-source β€” turns on random source mode, so hping throws packets out with a random source address every time. Iconic for stressing out firewall state tables and all those other per-ip dynamic tables living inside TCP/IP stacks and firewall software πŸ”₯.
  • --rand-dest β€” random destination mode, let's go ✨ hping sends packets to random addresses that follow whatever rule you gave as the target host. You need to give a numerical IP address as target host, like 10.0.0.x. Every x gets swapped for a random number in the range 0-255. So to hit Internet IP addresses across the whole IPv4 space you'd do something like hping x.x.x.x --rand-dest. Not sure what addresses your rule is spitting out? Use the --debug switch and it'll display every new destination address it generates 🫢. When this is on, matching packets get accepted from all the destinations.
⚠️ Warning: with this option enabled hping can't detect the right outgoing interface for the packets, so you should use the --interface option to pick the outgoing interface you want.
  • -t --ttl time to live β€” sets the TTL (time to live) of your outgoing packets. You'll probs be using this with --traceroute or --bind. If you're in doubt just try hping3 some.host.com -t 1 --traceroute πŸ’–.
  • -N --id β€” sets the ip->id field. Default id is random, but if fragmentation is turned on and no id is specified it'll be getpid() & 0xFFFF β€” a better solution is sitting on the TODO list, fr fr.
  • -H --ipproto β€” sets the ip protocol when you're in RAW IP mode.
  • -W --winid β€” id from Windows* systems before Win2k has a different byte ordering, so if you enable this option hping3 will properly display id replies from those Windows machines πŸ‘‘
  • -r --rel β€” displays id increments instead of id. The HPING3-HOWTO has more tea. Heads up: increments aren't computed as id[N]-id[N-1], they use packet loss compensation. See relid.c for the deets.
  • -f --frag β€” splits packets into more fragments πŸ“ handy for testing IP stacks' fragmentation performance, and for testing whether some packet filter is so weak 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 one's for doing 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 the 'virtual mtu', fragmentation gets turned on automatically ⭐.
  • -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 every 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 with hping you can use record route even if the target host filters ICMP β€” record route is an IP option, not an ICMP option, so you can use it even in TCP and UDP mode 🌈.

  • -C --icmptype type β€” sets icmp type. Default is ICMP echo request (and it implies --icmp).
  • -K --icmpcode code β€” sets icmp code. Default is 0 (implies --icmp).
  • --icmp-ipver β€” sets the IP version of the IP header contained inside ICMP data. Default is 4.
  • --icmp-iphlen β€” sets the IP header length of the IP header contained inside ICMP data. Default is 5 (5 words of 32 bits).
  • --icmp-iplen β€” sets the IP packet length of the IP header contained inside ICMP data. Default is the real length.
  • --icmp-ipid β€” sets the IP id of the IP header contained inside ICMP data. Default is random.
  • --icmp-ipproto β€” sets the IP protocol of the IP header contained inside ICMP data. Default is TCP.
  • --icmp-cksum β€” sets the 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) 🎭.

  • -s --baseport source port β€” hping3 uses the source port to guess the reply's sequence number. It starts with a base source port number and increases it for every packet sent. When a packet comes back, the sequence number can be computed as replies.dest.port - base.source.port. Default base source port is random; with this option you can set a different number. If you need the source port to NOT increase for every sent packet, use the -k --keep option πŸ’….
  • -p --destport [+][+]dest port β€” sets destination port, default is 0. If a + character comes before the dest port number (i.e. +1024), the destination port increases for every reply received. If a double + comes before it (i.e. ++1024), the destination port increases for every packet sent. By default the destination port can be modified interactively using CTRL+z 😌.
  • --keep β€” keep still source port, see --baseport for more info.
  • -w --win β€” sets the TCP window size. Default is 64.
  • -O --tcpoff β€” sets a 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 β€” use this one to collect sequence numbers generated by the target host πŸ•΅οΈ super useful when you need to analyze whether the TCP sequence number is predictable. Output example:
#hping3 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, the second 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-mss β€” enables the TCP MSS option and sets it to the given value.
  • --tcp-timestamp β€” enables the TCP timestamp option, and tries to guess the timestamp update frequency and the remote system uptime ⏱️.
  • -F --fin β€” sets the FIN tcp flag.
  • -S --syn β€” sets the SYN tcp flag.
  • -R --rst β€” sets the RST tcp flag.
  • -P --push β€” sets the PUSH tcp flag.
  • -A --ack β€” sets the ACK tcp flag.
  • -U --urg β€” sets the URG tcp flag.
  • -X --xmas β€” sets the Xmas tcp flag πŸŽ„.
  • -Y --ymas β€” sets the Ymas tcp flag.

✨ COMMON OPTIONS ✨

  • -d --data data size β€” sets the packet body size. ⚠️ Warning: with --data 40 hping3 will NOT generate a 0 byte packet, it generates protocol_header+40 bytes. hping3 displays packet size info 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 gets 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 together with the --file filename option β€” the remainder of the data space gets filled using filename πŸ’–.
  • -j --dump β€” dumps received packets in hex.
  • -J --print β€” dumps received packets' printable characters.
  • -B --safe β€” enables safe protocol; with this option, lost packets in file transfers get resent πŸ”. For example, to send the file /etc/passwd from host A to host B you could use:
[host_a]
# hping3 host_b --udp -p 53 -d 100 --sign signature --safe --file /etc/passwd
[host_b]
# hping3 host_a --listen signature --safe --icmp
  • -u --end β€” if you're using the --file filename option, this tells you when EOF has been reached. Plus it prevents the other end from accepting more packets. Please, for more info see the HPING3-HOWTO.
  • -T --traceroute β€” traceroute mode πŸ‘‘ with this option hping3 increases the ttl for each ICMP time to live 0 during transit that it receives. Try hping3 host --traceroute. This option implies --bind and --ttl 1. You can override that 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, try hping3 host --traceroute --ttl 5 --tr-keep-ttl πŸ¦‹.
  • --tr-stop β€” if this is specified, hping will exit as soon as it receives the first packet that isn't an ICMP time exceeded. This better emulates the traceroute behavior πŸ’….
  • --tr-no-rtt β€” doesn't show RTT information in traceroute mode. The ICMP time exceeded RTT information isn't even calculated if this option is set.
  • --tcpexitcode β€” exits with the last received packet's tcp->th_flag as the exit code. Handy for scripts that need to know, say, whether 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 πŸ’–

ok so when hping3 gives you a TCP reply back, this is the standard lil glow-up it shows you:

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

let me break it down field by field because every single one matters bestie:

  • len β€” the size, in bytes, of the data captured from the data link layer, excluding the data link header size. and like, heads up: this might not match the IP datagram size because of low level transport layer padding. it's giving "close enough" energy 🫢
  • ip β€” the source ip address, obviously πŸ’…
  • flags β€” the TCP flags!! and the letters are: R for RESET, S for SYN, A for ACK, F for FIN, P for PUSH, U for URGENT, X for not standard 0x40, and Y for not standard 0x80. so RA up there means RESET + ACK, iconic honestly
  • DF β€” if the reply contains this, the IP header has the don't fragment bit set πŸŽ€
  • seq β€” the sequence number of the packet. it's obtained using the source port for TCP/UDP packets, and the sequence field for ICMP packets
  • id β€” the IP ID field
  • win β€” the TCP window size
  • rtt β€” the round trip time, in milliseconds ⏱️

and ok, if you run hping with the -V command line switch it will show you extra info about the packet, like:

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

and those extra fields are:

  • 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

and the field meaning is just the same as the TCP output meaning of the same fields. no new lore, same lore πŸ’œ

🌸 ICMP OUTPUT FORMAT 🌸

an example of ICMP output is:

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

it's very simple to understand bestie, 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 whole plot twist ✨


πŸ‘‘ AUTHOR πŸ‘‘

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

πŸ’€ BUGS πŸ’€

ok so listen, the tea:

  • Even using the --end and --safe options to transfer files, the final packet will be padded with 0x00 bytes. yeah. even then. πŸ™ˆ
  • 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, it 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 our fault, not libpcap's fault, it's a solaris moment fr fr πŸ˜”

🌈 SEE ALSO 🌈

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


and that's the whole page bestie!! this one's the 2001 Aug 14 edition of HPING3(8) β€” yes, 2001, she's vintage, she's an elder icon, and she still slays πŸ’…βœ¨ go ping something, love u, bye πŸ«ΆπŸ’–