On the wire
hping3
Builds one TCP, UDP or ICMP packet by hand, sends it, and prints the single reply — to read a firewall a probe at a time.
Where nmap sorts thousands of probes into open/closed/filtered, hping3 sends one packet you control
completely and shows you the raw reply. Set the flags yourself (-S for a lone SYN, -A for a bare ACK), aim it
at a port, and read the flags= field that comes back: SA (SYN-ACK) is an open port agreeing to connect, RA
or R is a reset (refused), and no reply at all is a silent drop. Because it forges packets it needs raw sockets, so
it runs under sudo. --scan sweeps a range of ports in one run; --traceroute climbs the TTL so each router on
the path names itself, which through an allowed port maps the network behind a firewall (firewalking). The ttl= of a
reply is itself a clue: a reset that skipped the usual hops was forged by a firewall, not sent by the host.
hping3 command usage
hping3 [-S | -A | --icmp] [-p PORT] [-c COUNT] [--scan RANGE] [--traceroute] TARGET
Options
-
-S - set the SYN flag — the first packet of a handshake, to test if a port is open
-
-A - set the ACK flag — a packet with no handshake behind it, to probe how a target answers the unexpected
-
-p 80 - the destination port
-
-c 3 - send this many packets, then stop
-
--scan 1-10000 - sweep a range of ports in one run, listing those that answer SYN-ACK
-
--traceroute - climb the TTL from 1, printing each router that reports time-exceeded
-
--icmp - send ICMP echo instead of TCP
hping3 examples
-
sudo hping3 -S -p 80 -c 3 10.0.3.10 - Sends three lone SYNs to port 80 and reads the flags:
SAmeans open, and no connection is ever completed. -
sudo hping3 -S -p 22 -c 3 10.0.3.10 - Probes a port that is refused; a
RAreply is a reset, silence is a drop. -
sudo hping3 --scan 1-10000 -S 10.0.3.10 - Sweeps ports 1–10000 and lists each one that answers with a SYN-ACK.
-
sudo hping3 --traceroute -S -p 80 -c 5 10.0.3.10 - Walks an allowed port, naming each router on the way, to map what sits behind the firewall.
Reading the output
$ sudo hping3 -S -p 80 -c 3 10.0.3.10 HPING 10.0.3.10 (eth0 10.0.3.10): S set, 40 headers + 0 data bytes len=44 ip=10.0.3.10 ttl=62 DF id=0 sport=80 flags=SA seq=0 win=64240 rtt=1.4 ms --- 10.0.3.10 hping statistic --- 3 packets transmitted, 3 packets received, 0% packet loss
flags=SAis SYN + ACK: the port is open and the firewall let the SYN reach a listening service.ttl=62counts the router hops: a starting 64 minus two means the reply came from a host two routers away, not from the firewall one hop out.
Pitfalls
- Raw sockets need root; without
sudohping3 exits with a permission error before it sends anything. - A
RAreset can be forged by a firewall for a port it guards, so it does not always mean the host itself is refusing — check thettl=.