feat(malware): ClamAV stage, committed-binary inventory, unchanged rescans skipped (#465) #488

Merged
sharang merged 1 commits from feat/465-malware-binaries into main 2026-10-06 08:49:40 +00:00
Owner

Closes #465. Requested by the platform session; stage only. The sidecar is orca-platform #66.

Malware stage (pipeline/clamav.rs)

  • The agent streams each file of the tree to clamd at CLAMD_ADDRESS (INSTREAM over TCP):
    • vendor code is included: a vendored DLL is exactly where it hides;
    • .git is not;
    • at most 64 MiB per file; larger files are listed under Nicht ausgeführt.
  • The agent image carries no signatures; the sidecar keeps them current with freshclam.
  • Clean files are remembered per tenant by SHA-256 and signature version, so a rescan only streams what changed or met new signatures. The log shows N files streamed.
  • Each hit is a finding:
    • severity High, new ScanType::Malware, CWE-506;
    • shows the signature, file and SHA-256;
    • heuristic signatures (Heuristics.*, *.Malware.*, PUA.*) say they need a person's review;
    • the LLM triage skips them (skipped: binary); it has no code to read.
  • Without clamd:
    • not configured → listed as not enabled;
    • unreachable or failing → listed as not completed;
    • never reported as clean, and the scan goes on.
  • Tested against a real clamd 1.5.4 (EICAR found, a clean file passes). The test skips without CLAMD_ADDRESS.

Committed binaries (pipeline/binaries.rs)

  • Recognised by their first bytes:
    • PE: PE32/PE32+, CPU, .NET from the CLR header, and version resource strings (ProductName, FileVersion, CompanyName, OriginalFilename);
    • ELF: class and CPU (ARM, Xtensa, RISC-V, …);
    • Mach-O: told apart from Java class files, which share the CAFEBABE magic;
    • firmware images: .hex, .srec, .uf2, .dfu, and raw .bin of 1 KiB or more.
  • Each becomes an Info finding with its size and SHA-256. A changed file is a new finding. More than five in one repository are grouped (#464).

Unchanged scheduled rescans (pipeline/change.rs)

  • Uploaded files: a scheduled or webhook scan of uploads identical to the last completed scan (artifact ids and content hashes) is skipped with SkipCode::UploadUnchanged. Git targets already skipped unchanged commits.
  • Both now also compare the Prüfwerk build (OnboardedTarget.last_scan.build = version + commit), so a new release rescans every target once.
  • Targets with a live URL always run.
  • Usage: a skipped scan no longer emits scan.completed. Until now unchanged git targets emitted it every 6 h, so skipped runs counted as scans.
  • #459 interaction: a scan interrupted by a restart now resumes with its own trigger, so a person's scan still runs in full (the test is extended).
  • "Prüfung starten" always runs. The CVE monitor keeps matching the stored SBOM independently, unchanged.

Not included

YARA (optional in the issue).

Tests and checks

  • Unit tests:
    • clamd answer parsing, heuristic flag, file selection;
    • EICAR against a real clamd;
    • PE/ELF/HEX/Java-class detection and version strings;
    • change detection (order, content, build, live URL, unhashed upload);
    • resume with the original trigger.
  • fmt and clippy -D warnings: agent, core, mcp, dashboard (server and wasm).
  • Agent lib: 701 tests (with clamd); dashboard 82; core 85.
  • Nightly, run locally (bless, then compare):
    • every baseline lists the malware stage as not enabled (the nightly has no clamd);
    • fw-c-sensor-node gains a synthetic Prebuilt/bootloader.hex, listed as a committed binary;
    • the Python baselines' OSV drift was discarded.

To check on stage

Check 15 in docs/release/staging-test-plan-after-v0.4.5.md. It needs orca #66 deployed.

  • EICAR archive → a High finding, and a rescan streams 0 files.
  • ClamAV stopped → listed as not completed.
  • fw-c-sensor-node → the committed-binary Info finding.
  • A scheduled scan of an unchanged upload → Änderungserkennung skipped and no usage sent.
  • A restart during "Prüfung starten" → it resumes in full.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #465. Requested by the platform session; stage only. The sidecar is orca-platform #66. ## Malware stage (`pipeline/clamav.rs`) - The agent streams each file of the tree to **clamd** at `CLAMD_ADDRESS` (`INSTREAM` over TCP): - vendor code is included: a vendored DLL is exactly where it hides; - `.git` is not; - at most 64 MiB per file; larger files are listed under **Nicht ausgeführt**. - The agent image carries no signatures; the sidecar keeps them current with freshclam. - **Clean files are remembered** per tenant by SHA-256 and signature version, so a rescan only streams what changed or met new signatures. The log shows `N files streamed`. - **Each hit is a finding:** - severity **High**, new `ScanType::Malware`, CWE-506; - shows the signature, file and SHA-256; - heuristic signatures (`Heuristics.*`, `*.Malware.*`, `PUA.*`) say they need a person's review; - the LLM triage skips them (`skipped: binary`); it has no code to read. - **Without clamd:** - not configured → listed as not enabled; - unreachable or failing → listed as not completed; - never reported as clean, and the scan goes on. - Tested against a real clamd 1.5.4 (EICAR found, a clean file passes). The test skips without `CLAMD_ADDRESS`. ## Committed binaries (`pipeline/binaries.rs`) - Recognised by their first bytes: - **PE:** PE32/PE32+, CPU, `.NET` from the CLR header, and version resource strings (ProductName, FileVersion, CompanyName, OriginalFilename); - **ELF:** class and CPU (ARM, Xtensa, RISC-V, …); - **Mach-O:** told apart from Java class files, which share the `CAFEBABE` magic; - **firmware images:** `.hex`, `.srec`, `.uf2`, `.dfu`, and raw `.bin` of 1 KiB or more. - Each becomes an **Info** finding with its size and SHA-256. A changed file is a new finding. More than five in one repository are grouped (#464). ## Unchanged scheduled rescans (`pipeline/change.rs`) - **Uploaded files:** a scheduled or webhook scan of uploads identical to the last completed scan (artifact ids and content hashes) is skipped with `SkipCode::UploadUnchanged`. Git targets already skipped unchanged commits. - **Both now also compare the Prüfwerk build** (`OnboardedTarget.last_scan.build` = version + commit), so **a new release rescans every target once**. - Targets with a live URL always run. - **Usage:** a skipped scan no longer emits `scan.completed`. Until now unchanged git targets emitted it every 6 h, so skipped runs counted as scans. - **#459 interaction:** a scan interrupted by a restart now resumes with **its own trigger**, so a person's scan still runs in full (the test is extended). - **"Prüfung starten"** always runs. The **CVE monitor** keeps matching the stored SBOM independently, unchanged. ## Not included YARA (optional in the issue). ## Tests and checks - **Unit tests:** - clamd answer parsing, heuristic flag, file selection; - EICAR against a real clamd; - PE/ELF/HEX/Java-class detection and version strings; - change detection (order, content, build, live URL, unhashed upload); - resume with the original trigger. - fmt and clippy `-D warnings`: agent, core, mcp, dashboard (server and wasm). - Agent lib: 701 tests (with clamd); dashboard 82; core 85. - **Nightly**, run locally (bless, then compare): - every baseline lists the `malware` stage as not enabled (the nightly has no clamd); - `fw-c-sensor-node` gains a synthetic `Prebuilt/bootloader.hex`, listed as a committed binary; - the Python baselines' OSV drift was discarded. ## To check on stage Check 15 in `docs/release/staging-test-plan-after-v0.4.5.md`. It needs orca #66 deployed. - **EICAR archive** → a High finding, and a rescan streams 0 files. - **ClamAV stopped** → listed as not completed. - **`fw-c-sensor-node`** → the committed-binary Info finding. - **A scheduled scan of an unchanged upload** → `Änderungserkennung` skipped and no usage sent. - **A restart during "Prüfung starten"** → it resumes in full. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-06 08:41:04 +00:00
feat(malware): ClamAV stage, committed-binary inventory, unchanged rescans skipped (#465)
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 8m12s
7743f03ed8
Closes #465.

Malware (pipeline/clamav.rs, stage after the secret scan):
- The agent streams each file of the tree (vendor code included, .git
  not; up to 64 MiB, larger ones listed under "Nicht ausgeführt") to a
  clamd service at CLAMD_ADDRESS (INSTREAM over TCP; the stage sidecar is
  orca-platform #66). No signatures in the agent image.
- Clean files are remembered per tenant by SHA-256 and signature version
  (malware_clean_files), so rescans stream only what changed or met new
  signatures.
- A hit is a High finding (new ScanType::Malware, CWE-506) with signature,
  file and SHA-256; heuristic signatures say they need review. The LLM
  triage skips them ("skipped: binary").
- No CLAMD_ADDRESS: the stage is listed as not enabled; clamd unreachable
  or failing: as not completed (ToolFailed). The scan goes on.

Committed binaries (pipeline/binaries.rs):
- PE (format, CPU, .NET, version resource strings), ELF, Mach-O (told
  apart from Java classes) and firmware images (.hex/.srec/.uf2/.dfu/raw
  .bin of 1 KiB+) found by their bytes, as Info findings with size and
  SHA-256; a changed file is a new finding; many group (#464).

Unchanged scheduled rescans (pipeline/change.rs):
- A scheduled or webhook scan of uploaded files identical to the last
  completed scan (ids and content hashes) is skipped
  (SkipCode::UploadUnchanged); git targets already skipped unchanged
  commits. Both now also compare the Prüfwerk build (LastScan.build), so
  a release rescans every target once. Targets with a live URL always run.
- A skipped scan sends no scan.completed usage (it did before, every six
  hours, for unchanged git targets).
- A scan a restart interrupted resumes with its own trigger, so a
  person's scan still runs in full (#459).
- The CVE monitor keeps matching the stored SBOM independently.

Dashboard texts for the new type, phase, skip codes, stage and tools; docs
(scanning, findings, tools incl. egress); nightly: every baseline lists
the malware stage as not enabled (no clamd in the nightly), and
fw-c-sensor-node gains a prebuilt bootloader image as a committed binary.
Staging test plan: check 15.

YARA is not part of this (optional in the issue).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit d960ba658e into main 2026-10-06 08:49:40 +00:00
Sign in to join this conversation.