refactor(llm-security): build the SIG ruleset from vendored commons (malware-signatures 0.1.0)

Fifth and last consumer swap of v8 Phase 5 step 4. The seven known-bad-identity
signatures stop living in knowledge/signatures.json and are built from the
vendored commons artifact signatures/malware-signatures.json instead.

Measured before the swap over all seven positions -- id, family, severity,
pattern, description, provenance, key order, and recompilation identity under
the engine's unconditional `i` flag: zero divergences over 56 checks, in order.
The commons copy was extracted from this repository's own file at b0de0ca and
had not drifted.

knowledge/signatures.json is REMOVED rather than left in place. Keeping it would
have left two files spelling one table with nothing gating the drift, and its
golden `file:` pin would have gone on passing while pinning bytes no scanner
reads -- a gate reporting success without running. The pin is replaced by a
walked-module anchor over SIGNATURE_RULES, which is strictly stronger: the pin
covered the bytes on disk, the walk covers what `new RegExp` made of them.
Golden diff was exactly that and nothing else: 7 ADDED, 1 REMOVED, 0 CHANGED
(102/7/5 -> 109/7/4), each added source verified equal to the recompiled commons
pattern.

compileRules() moves into the new lib module and is exported, so the built-in
ruleset and the operator's sig.custom_rules_path path keep one implementation
rather than two copies of the defaulting logic.

Coverage by construction, not by memory: the probe table in the scanner test is
asserted against the LOADED ruleset, so a rule commons adds cannot arrive
without an end-to-end probe. Mutation of the vendored JSON fires in three
directions -- under-match (xmrig alternative dropped) reddens two scanner tests
plus golden; over-match (webshell rule widened to a bare `shell`) reddens the
clean-fixture false-positive probe plus golden; reorder reddens the declared-
order test plus golden.

Loud failure is contract: an unresolvable commons writes one line to stderr
rather than silently disabling known-malware detection, and never throws.

Suite 2247 / 2241 pass / 6 skipped / 0 fail. suite-counts.json untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0151x4FVg9Mn55C2LvHLpHKo
This commit is contained in:
Kjell Tore Guttormsen 2026-08-13 21:28:14 +02:00
commit bbada84e9f
12 changed files with 480 additions and 132 deletions

View file

@ -2,9 +2,9 @@
"artifact": "golden-pattern-dump",
"schema": 1,
"counts": {
"regex": 102,
"regex": 109,
"table": 7,
"file": 5
"file": 4
},
"records": [
{
@ -505,6 +505,48 @@
"source": "ignor(?:ez?|er?)\\s+(?:les?\\s+)?instructions?\\s+pr[e\\u00e9]c[e\\u00e9]dentes?",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[0].re",
"source": "(?:eval|assert|system|exec|passthru|shell_exec|popen|proc_open)\\s*\\(\\s*\\$_(?:POST|GET|REQUEST|COOKIE|SERVER)",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[1].re",
"source": "\\$_(?:POST|GET|REQUEST|COOKIE)\\s*\\[[^\\]]*\\]\\s*\\(",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[2].re",
"source": "(?:bash|sh)\\s+-i\\s*>&?\\s*\\/dev\\/tcp\\/",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[3].re",
"source": "\\bnc\\s+-[a-z]*e[a-z]*\\s+\\/(?:bin|usr\\/bin)\\/(?:sh|bash)\\b",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[4].re",
"source": "stratum\\+(?:tcp|ssl):\\/\\/",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[5].re",
"source": "\\b(?:xmrig|minerd|cgminer|ccminer|cpuminer)\\b",
"flags": "i"
},
{
"kind": "regex",
"key": "malware-signatures:SIGNATURE_RULES[6].re",
"source": "\\b(?:mimikatz|meterpreter|sekurlsa::|lsadump::)\\b",
"flags": "i"
},
{
"kind": "regex",
"key": "secret-egress:SECRET_PATTERNS[0].pattern",
@ -666,11 +708,6 @@
"key": "knowledge/attack-mutations.json",
"sha256": "40b99cd14fea4ca510937bdbdc4179a1d4007bcd5548849935408237fb2cd6f2"
},
{
"kind": "file",
"key": "knowledge/signatures.json",
"sha256": "0155368f194c51e01f48e5b253067282a9c083549401a2d374afc46bb89c66bc"
},
{
"kind": "file",
"key": "scanners/lib/injection-patterns.mjs",