Skip to content

M4 — ICMP back-fill for the SYN and flag scans (core::icmp_quote) - #57

Merged
kj299 merged 1 commit into
masterfrom
claude/m4-icmp-backfill
Jul 25, 2026
Merged

kj299 merged 1 commit into
masterfrom
claude/m4-icmp-backfill

Conversation

@kj299

@kj299 kj299 commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Backlog #2's last sub-slice. An ICMP destination-unreachable (type 3) or time-exceeded (type 11) quotes the packet that provoked it, so it can be matched back to the probe it answers. The UDP scan used this from the start; core::icmp_quote generalizes the quote parser to TCP and shares it with -sS and all six flag scans.

This matters most for -sF/-sN/-sX/-sM, whose no-response default is open|filtered: without ICMP matching those scans could never report a port as filtered at all.

What lands

core::icmp_quote (new) — parse_icmp_error yields the three addresses that are not interchangeable:

field meaning
sender who sent the error — legitimately an intermediate router
quoted_src source of the quoted packet — must be us
quoted_dst where our probe was going — the host the verdict belongs to

from_target is then just sender == quoted_dst. Also ports portreasons.cc: icmp_to_reason, and becomes the single home of ipv4_offset, which all three matchers previously carried their own copy of — closing the "DRY the scan matchers" follow-up.

core::synscan — match_tcp_icmp_error, shared with the flag scans since the quote-matching rules are identical. The quote contains our original packet, so unlike a RST (which reflects no sequence of ours) the encoded sequence is present and is verified, as the C compares th_seq to probe->tcpseq(). That makes a flag scan's ICMP path better authenticated than its RST path.

The three reply structs now carry the reason they matched on, so a filtered port reports the specific code instead of a generic no-response.

sys::group — MatchParams groups the per-scan match constants and carries our source address; the SYN and flag BPF filters now also admit ICMP, without which the errors never reach the matcher at all.

Two findings from reading the C — one corrects this port

1. A ledger claim in #55 was wrong, and I've fixed it. That PR said attributing an ICMP error to the quoted destination was "stricter than the C". It isn't — the C does the same thing (findHost(&encaps_hdr.dst), then from_target against the outer source). DIVERGENCES.md now records it as a structural note with an explicit correction. The ledger ships as release notes, so an overstated security claim is worth fixing directly.

2. A real gap in our own UDP path. The C requires the quoted packet's source to be our address — "If it didn't come from us, we don't care." We never checked it. The port/attempt encoding limited the impact, but a crafted error quoting a third party's packet could be accepted. All three scans now enforce it, which is why every match context carries our_ip.

Verification

  • core::icmp_quote: 8 unit tests, including every truncation of a valid frame, non-quoting ICMP types, a non-IPv4 quote, and a sub-minimum IHL.
  • SYN: all 8 accepted type/code pairs → filtered with the right reason; router-relayed error lands on the probed host; rejects a quote of someone else's packet, a foreign sequence, an out-of-range attempt, and a UDP quote.
  • Flag scans: all six report filtered from an ICMP error; -sF shown going open|filtered → filtered with and without the error, which is the back-fill's whole point.
  • Group engine: ICMP demux across two hosts — a router's error for .3 does not land on .2, and only .3 gets an ICMP reason.

Gates

fmt + clippy (default and all-features) on pinned 1.97.0 · 335 core tests · miri clean · unsafe-audit 11/11 documented, 0 undocumented (no new unsafe) · fuzz match_syn 5.0M / match_udp 5.7M / match_flag 1.8M / services_probes_parse 290k runs, no crashes · all four privileged e2e suites pass as root. Rebased onto master after #56 merged and re-verified.

Ledger

synscan-icmp-match-deferred and flagscan-icmp-match-deferred resolved; udpscan-icmp-attributed-to-quoted-destination corrected; new icmp-quote-requires-our-source, icmp-quote-verifies-our-sequence, icmp-reason-fidelity, icmp-bpf-widened-for-tcp-scans.

Backlog #2 is now complete. Next in the plan of record is backlog #3 — M5, OS detection (osscan2 + nmap-os-db, IPv6 FPEngine).

🤖 Generated with Claude Code

https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w


Generated by Claude Code

