skip to content

Why use hping3 rather than a port scanner to test one firewall rule, and what does a bare hping3 probe send by default?

level: juniorimportance: should knowfreq 24%

answer

  1. one packet, one answer
  2. you read the reply yourself
  3. default protocol is TCP
  4. destination port zero
  5. no flags until you ask

basics

~20 s

hping3 sends one hand-built packet per probe and prints each reply, so it shows how a rule answers one exact combination, not which ports are open. A bare run sends TCP with no flags to port 0, once a second.

solid answer

~40 s

A port scanner sweeps many ports and condenses the replies into states. hping3 does the opposite: you choose the protocol, flags, port and count, it sends exactly that, and you read the raw reply, so you can ask how a rule set treats *one* combination. Its defaults are a trap, though: with no protocol option it sends TCP with no flags set to destination port 0, window 64, TTL 64, one packet a second and no end. So a real test always sets a flag, a port and a count, for example `-S -p 443 -c 1`. It builds raw packets, so expect to need elevated privilege, and run it only against hosts and paths your written scope covers.

code

bash · 2 lines
bash
# One TCP SYN to port 443 on a host you own, then stop
hping3 -S -p 443 -c 1 192.0.2.10

go deeper

for a junior

Recall that hping3 sends one packet per probe and that its default is TCP with no flags to port 0, so you must set flag, port and count yourself.

for a middle

Explain the defaults table (window 64, TTL 64, one-second interval, rising source port) and why a rule test sets -S, -p and -c explicitly.

for a senior

Show that you write the expected answer before the probe, run it from the right source zone, and treat the reply as evidence to reconcile with the firewall log.

for a principal

Judge when a hand-built probe is the right evidence for a change and when a repeatable, scripted regression suite should own it.

## What hping3 is for hping3 is a command-line packet crafter. You choose the protocol, the TCP flags, the ports and a handful of header fields; it builds exactly one packet per probe, sends it, and prints whatever comes back. That makes it a rule-testing tool. The question it answers is "how does this path respond to this exact packet?", which is the question a firewall administrator has after a change: does the new rule let a SYN to port 443 through, reject it, or drop it? A port scanner answers a different question. It sweeps many ports, retries, and condenses the replies into labels such as open or filtered. That is useful for inventory and poor for validating one rule, because the label hides the packet that produced it. hping3 does contain a `--scan` mode, but a rule test does not use it: it uses single probes whose reply you read yourself. ## What a bare command sends The defaults come from the source tree (`docs/hping2.8`, `usage.c`, `hping2.h`) and surprise people who expect something ping-like: | Setting | Default | Option that changes it | |---|---|---| | Protocol | TCP | `-1` / `--icmp`, `-2` / `--udp`, `-0` / `--rawip` | | Destination port | 0 | `-p` | | TCP flags | none set | `-S`, `-A`, `-F`, `-R`, `-P`, `-U` (also `-X`, `-Y`) | | TCP window | 64 | `-w` | | Source port | random start, one higher per packet | `-s` sets the start, `-k` keeps it fixed | | IP time to live | 64 | `-t` | | Interval | one second | `-i` | | Count | no limit | `-c` | | ICMP probe (with `--icmp`) | echo request, code 0 | `-C`, `-K` | Because the default destination port is 0 and no flag is set, a bare `hping3 192.0.2.10` is almost never the test you mean. It is the first thing to correct in a review of someone's test script. ## Building one probe 1. Write down the expected answer first, from the change ticket: allowed, rejected or dropped. 2. Pick the protocol, the flag letter and the port that make that one combination. 3. Bound the run with `-c`, so it sends that many probes and then waits about a second for replies. 4. Run it from the network position the rule is about, since a rule that treats one source zone differently from another proves nothing from the wrong side. 5. Compare the reply with the expectation and with the firewall's own log line for the probe. A typical probe is `hping3 -S -p 443 -c 1 192.0.2.10`: one TCP SYN to port 443. ## Reading what comes back For TCP, each reply is one line, for example `len=46 ip=192.0.2.10 flags=SA DF seq=0 ttl=64 id=0 win=29200 rtt=0.4 ms` (the numbers here are illustrative). The flags field uses single letters (R reset, S SYN, A ACK, F FIN, P push, U urgent), and the ttl, id and win fields come from the replying device. An ICMP error prints as a line beginning `ICMP`, such as `ICMP Port Unreachable from ip=...`. When nothing answers, hping3 prints nothing for that probe, and the closing summary reports packets sent, packets received and the loss percentage. ## Authorisation and operation - hping3 opens a raw socket, so it normally needs elevated privilege; the source exits with "can't open raw socket" when it cannot. - Test only hosts and paths named in a written scope, in a change window you own, from a source address the owner of the sensors knows about. - Keep `-c` small and the interval at its one-second default; a test that needs more packets than a handful has usually stopped being a single-rule test. - Treat every reply as an inference. A reset can come from the host or from the firewall; silence can be a drop, a lost packet or a down host. The rest of this leaf covers how to tell them apart. ## Why this matters The default probe is a TCP packet with no flags to port 0, which no real client sends. A test that forgot to set flag and port tells you how the path treats malformed traffic, not whether the web port works, and an engineer who reads that result as "port 443 is blocked" has changed a firewall on a false premise.

  • Why does a test almost always carry -c, and what does hping3 do without it?
    The default count is unlimited, so hping3 keeps sending one probe a second until you interrupt it. With `-c 1` it sends one packet, then waits about a second for a reply and prints its summary, which bounds the traffic the firewall and any sensor see and makes the run repeatable.
  • What does hping3 print when a probe gets no reply at all?
    Nothing for that probe. The closing summary line then reports the packets sent, the packets received and a packet-loss percentage, so a silent run ends with zero received and 100% loss. The silence itself carries no reason; you need the firewall log or a control probe to say why.

  • A bare hping3 command sends an ICMP echo request like ping does
  • The default probe is a SYN to port 80
  • hping3 reports open, closed and filtered port states for you
  • It needs no elevated privilege because it only sends ordinary packets
  • A test can run without -c because the one-second pace is harmless