Repository navigation
Rewrite nmap C→Rust (Windows) — Milestone 0: foundation - #1
Merged
Merged
Conversation
Foundation for the safety-first C->Rust rewrite of nmap (Windows-targeted),
driven by the c2rust-port Porting Kit. No C source is modified; the C tree
becomes the differential oracle.
- Vendor the kit into porting-kit/ (docs, runnable harnesses, skills).
- Symlink porting-kit skills into .claude/skills/ (integrity check clean).
- Stand up nmap-rs/ Cargo workspace from the kit skeleton:
- core (#![forbid(unsafe_code)]) / sys (only unsafe; audited) / cli (nmap-rs bin)
- workspace safety lints (overflow-checks, arithmetic_side_effects,
cast_possible_truncation, undocumented_unsafe_blocks, missing_safety_doc)
- TRACE env-gated phase logger scaffolded day one (NMAP_RS_TRACE)
- deny.toml for the supply-chain gate
- Wire path-scoped CI (nmap-rs-ci.yml) for the safety gates; exclude nmap-rs/**
and porting-kit/** from the C build.yml so neither pipeline triggers the other
(kit LESSONS #5).
- make check-kit green; cargo fmt/clippy/test green; unsafe-audit 0 undocumented.
Kit findings for the eventual retrospective: the kit skeleton's own placeholder
code failed the workspace's own gates (clippy arithmetic_side_effects on `i + 1`;
not rustfmt-clean) — fixed here; candidates for a LESSONS entry.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
…=false CI supply-chain gate failed: the kit's vendored deny.template.toml uses the pre-0.18 key `wildcard-dependencies`, which current cargo-deny (0.19.9) rejects (renamed to `wildcards`). Rewrote deny.toml to the v2 schema and set `allow-wildcard-paths = true`. That alone wasn't enough: cargo-deny's wildcard exemption for path deps does not apply to *publishable* crates. These are application crates never published to crates.io, so mark each `publish = false` — now the intra-workspace path deps pass the `wildcards = "deny"` gate. Verified locally: `cargo deny check` → advisories ok, bans ok, licenses ok, sources ok (exit 0). Kit finding for the retrospective: porting-kit deny.template.toml is stale vs cargo-deny 0.18+ (wildcard-dependencies -> wildcards) and its wildcards="deny" default breaks a path-only workspace unless crates are publish=false. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
Full C->Rust roadmap driven by the c2rust-port kit: M0 foundation (done) through connect-scan MVP, async engine, service/OS detection, raw scanning, signature-DB maintenance, and NSE. Status tracker reflects M0 complete / M1 current so the phase is not lost across sessions. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
kj299
marked this pull request as ready for review
July 9, 2026 06:12
This was referenced Jul 9, 2026
kj299
pushed a commit
that referenced
this pull request
Jul 18, 2026
…(six gates) The service-detection match engine — the Rust analog of ServiceProbeMatch::testMatch / ServiceProbe::testMatch. Given a probe's match/softmatch rules and a target banner, decide the service. This is M3's highest-risk module: every byte matched is attacker-chosen, so the banner is the #1 fuzz target. The hybrid engine (the M3-1 spike's decision, now built): - Linear default: regex::bytes (Unicode off) on raw bytes — the ~93.6% path, a finite automaton with a linear-time guarantee, so ReDoS is UNEXPRESSIBLE (strictly safer than the C's leashed PCRE2). - Bounded-backtracking fallback: fancy-regex with an explicit backtrack_limit (the analog of nmap's match_limit=50000); exceeding it yields "no match", never a hang. It is &str-only, so a binary banner is matched through a latin-1 bijection (byte b <-> char U+00b) and captures are mapped back to bytes — exact because every backtracking pattern in the corpus is ASCII. Result: all 12,171 shipped rules compile (100% coverage, 0 dropped) — the improved pcre_translate (literal-[-in-class rewrite) erased the spike's ~9-pattern residual. Degrade, not abort (DIVERGENCES.md): - matcher-empty-match-drop: a rule whose regex can match "" is dropped with a warning (nmap fatal()s via PCRE2_INFO_MATCHEMPTY); would mislabel every port. - a rule neither engine accepts is dropped with a warning (never fatal); never fires on the shipped DB, only hostile/custom --versiondb. Six gates: - ported: crates/core/src/matcher.rs (forbid(unsafe_code)), 11 unit tests incl. fancy-engine binary capture round-trip and first-match-wins ordering - differential: tests/matcher_corpus.rs compiles all 12,171 real rules (100%, 0 dropped), matches real ssh/ftp banners, total over hostile banners - fuzzed: fuzz target matcher (compile arbitrary pattern + match arbitrary banner), 200k+ runs, 0 crashes; the (a+)+$ ReDoS seed does not hang - sanitized: miri clean on all 11 unit tests - unsafe-audited: 0 unsafe (regex/fancy-regex expose safe APIs) - supply-chain: cargo audit + deny clean with the two new deps; corpus test pins Version-string substitution ($1/$P/...) is the next module (core::versioninfo); the matcher returns the raw capture groups it will consume. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
kj299
pushed a commit
that referenced
this pull request
Jul 19, 2026
…(six gates) The service-detection match engine — the Rust analog of ServiceProbeMatch::testMatch / ServiceProbe::testMatch. Given a probe's match/softmatch rules and a target banner, decide the service. This is M3's highest-risk module: every byte matched is attacker-chosen, so the banner is the #1 fuzz target. The hybrid engine (the M3-1 spike's decision, now built): - Linear default: regex::bytes (Unicode off) on raw bytes — the ~93.6% path, a finite automaton with a linear-time guarantee, so ReDoS is UNEXPRESSIBLE (strictly safer than the C's leashed PCRE2). - Bounded-backtracking fallback: fancy-regex with an explicit backtrack_limit (the analog of nmap's match_limit=50000); exceeding it yields "no match", never a hang. It is &str-only, so a binary banner is matched through a latin-1 bijection (byte b <-> char U+00b) and captures are mapped back to bytes — exact because every backtracking pattern in the corpus is ASCII. Result: all 12,171 shipped rules compile (100% coverage, 0 dropped) — the improved pcre_translate (literal-[-in-class rewrite) erased the spike's ~9-pattern residual. Degrade, not abort (DIVERGENCES.md): - matcher-empty-match-drop: a rule whose regex can match "" is dropped with a warning (nmap fatal()s via PCRE2_INFO_MATCHEMPTY); would mislabel every port. - a rule neither engine accepts is dropped with a warning (never fatal); never fires on the shipped DB, only hostile/custom --versiondb. Six gates: - ported: crates/core/src/matcher.rs (forbid(unsafe_code)), 11 unit tests incl. fancy-engine binary capture round-trip and first-match-wins ordering - differential: tests/matcher_corpus.rs compiles all 12,171 real rules (100%, 0 dropped), matches real ssh/ftp banners, total over hostile banners - fuzzed: fuzz target matcher (compile arbitrary pattern + match arbitrary banner), 200k+ runs, 0 crashes; the (a+)+$ ReDoS seed does not hang - sanitized: miri clean on all 11 unit tests - unsafe-audited: 0 unsafe (regex/fancy-regex expose safe APIs) - supply-chain: cargo audit + deny clean with the two new deps; corpus test pins Version-string substitution ($1/$P/...) is the next module (core::versioninfo); the matcher returns the raw capture groups it will consume. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w
kj299
added a commit
that referenced
this pull request
Jul 19, 2026
…23) * M3 module 3/6 — core::matcher: hybrid service-detection regex engine (six gates) The service-detection match engine — the Rust analog of ServiceProbeMatch::testMatch / ServiceProbe::testMatch. Given a probe's match/softmatch rules and a target banner, decide the service. This is M3's highest-risk module: every byte matched is attacker-chosen, so the banner is the #1 fuzz target. The hybrid engine (the M3-1 spike's decision, now built): - Linear default: regex::bytes (Unicode off) on raw bytes — the ~93.6% path, a finite automaton with a linear-time guarantee, so ReDoS is UNEXPRESSIBLE (strictly safer than the C's leashed PCRE2). - Bounded-backtracking fallback: fancy-regex with an explicit backtrack_limit (the analog of nmap's match_limit=50000); exceeding it yields "no match", never a hang. It is &str-only, so a binary banner is matched through a latin-1 bijection (byte b <-> char U+00b) and captures are mapped back to bytes — exact because every backtracking pattern in the corpus is ASCII. Result: all 12,171 shipped rules compile (100% coverage, 0 dropped) — the improved pcre_translate (literal-[-in-class rewrite) erased the spike's ~9-pattern residual. Degrade, not abort (DIVERGENCES.md): - matcher-empty-match-drop: a rule whose regex can match "" is dropped with a warning (nmap fatal()s via PCRE2_INFO_MATCHEMPTY); would mislabel every port. - a rule neither engine accepts is dropped with a warning (never fatal); never fires on the shipped DB, only hostile/custom --versiondb. Six gates: - ported: crates/core/src/matcher.rs (forbid(unsafe_code)), 11 unit tests incl. fancy-engine binary capture round-trip and first-match-wins ordering - differential: tests/matcher_corpus.rs compiles all 12,171 real rules (100%, 0 dropped), matches real ssh/ftp banners, total over hostile banners - fuzzed: fuzz target matcher (compile arbitrary pattern + match arbitrary banner), 200k+ runs, 0 crashes; the (a+)+$ ReDoS seed does not hang - sanitized: miri clean on all 11 unit tests - unsafe-audited: 0 unsafe (regex/fancy-regex expose safe APIs) - supply-chain: cargo audit + deny clean with the two new deps; corpus test pins Version-string substitution ($1/$P/...) is the next module (core::versioninfo); the matcher returns the raw capture groups it will consume. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w * matcher: decode the latin-1 banner once per probe, not once per rule Optimization (behavior-identical). The backtracking engine is &str-only, so a binary banner is decoded to a latin-1 String before matching. The previous code rebuilt that String inside every backtracking rule's captures/is_match; a probe with many backtracking rules (the NULL probe has ~120) therefore re-decoded the same banner once per rule. CompiledProbe::test / matches now build the latin-1 view at most once per call (lazily, only if a backtracking rule is reached) and share it across rules via CompiledRule::captures_with / is_match_with. Linear rules never touch it. Measured: ~10% faster on the worst case (8 KB non-matching banner walked against the whole NULL probe: 12955 -> 11714 us/call); the win scales with banner size and is never negative. No semantic change — the 12,171-rule corpus still compiles 100%, all 11 unit tests pass, miri clean, fuzz 127k+ runs 0 crashes. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01JfEzHqD7a7TKDuUs5GwZ2w --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
The first milestone of a long, multi-milestone safety-first C→Rust rewrite of nmap targeting Windows, driven by the
c2rust-portPorting Kit. The full plan (milestone ladder M0→M7 + a signature-DB-maintenance workstream) was agreed separately.Prime directive: the Rust must be safer and more secure than the C, not merely equivalent. The C tree is the specification (and the differential oracle) — no C source is modified.
Milestone 0 — Foundation (this PR)
porting-kit/(docs, runnable harnesses, skills) and symlinked theporting-kit-*skills into.claude/skills/(integrity check clean;make -C porting-kit check-kitgreen).nmap-rs/— a Cargo workspace from the kit skeleton, encoding unsafe-isolation structurally:crates/core—#[forbid(unsafe_code)]; where most ported logic will live.crates/sys— the only crate permittedunsafe; every block audited (// SAFETY:). ~0 unsafe expected through the MVP.crates/cli— thin; binarynmap-rs(coexists with Cnmapduring the port).overflow-checks,arithmetic_side_effects,cast_possible_truncation,undocumented_unsafe_blocks,missing_safety_doc);deny.toml; aNMAP_RS_TRACEenv-gated phase logger scaffolded on day one..github/workflows/nmap-rs-ci.yml) for the safety gates, and excludednmap-rs/**+porting-kit/**from the Cbuild.ymlso neither pipeline triggers the other (kit LESSONS nmap C→Rust — M1: core::timing (RTT estimator + -T0..-T5 templates) #5). Fuzz + differential gates are wired but self-skip until Milestone 1 supplies their inputs.Gates (all green locally)
cargo fmt --check·cargo clippy -D warnings·cargo test· unsafe-audit (0 undocumented) ·make check-kit.Notes
clippy::arithmetic_side_effectsoni + 1; not rustfmt-clean) — fixed here; a candidate LESSONS entry to feed upstream.x86_64-pc-windows-msvc;corebuilds/tests on the Linux CI runner every push regardless of target.Next
Milestone 1 — the MVP vertical slice: unprivileged TCP connect scan + host discovery + normal/grepable/XML output, verified by same-binary differential against C nmap. Begins with
porting-kit-kickoff(Phase 0 inventory + C-flaw scan + threat model) ∥porting-kit-oracle.🤖 Generated with Claude Code
Generated by Claude Code