Backlog #2's last sub-slice. An ICMP destination-unreachable (type 3) or
time-exceeded (type 11) quotes the packet that provoked it, so it can be
matched back to the probe it answers. The UDP scan used this from the
start; core::icmp_quote generalizes the quote parser to TCP and shares it
with -sS and all six flag scans.

This matters most for -sF/-sN/-sX/-sM, whose no-response default is
open|filtered: without ICMP matching those scans could never report a port
as filtered at all.

core::icmp_quote (new)
  - parse_icmp_error yields the three addresses that are NOT interchangeable:
    the sender (may be a router), the quoted source (must be us), and the
    quoted destination (the host the verdict belongs to). from_target is
    then just sender == quoted_dst.
  - icmp_to_reason ports portreasons.cc, including that codes 9/10/13 are
    three distinct reasons in nmap, not one "admin-prohibited".
  - Also now the single home of ipv4_offset, which all three matchers had
    their own copy of — closing the "DRY the scan matchers" follow-up.

core::synscan
  - match_tcp_icmp_error, shared with the flag scans since the quote rules
    are identical. The quote contains our original packet, so unlike a RST
    (which reflects no sequence of ours) the encoded sequence IS present and
    is verified, as the C compares th_seq to probe->tcpseq().
  - SynReply/FlagReply/UdpReply now carry the reason they matched on, so a
    filtered port reports the specific code rather than "no-response".

sys::group
  - MatchParams groups the per-scan match constants and carries our source
    address; the SYN and flag BPF filters now also admit ICMP, without which
    the errors never reach the matcher.

Two findings from reading the C, one of which corrects this port:

1. The #55 ledger claimed attributing an ICMP error to the quoted
   destination was "stricter than the C". That was wrong: the C does the
   same (findHost(&encaps_hdr.dst), then from_target against the outer
   source). Corrected in DIVERGENCES.md — it is a structural note, not a
   hardening. The ledger ships as release notes, so accuracy matters.

2. A real gap in our own UDP path: the C requires the quoted packet's
   source to be our address ("If it didn't come from us, we don't care")
   and we never checked it. All three scans now enforce it, which is why
   every match context carries our_ip.

Gates: fmt + clippy (default and all-features) on 1.97.0; 335 core tests;
miri clean; unsafe-audit 11/11 documented, 0 undocumented; fuzz match_syn
5.0M / match_udp 5.7M / match_flag 1.8M / services_probes_parse 290k runs,
no crashes; all four privileged e2e suites pass as root.

Ledger: synscan-icmp-match-deferred and flagscan-icmp-match-deferred
resolved; udpscan-icmp-attributed-to-quoted-destination corrected; new
icmp-quote-requires-our-source, icmp-quote-verifies-our-sequence,
icmp-reason-fidelity, icmp-bpf-widened-for-tcp-scans.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
@kj299
kj299 marked this pull request as ready for review July 25, 2026 14:07
@kj299
kj299 merged commit 892b31e into master Jul 25, 2026
12 checks passed
kj299 pushed a commit that referenced this pull request Nov 14, 2026
Three of the six are older lessons that did not fire (#42 CI liveness,
#41 review every step, #47 defaults are inputs); each now has a command
that fails. The others:
- #56: Phase 0 read nmap's --send-eth path as its default, and the
  claim stood four steps because the oracle could not run here. The
  threat model gains a register of claims read but not measured, each
  traced from the option's default, and a table of the checks each
  received message's standard requires of a receiver. The flaw scanner
  found 0 of the milestone's 3 C defects: each is an absent check.
- #57: a flag a gate script passes on every run is a matrix column with
  one value (-Pn hid a two-milestone-old defect).
PLAYBOOK (400 lines), REVIEW-GATE, ORACLE-CHECKS, the prompts and all six
skills carry them; check-kit passes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
kj299 pushed a commit that referenced this pull request Nov 14, 2026
… retrospective

The kit's CI template passes --src to `progress.py audit`, so that a
gate tick whose code has changed fails (LESSONS #45). nmap's workflow
never did, and STALE-TICK could fire only on a local run (LESSONS #57).

PLAN.md records that the IPv6-scans milestone merged with no CI run on
any of its commits, and what its retrospective changed in the kit.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
kj299 added a commit that referenced this pull request Nov 14, 2026
Porting kit: IPv6-scans retrospective (LESSONS #52–#57); M7 cutover gate Phase 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants