Skip to content

nmap C→Rust — M1: cli (the MVP works end-to-end) - #9

Merged
kj299 merged 1 commit into
masterfrom
claude/m1-cli
Jul 9, 2026
Merged

kj299 merged 1 commit into
masterfrom
claude/m1-cli

Conversation

@kj299

@kj299 kj299 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

What this is

The capstone of Milestone 1 — the cli module that wires argv → targets → ports → timing → connect_scan → output into the nmap-rs binary. nmap-rs -sT <target> now produces real nmap-style output end to end. All logic stays in core (pure) / sys (async I/O); the CLI is thin.

Changes

  • options — extended RunConfig + parse_args for the M1 CLI surface: -p (attached -p22 or separate -p 22), -oN/-oX/-oG <file|->, -6, -Pn, -sT, with option-argument handling. Unknown flags are still recorded, never mis-parsed.
  • main.rs (#[tokio::main]) — loads nmap-services (searched paths / NMAP_RS_DATADIR), selects ports (-p | top-1000 | 1-1024 fallback), resolves/expands targets (parse_target + sys::net::resolve_host, bounded by MAX_TARGETS), runs connect_scan, re-attaches hostnames, honors -Pn, and renders normal/XML/grepable to stdout or files. Typed errors + exit codes; no unwrap on user/network input.

Verified — live, end to end

$ nmap-rs -sT -p 22,80,8080,9999 127.0.0.1
Nmap scan report for 127.0.0.1
Host is up.
Not shown: 3 closed tcp ports (conn-refused)
PORT     STATE SERVICE
8080/tcp open  http-proxy
Nmap done: 1 IP address (1 host up) scanned in 0.00 seconds

-oX - emits proper nmap XML (with localhost→127.0.0.1 resolution, extraports, runstats); -oG - emits the grepable form; service names come from nmap-services.

  • fmt + clippy(-D warnings) + 47 core tests + 8 sys tests + unsafe-audit (0) + supply-chain clean — green.

Milestone 1: all 9 modules ported ✅

model · targets · options · log · ports · timing · net · connect_scan · output · cli. The MVP scanner is functional. Remaining M1 work: stand up the shared cargo-fuzz targets (target/port/services parsers) + the C-nmap differential oracle to formally close the fuzz/differential gate columns, then the M1 retrospective (which patches the kit — the non-negotiable compounding step).

🤖 Generated with Claude Code


Generated by Claude Code

The capstone. Wires argv -> targets -> ports -> timing -> connect_scan ->
output into the nmap-rs binary; all logic stays in core (pure) / sys (async I/O).

- options: extend RunConfig + parse_args for the M1 CLI surface — -p (attached
  or separate), -oN/-oX/-oG <file|->, -6, -Pn, -sT; option-argument handling;
  unknown flags still recorded, not mis-parsed.
- main.rs (#[tokio::main]): load nmap-services (searched paths / NMAP_RS_DATADIR),
  select ports (-p | top-1000 | 1-1024 fallback), resolve/expand targets
  (parse_target + sys::net::resolve_host, bounded by MAX_TARGETS), run
  connect_scan, re-attach hostnames, honor -Pn, render normal/XML/grepable to
  stdout or files. Typed errors + exit codes; no unwrap on user/net input.

Live end-to-end verified: `nmap-rs -sT -p 22,80,8080,9999 127.0.0.1` reports
8080/tcp open http-proxy (name from nmap-services) and "Not shown: 3 closed
tcp ports"; -oX/-oG and hostname resolution (localhost) all correct.

Gates: fmt + clippy(-D) + 47 core tests + 8 sys tests + unsafe-audit 0 +
supply-chain clean. All 9 M1 modules now ported. progress: cli -> ported.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
@kj299
kj299 marked this pull request as ready for review July 9, 2026 21:54
@kj299
kj299 merged commit ce023cb into master Jul 9, 2026
12 checks passed
kj299 added a commit that referenced this pull request Jul 10, 2026
The compounding step for Milestone 1 — patch PLAYBOOK/harnesses and append
LESSONS.md with what the nmap MVP taught the kit. Each edit names the failure it
prevents next time.

LESSONS #6 — scan_c_flaws read only .c/.h and reported nmap's ~9.4k LOC of C++
(.cc) as "0 flaws". Extension set widened to cover C++ (fix already in tree from
PR #2); now pinned with a self-test that iter_c_files yields .cc/.cpp/.hpp and
ignores non-source. Phase 0: confirm the scanner reads the target's languages
before believing a low count.

LESSONS #7 — diff_run.py is case-granular, so an MVP that intentionally renders a
subset of C output can't be diffed raw (every case diverges) or ledgered (the
whole case goes blind). Documented the canonical-projection pattern: wrap both
sides in a filter that emits only the semantic result, canonicalizing both
representations so real regressions still break the match. Phase 4 gate 2.

LESSONS #8 — Miri can't execute real I/O (tokio connect aborts under Miri).
Split the pure decision (verdict) from the syscall and cfg(miri)-ignore the I/O
tests, so "Miri can't run this" never becomes "no Miri coverage." Phase 4 gate 4.

LESSONS #9 — the linear six-gate model implies every module needs a fuzz tick,
but fuzzing is threat-model-scoped (parsers, not renderers/models). And
`cargo fuzz run <t> seeds/<t>` writes discovered inputs back into the seeds dir.
gen_fuzz_target.sh guidance now shows corpus/<t> seeds/<t> (writable, read-only)
and scopes the gate. Phase 4 gate 3.

Meta: 3 of 4 are the same shape as winlsof #2-#4 — a control that inspects less
than its green checkmark implies; the defense (retrospective step 0: run every
harness against the real target and eyeball what it inspected) held again.

check-kit: all harness self-tests + skills integrity green.


Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w

Co-authored-by: Claude <[email protected]>
kj299 added a commit that referenced this pull request Jul 19, 2026
The leaf every M4 packet parser stands on: read_u8/read_be_u16/u32/u64,
read_array::<N>, take/peek/skip each return Result, never index out of range,
never panic. checked_add on the offset stops a near-usize::MAX take() wrapping
into a false in-bounds read; a failed read leaves the cursor unmoved. Replaces
C's advance-a-pointer-and-trust-validate() pattern with a bounds check by
construction. 19 tests (incl. exhaustive buf-len x take-len sweep), miri clean,
forbid(unsafe). Differential/fuzz N/A for this leaf (LESSONS #9).
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