HPING2(8)
๐ 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 toless.-v,--versionโ Show version information and API used to access to data link layer, linux sock packet or libpcap.-c,--countcount โ Stop after sending (and receiving)countresponse packets. After last packet was sendhping2waitCOUNTREACHED_TIMEOUTseconds target host replies. You are able to tuneCOUNTREACHED_TIMEOUTeditinghping2.h.-i,--intervalโ Wait the specified number of seconds or micro seconds between sending each packet.--interval Xset wait to X seconds,--interval uXset wait to X micro seconds. The default is to wait one second between each packet. Usinghping2to transfer files tune this option is really important in order to increase transfer rate. Even usinghping2to perform idle/spoofing scanning you should tune this option, seeHPING2-HOWTOfor 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 u0option.-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,--interfaceinterface name โ By default on linux and BSD systemshping2uses default routing interface. In other systems or when there is no default routehping2uses the first non-loopback interface. However you are able to forcehping2to use the interface you need using this option. Note: you don't need to specify the whole name, for example-I etwill matcheth0ethernet0myet1etcetera. If no interfaces matchhping2will try to uselo.-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 withhping2. When debug mode is enabled you will get more information about interface detection, data link layer access, interface settings, options parsing, fragmentation,HCMPprotocol 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 stophping2.--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 modehping2will send IP header with data appended with--signatureand/or--file, see also--ipprotothat allows you to set the ip protocol field.-1,--icmpโ ICMP mode, by defaulthping2will send ICMP echo-request, you can set other ICMP type/code using--icmptype--icmpcodeoptions.-2,--udpโ UDP mode, by defaulthping2will 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, so1,2,3means port 1, 2 and 3. ranges are specified using astart-endnotation, like1-1000, that tell hping to scan ports between 1 and 1000 (included). the special wordallis an alias for0-65535, while the special wordknownincludes 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,--listensignature โ HPING2 listen mode, using this optionhping2waits for packet that containsignatureand dump fromsignatureend to packet's end. For example ifhping2 --listen TESTreads a packet that contain234-09sdflkjs45-TESThello_worldit will displayhello_world.
๐ IP RELATED OPTIONS ๐
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 theHPING2-HOWTO.--rand-sourceโ Turns on random source mode โจ.hpingsends 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 ๐ฆ.hpingsends 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, like10.0.0.x. Every occurrence ofxgets replaced with a random number in the range 0-255. So if you want Internet IP addresses across the whole IPv4 space, use something likehping x.x.x.x --rand-dest. If youโre not sure what kind of addresses your rule is generating, try the--debugswitch 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,hpingcanโt detect the right outgoing interface for the packets, so you should use the--interfaceoption 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--tracerouteor--bind. If youโre in doubt, tryhping2 some.host.com -t 1 --traceroute.-N,--idโ Sets theip->idfield. Default id is random, but if fragmentation is turned on and id isnโt specified it will begetpid() & 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,hping2will properly display id replies from those Windows ๐ป.-r,--relโ Displays id increments instead of id. See theHPING2-HOWTOfor more info. Increments arenโt computed asid[N]-id[N-1]but using packet loss compensation. Seerelid.cfor 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--mtuoption.-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 theRECORD_ROUTEoption 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 usinghpingyouโ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 RELATED OPTIONS ๐ฆ
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/UDP RELATED OPTIONS ๐
TCP and UDP besties, this is your section โ ports, flags, sequence numbers, all the spicy stuff ๐ฅ.
-s,--baseport source portโhping2uses 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 asreplies.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 --keepoption ๐ซถ.-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--baseportfor more information ๐.-w,--winโ Sets TCP window size. Default is 64 ๐ช.-O,--tcpoffโ Sets fake tcp data offset. Normal data offset istcphdrlen / 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 40hping2will not generate 0 byte packets butprotocol_header+40bytes โ ๏ธ.hping2will 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,hpingwill use the signature size as the data size. This option can be used safely with the--file filenameoption; 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/passwdfrom 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 filenameoption, tells you when EOF has been reached ๐ญ. Moreover, prevents the other end from accepting more packets. Please, for more information see theHPING2-HOWTO.-T,--tracerouteโ Traceroute mode ๐บ๏ธ. Using this option,hping2will increase TTL for each ICMP time to live 0 during transit received. Tryhping2 host --traceroute. This option implies--bindand--ttl 1. You can override the ttl of 1 using the--ttloption. 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 tryhping2 host --traceroute --ttl 5 --tr-keep-ttl.--tr-stopโ If this option is specified,hpingwill 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โstcp->th_flagas 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:Rfor RESET,Sfor SYN,Afor ACK,Ffor FIN,Pfor PUSH,Ufor URGENT,Xfor not standard0x40,Yfor not standard0x80.- 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.seqandackโ 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
- nixos 26.05: hping 2014-12-26
- nixpkgs unstable: hping 2014-12-26
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms