feat(binaries): hardening, signatures, .NET references and Intel HEX checks of committed binaries (#495) #501

Merged
sharang merged 2 commits from feat/495-binary-depth into main 2026-10-06 11:40:55 +00:00
Owner

Closes #495. On top of the committed-binary inventory (#465). Stage only.

Library choice: native Rust, no Python helper

  • PE/ELF headers: the object crate (gimli-rs, Apache-2.0 OR MIT), v0.36.7. It is already in the build: firmwerk-sbom pulls it in with read + std (elf, pe, coff …). compliance-agent declares the same version and features, so cargo tree shows no new crate. Cargo.lock gains one line (the dependency edge).
  • .NET AssemblyRefs: a small ECMA-335 reader of our own (binary_depth/dotnet.rs, about 200 lines). It reads the CLR header, the BSJB metadata root, the #~ row counts and the row widths of tables 0x00–0x22, then the AssemblyRef table and #Strings. There is no mature, permissive Rust crate for this: dotscope (Apache-2.0) is young, has little adoption and is 3.5 MB. This is the one place where native Rust had nothing ready-made.
  • Intel HEX: about 100 lines of our own (binary_depth/ihex.rs). The format is frozen; the ihex crate (MIT/Apache, last release 2020) would add a dependency for less control over line-level errors.
  • LIEF (Apache-2.0), dnfile (MIT) and intelhex (BSD-3) are not used. They would need Python in the agent image plus a helper process.
  • Image size: no new crate, no Python, no Dockerfile change. The only growth is the new code in the agent binary.

What is extracted (pipeline/binary_depth/)

File Evidence on the inventory finding Gap findings (rule, severity)
PE ASLR (DYNAMICBASE and relocations), high-entropy ASLR (PE32+), DEP, CFG, SafeSEH (PE32 x86), /GS (load-config security cookie), Authenticode present (not verified) binary-no-aslr Low, binary-no-nx Low, binary-no-high-entropy-va Info, binary-no-cfg Info, binary-no-safeseh Info, binary-no-stack-protector Info, binary-unsigned Info
.NET (IL-only) References N assemblies: name version, … (the first 40 listed; all kept in Binary.depth.assembly_refs). CFG/SafeSEH/GS are n/a binary-unsigned Info, ASLR/DEP as for PE
native PE Candidates from the version resource (low confidence, for NVD matching): cpe:2.3:a:<vendor>:<product>:<version>:…, pkg:generic/<vendor>/<product>@<version> –
ELF, dynamically linked RELRO none/partial/full, NX (PT_GNU_STACK), PIE (DF_1_PIE / interpreter; n/a for a .so), stack protector (__stack_chk_fail), FORTIFY (__*_chk vs. fortifiable imports) binary-no-relro Low, binary-partial-relro Info, binary-no-nx Low, binary-no-aslr Low, binary-no-stack-protector Info, binary-no-fortify Info
ELF, static or bare-metal; .o … not assessed (no loader, so no RELRO/ASLR by design) –
Intel HEX records, data bytes, merged address ranges, start address, Every record checksum is valid. or what is wrong (checksum lines, non-records, overlaps, missing EOF, records after EOF) binary-hex-invalid Low
  • Gap findings use the binary-inventory scanner, ScanType::Malware (the LLM triage skips them as binary) and fingerprint (repo, rule, path, SHA-256). Their title and description cover the whole rule, so a group of more than five (#477) reads correctly; the file is the place.
  • ELF and HEX are read whole up to 64 MiB; a larger file says so. PE reads stay at the 32 MiB of #465.
  • Checked against real local files (not committed): native and .NET PE32/PE32+, an ILMerged assembly, a signed PE, distro ELF executables and libraries, a gcc -no-pie -z norelro build and the nightly bootloader.hex. The flags agree with objdump -p and readelf -lWd.

Control map

  • New field ScanBinding.attach_only (control-map/src/lib.rs). Such a binding links findings to its control but never makes the control count as checked (applies_to → false). Without it, the binary stage would mark cra-ai-1 "no violation found" for any language (for example a Go repo with no binaries).
  • cra_control_map.json, two bindings with tool: binary-inventory:
    • cra-ai-1: binary-no-aslr, binary-no-nx, binary-no-relro;
    • cra-ai-6: binary-hex-invalid.
  • Deliberately unmapped: binary-unsigned and the defence-in-depth extras (CFG, SafeSEH, /GS, FORTIFY, high-entropy ASLR, partial RELRO). They are Info, and many legitimate in-house DLLs lack them. Binding them would fail the control on noise.
  • These findings have no line, so the control triage never reads them. binaries::gap_finding stamps control_refs from the map directly, by rule id.
  • every_code_binding_names_its_languages now allows binary-inventory to have no languages.
  • ⚠️ For #492/#494: this PR touches cra_control_map.json (only the two scans entries above) and ScanBinding. Rebase on top of it and keep the new field. The control-map source hash changes, so evidence reports show a new mapping version.

Not done / follow-ups

  • No SBOM hunk. AssemblyRefs are evidence text plus Binary.depth.assembly_refs, ready for the #474 NuGet mapping. CPE/purl candidates are evidence text only; feeding them to the NVD lookup would touch cve.rs (#493/#496). Both are left for a follow-up.
  • Authenticode is detected, not verified (no chain or hash check).
  • No Mach-O hardening, no S-record/UF2 checks.
  • An inventory finding stored before this change keeps its old description: stored single findings are not rewritten. New gap findings appear on the next rescan.

Touched outside the new module

  • binaries.rs: a depth field, evidence in the description, findings().
  • orchestrator.rs: map → flat_map(binaries::findings), one line.
  • Cargo.toml: object.
  • control-map: the field and the map bindings described above.
  • No changes to dedup/fingerprints, finding_store, rules/vendor, cve.rs or the SBOM.

Checks

  • cargo fmt, cargo clippy -p compliance-agent --all-targets -- -D warnings, cargo clippy -p control-map --all-targets -- -D warnings.
  • cargo test -p compliance-agent --lib: 725 passed (rebased on #497 and #500). cargo test -p control-map: passed.
  • The tests build their PE/ELF fixtures byte by byte, so no third-party binaries are committed. The nightly baseline is unchanged (bootloader.hex is valid).
  • Staging test plan: check 20 appended (after #491's 18 and #493's 19), marked [visible].

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB

Closes #495. On top of the committed-binary inventory (#465). Stage only. ## Library choice: native Rust, no Python helper - **PE/ELF headers:** the `object` crate (gimli-rs, Apache-2.0 OR MIT), v0.36.7. It is already in the build: `firmwerk-sbom` pulls it in with `read` + `std` (elf, pe, coff …). `compliance-agent` declares the same version and features, so `cargo tree` shows **no new crate**. `Cargo.lock` gains one line (the dependency edge). - **.NET AssemblyRefs:** a small ECMA-335 reader of our own (`binary_depth/dotnet.rs`, about 200 lines). It reads the CLR header, the `BSJB` metadata root, the `#~` row counts and the row widths of tables 0x00–0x22, then the AssemblyRef table and `#Strings`. There is no mature, permissive Rust crate for this: `dotscope` (Apache-2.0) is young, has little adoption and is 3.5 MB. This is the one place where native Rust had nothing ready-made. - **Intel HEX:** about 100 lines of our own (`binary_depth/ihex.rs`). The format is frozen; the `ihex` crate (MIT/Apache, last release 2020) would add a dependency for less control over line-level errors. - LIEF (Apache-2.0), dnfile (MIT) and intelhex (BSD-3) are **not** used. They would need Python in the agent image plus a helper process. - **Image size:** no new crate, no Python, no Dockerfile change. The only growth is the new code in the agent binary. ## What is extracted (`pipeline/binary_depth/`) | File | Evidence on the inventory finding | Gap findings (rule, severity) | |---|---|---| | PE | ASLR (DYNAMICBASE and relocations), high-entropy ASLR (PE32+), DEP, CFG, SafeSEH (PE32 x86), /GS (load-config security cookie), Authenticode present (not verified) | `binary-no-aslr` Low, `binary-no-nx` Low, `binary-no-high-entropy-va` Info, `binary-no-cfg` Info, `binary-no-safeseh` Info, `binary-no-stack-protector` Info, `binary-unsigned` Info | | .NET (IL-only) | `References N assemblies: name version, …` (the first 40 listed; all kept in `Binary.depth.assembly_refs`). CFG/SafeSEH/GS are n/a | `binary-unsigned` Info, ASLR/DEP as for PE | | native PE | `Candidates from the version resource (low confidence, for NVD matching): cpe:2.3:a:<vendor>:<product>:<version>:…, pkg:generic/<vendor>/<product>@<version>` | – | | ELF, dynamically linked | RELRO none/partial/full, NX (PT_GNU_STACK), PIE (DF_1_PIE / interpreter; n/a for a `.so`), stack protector (`__stack_chk_fail`), FORTIFY (`__*_chk` vs. fortifiable imports) | `binary-no-relro` Low, `binary-partial-relro` Info, `binary-no-nx` Low, `binary-no-aslr` Low, `binary-no-stack-protector` Info, `binary-no-fortify` Info | | ELF, static or bare-metal; `.o` | `… not assessed` (no loader, so no RELRO/ASLR by design) | – | | Intel HEX | records, data bytes, merged address ranges, start address, `Every record checksum is valid.` or what is wrong (checksum lines, non-records, overlaps, missing EOF, records after EOF) | `binary-hex-invalid` Low | - Gap findings use the `binary-inventory` scanner, `ScanType::Malware` (the LLM triage skips them as `binary`) and fingerprint (repo, rule, path, SHA-256). Their title and description cover the whole rule, so a group of more than five (#477) reads correctly; the file is the place. - ELF and HEX are read whole up to 64 MiB; a larger file says so. PE reads stay at the 32 MiB of #465. - Checked against real local files (not committed): native and .NET PE32/PE32+, an ILMerged assembly, a signed PE, distro ELF executables and libraries, a `gcc -no-pie -z norelro` build and the nightly `bootloader.hex`. The flags agree with `objdump -p` and `readelf -lWd`. ## Control map - **New field `ScanBinding.attach_only`** (`control-map/src/lib.rs`). Such a binding links findings to its control but never makes the control count as checked (`applies_to` → false). Without it, the binary stage would mark cra-ai-1 "no violation found" for any language (for example a Go repo with no binaries). - `cra_control_map.json`, two bindings with `tool: binary-inventory`: - cra-ai-1: `binary-no-aslr`, `binary-no-nx`, `binary-no-relro`; - cra-ai-6: `binary-hex-invalid`. - **Deliberately unmapped:** `binary-unsigned` and the defence-in-depth extras (CFG, SafeSEH, /GS, FORTIFY, high-entropy ASLR, partial RELRO). They are Info, and many legitimate in-house DLLs lack them. Binding them would fail the control on noise. - These findings have no line, so the control triage never reads them. `binaries::gap_finding` stamps `control_refs` from the map directly, by rule id. - `every_code_binding_names_its_languages` now allows `binary-inventory` to have no languages. - ⚠️ **For #492/#494:** this PR touches `cra_control_map.json` (only the two `scans` entries above) and `ScanBinding`. Rebase on top of it and keep the new field. The control-map source hash changes, so evidence reports show a new mapping version. ## Not done / follow-ups - **No SBOM hunk.** AssemblyRefs are evidence text plus `Binary.depth.assembly_refs`, ready for the #474 NuGet mapping. CPE/purl candidates are evidence text only; feeding them to the NVD lookup would touch `cve.rs` (#493/#496). Both are left for a follow-up. - Authenticode is detected, not verified (no chain or hash check). - No Mach-O hardening, no S-record/UF2 checks. - An inventory finding stored before this change keeps its old description: stored single findings are not rewritten. New gap findings appear on the next rescan. ## Touched outside the new module - `binaries.rs`: a `depth` field, evidence in the description, `findings()`. - `orchestrator.rs`: `map` → `flat_map(binaries::findings)`, one line. - `Cargo.toml`: `object`. - `control-map`: the field and the map bindings described above. - No changes to `dedup`/fingerprints, `finding_store`, `rules/vendor`, `cve.rs` or the SBOM. ## Checks - `cargo fmt`, `cargo clippy -p compliance-agent --all-targets -- -D warnings`, `cargo clippy -p control-map --all-targets -- -D warnings`. - `cargo test -p compliance-agent --lib`: 725 passed (rebased on #497 and #500). `cargo test -p control-map`: passed. - The tests build their PE/ELF fixtures byte by byte, so no third-party binaries are committed. The nightly baseline is unchanged (`bootloader.hex` is valid). - Staging test plan: check 20 appended (after #491's 18 and #493's 19), marked **[visible]**. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang force-pushed feat/495-binary-depth from 21e34cabac to 2b1ce9e56b 2026-10-06 11:16:46 +00:00 Compare
sharang force-pushed feat/495-binary-depth from 2b1ce9e56b to a4acde3677 2026-10-06 11:19:37 +00:00 Compare
sharang added 2 commits 2026-10-06 11:32:15 +00:00
On top of the committed-binary inventory (#465), natively in Rust:

- PE: ASLR (DYNAMICBASE, relocations), high-entropy ASLR, DEP, CFG,
  SafeSEH, /GS, Authenticode present; IL-only .NET assemblies skip the
  native-only checks
- ELF (dynamically linked only): RELRO, NX stack, PIE, stack protector,
  FORTIFY; static and bare-metal ELF are not assessed
- .NET: AssemblyRefs from the CLI metadata tables (own ECMA-335 reader)
- native PE: CPE/purl candidates from the version resource, low confidence
- Intel HEX: record checksums, address ranges, size, start address

Evidence goes on the inventory finding; each gap is its own Low/Info
finding per rule (grouped by #477). ASLR/NX/RELRO gaps bind to cra-ai-1 and
a damaged HEX image to cra-ai-6 through attach-only control-map bindings,
which never make a control count as checked.

PE/ELF headers are read with the object crate, already in the build via
firmwerk-sbom: no new crate, no Python helper, no image change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
docs(release): #495 check: stored inventory texts are not rewritten
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m32s
160f004955
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang force-pushed feat/495-binary-depth from a4acde3677 to 160f004955 2026-10-06 11:32:15 +00:00 Compare
sharang merged commit b7dbd8f196 into main 2026-10-06 11:40:55 +00:00
Sign in to join this conversation.