skip to content

How can lone hping3 probes with different TCP flags show, during a firewall change review, whether the rules track connection state or only match flag bits?

level: seniorimportance: should knowfreq 11%

answer

  1. a SYN opens, an ACK follows
  2. an ACK with no session
  3. reset reply versus silence
  4. same flow tuple each time
  5. still an inference

basics

~10 s

Send a SYN, then a lone ACK, to a published port. A reset to the session-less ACK suggests the rules match flag bits; silence fits state tracking. Confirm in the firewall log.

solid answer

~40 s

A SYN to the published port (`-S -p 443`) should be answered with `flags=SA`; that shows the allow rule works. Then send an ACK that belongs to no session (`-A -p 443`). A stateless filter that permits "established" traffic by matching ACK or RST bits lets it through, and the host's stack answers with a reset, so you see `flags=RA`. A device that tracks state finds no session for the packet and typically drops it, so you see nothing. Use `-k` so repeated probes share one source port. The reading is an inference: a stateful device can also reject invalid packets with a reset, so confirm which device acted from the firewall log before you report the rule set as stateful or stateless.

code

bash · 3 lines
bash
# Same host, port and source port for both probes
hping3 -S -p 443 -k -c 1 192.0.2.10   # expect flags=SA
hping3 -A -p 443 -k -c 1 192.0.2.10   # reset = flag match, silence = state

go deeper

for a junior

Recall that a SYN opens a connection and an ACK normally follows one, and that stateful devices check for a session.

for a middle

Explain the probe pair, why -k holds the flow constant, and how reset against silence points to flag matching against state.

for a senior

Treat the reply as an inference, name the alternative explanations, and settle it from the firewall log rather than the probe alone.

for a principal

Decide which behaviours a change must prove on every path and zone, and how those probes are recorded so the review is repeatable.

## The question a change reviewer asks A firewall change is often meant to admit inbound connections to one published service and replies to connections that inside hosts started, and nothing else. Two designs can look identical in a diagram. A **stateless** filter decides each packet alone, typically allowing anything that carries the ACK bit as "probably a reply". A **stateful** device keeps a table of sessions and allows a packet only if it belongs to one. hping3 lets you tell them apart with a handful of packets because you control the flags, which a port scanner's summary would hide. ## The probe pair Test against a host you own that runs the published service, from the source zone the rule is written for. 1. `-S -p 443 -c 1`: a SYN to the open port. Expect `flags=SA`. This is the allow rule, and it proves the path and the host are working, so it is also your control probe. 2. `-A -p 443 -c 1`: an ACK that belongs to no session. This is the one that distinguishes the designs. | Reply to the lone ACK | What it suggests | Caveat | |---|---|---| | `flags=RA` | The packet crossed the device and the host answered with a reset, so the rule probably matched the ACK bit, not a session | A device may also generate resets itself; check the log | | No reply | The packet was dropped, consistent with a table that has no entry for it | A lost packet or a host-side drop looks the same | | An `ICMP ... from ip=` line | A device refused it explicitly | Note which device sent it | An analogy: a stateless filter checks the label on each parcel, and a stateful one checks the delivery manifest. A parcel labelled "reply" passes the label check even if nobody ordered it, but it fails the manifest check. ## Keeping the flow identical hping3 raises the source port by one for each packet unless told otherwise, so repeated probes belong to different flows. A state table keys on the flow, so when you compare a SYN and an ACK, hold the source port fixed with `-k` (and set the start with `-s` if the rule cares), or the comparison is muddied. The manual describes `-s` as the base source port and `-k` as keeping it still. ## Why the reading is only an inference - hping3 sends raw packets and does not keep a connection open, so it tests the rule set's reaction to individual packets, not to a full session. - Some stateful devices answer an invalid packet with a reset instead of dropping it, which would mimic a stateless pass. - A host's own firewall may drop the ACK, which looks like a stateful drop. - Different sources, zones, interfaces or rule orders can give different answers; the result holds for the path you tested. The firewall's log is what settles it: it shows whether a rule matched, whether the device saw the packet as invalid for its session table, and which action it took. ## A worked example The ticket says: allow inbound to 192.0.2.10 port 443, and replies only. From the outside zone, `-S -p 443` returns `flags=SA` and the lone ACK returns nothing. The reviewer writes that this is consistent with state tracking, and attaches the log line showing the drop for that source and time, to be confirmed. Had the ACK returned `flags=RA` with the same ttl as the host's own replies, the note would read that the ACK reached the host, so the rule appears to match the ACK bit, and a finding is opened if the design requires state tracking. ## Writing the result up State the probes, the source zone, the replies and the log lines, and say "consistent with state tracking" or "consistent with flag-based matching" instead of a flat verdict. Name what you did not test, such as other source zones. The comparison is only sound when the same source port and target were used for both probes, which is why -k matters. ## Rules of engagement Probe only the host and port in your written scope, in the change window, with the log owners told which source address to expect, and keep the count at one or two per combination.

  • Why hold the source port fixed with -k when comparing probes?
    hping3 raises the source port by one per packet by default, so each probe would be a different flow. A state table keys on the flow, so with differing ports the SYN and the ACK are not related by the device. `-k` keeps one source port, and `-s` sets where it starts.
  • The lone ACK is dropped, but you still doubt the firewall tracks state. What explains it?
    A host-side filter may be discarding it, or the packet or reply may have been lost. Repeat the probe, send the same ACK to a port with no listener to see whether the host's own stack answers, and read the firewall log for an invalid-session or rule-match entry before you conclude.

A stateless filter checks the label on each parcel; a stateful one checks the delivery manifest. A parcel labelled reply passes the label check even if nobody ordered it, but it fails the manifest check.

  • A reset reply to a lone ACK proves the firewall tracks state
  • hping3 holds a full connection open to test the session table
  • Silence to a lone ACK proves the rule set is stateful
  • One probe pair from one source zone covers every path through the firewall
  • A stateful device can never answer a packet with a reset