A detection engineering lab. Replayable attack telemetry, Sigma rules over the top, and a test suite that fails when a detection regresses.
Most detection repos are a pile of YAML with no way to answer two questions: does this rule still fire? and what does it fire on that it shouldn't? RuleRecoil answers both on every commit.
$ rulerecoil test --example
scenario kind events fired result
workstation_baseline benign 21 1 pass
encoded_powershell_cradle malicious 3 2 pass
lsass_credential_dump malicious 3 1 pass
office_macro_dropper malicious 4 2 pass
run_key_persistence malicious 2 1 pass
wmi_lateral_movement malicious 4 2 pass
╭────────────────────────────────────────────╮
│ all detections behaving │
│ 8 rules - 6 scenarios - 37 events replayed │
╰────────────────────────────────────────────╯
The one fired on the benign corpus is declared accepted noise, not a failure —
see expect.fires in that scenario's manifest.
rules/ and fixtures/ start empty — they are yours to fill, and each has a
README explaining the format. Everything above is the worked example in
examples/, reachable from any command with --example (-x). A gate that
reports green over zero rules says so rather than letting it read as a pass.
A rule plus a fixture that proves it fires is a test. A rule on its own is a hope. So every scenario declares what it expects, and the harness classifies three distinct failure modes that detection repos usually conflate:
| Failure | Meaning |
|---|---|
missed |
A malicious scenario says a rule fires, and it didn't. Someone tightened a rule, renamed a field, or a filter grew too broad. |
false_positive |
A rule fired on the benign corpus without being declared as accepted noise. Someone loosened a rule. |
untested_rule |
A rule exists that no malicious scenario asserts. It might be perfect, it might match nothing ever, and nobody would know. |
Plus two integrity failures that must never pass quietly: unresolved_reference
(an expectation naming a rule that doesn't exist) and ambiguous_reference (one
matching several rules). A manifest typo that silently disables an expectation
is a green test that proves nothing.
The benign corpus is the important half. It is built almost entirely of near-misses: PowerShell without an encoded command, certutil hashing a file rather than fetching one, Office parenting its own updater, WmiPrvSE driving a monitoring agent, and three processes reading LSASS for legitimate reasons. Tighten a rule and the malicious fixtures catch you. Loosen one and this does.
rules/ YOUR Sigma rules (starts empty, see its README)
fixtures/ YOUR telemetry (starts empty, see its README)
examples/rules/ worked example: 8 rules, 6 ATT&CK techniques
examples/fixtures/ worked example: 5 attack chains + benign baseline
rulerecoil/engine/ Sigma parsing and the in-memory matcher
rulerecoil/sources/ telemetry normalization (Sysmon, Security, PowerShell)
rulerecoil/harness.py rules x scenarios -> classified findings
rulerecoil/attack.py ATT&CK coverage, verified vs merely claimed
rulerecoil/web/ FastAPI layer over all of the above
cockpit/ Next.js 16 cockpit (rules, replay, coverage, explain)
tests/ ~125 tests; the detection suite runs examples/
The CLI is the gate; the cockpit is for reading. Four views: the regression gate, a rule browser, the replay timeline, and the ATT&CK heatmap.
pip install -e ".[dev,web]"
rulerecoil serve --example # API on 127.0.0.1:8011
cd cockpit && npm install
npm run dev # cockpit on localhost:3011Drop --example once rules/ and fixtures/ have your own content in them.
The API reloads rules and fixtures from disk on every request, so editing a
rule and hitting re-run in the UI genuinely re-runs the suite — there is no
build step or cache between you and the result. /docs gives the OpenAPI schema.
Point it at a different lab with rulerecoil serve --rules other/rules --fixtures other/fixtures, or move the API with NEXT_PUBLIC_API_BASE.
Views worth calling out:
- Replay (
/scenarios/<name>) — the event timeline, with fired events marked down the left edge. Click any event to see every normalized field, which is what you actually need when a rule didn't fire. - Explain (
/explain/<rule>/<scenario>) — the condition tree per event, with actual values inline. Failing branches stay expanded; passing subtrees collapse. - Coverage (
/coverage) — the heatmap, plus a detection gaps panel listing techniques your fixtures exercise that no rule covers.
rulerecoil test # the gate; exits non-zero on any regression
rulerecoil replay <scenario> # walk a scenario event by event
rulerecoil explain <rule> <scenario>
rulerecoil coverage --markdown coverage.md
rulerecoil lint # do all rules compile?
rulerecoil scenarios # what fixtures exist?
rulerecoil serve # the cockpit APIEvery command takes --rules / --fixtures to point elsewhere, or --example
(-x) for the bundled lab:
rulerecoil test --example
rulerecoil replay office_macro_dropper --example
rulerecoil explain lsass_credential_dump lsass_credential_dump --exampleexplain is the one you'll actually live in. It answers "why didn't my rule
fire?" by reporting every condition branch, including the ones evaluation would
have short-circuited past:
event 1 - process_access: C:\Windows\system32\lsass.exe MATCH
[PASS] Suspicious LSASS Process Access
[PASS] logsource windows/process_access
[PASS] AND
[PASS] TargetImage endswith '\lsass.exe' (actual: 'C:\Windows\system32\lsass.exe')
[PASS] GrantedAccess equals '0x1410' (actual: '0x1410')
[PASS] NOT
[fail] OR
[fail] SourceImage startswith 'C:\Program Files\Windows Defender\'
Synthetic fixtures give you determinism. Your own machine gives you truth: a rule that fires on telemetry you actually generate is a false positive you would actually have paged on.
rulerecoil channels # what does this host have?
rulerecoil ingest powershell --name my_workstation --since 7d
rulerecoil testchannels comes first because it answers the question that decides everything
else — is Sysmon installed? It does not ship with Windows, so on a stock box
the process_creation, process_access and registry_set channels most rules
target simply do not exist. Microsoft-Windows-PowerShell/Operational (4104
script blocks) usually does.
| preset | channel | notes |
|---|---|---|
sysmon |
Microsoft-Windows-Sysmon/Operational |
needs Sysmon installed |
powershell |
Microsoft-Windows-PowerShell/Operational |
usually available |
security |
Security |
needs Administrator; 4688 auditing off by default |
defender |
…/Windows Defender/Operational |
no rule targets it yet |
wmi |
…/WMI-Activity/Operational |
Any raw channel name works too, with --source to pick the adapter.
Records are read as native event XML via .ToXml() rather than through
ConvertTo-Json, whose output shape varies by provider and drops the EventData
names rules match on. Event XML maps exactly onto what the normalization layer
already accepts, so there is no glue in between.
Redaction is on by default. Captures are meant to be committed, and real
telemetry carries your username, hostname, domain and SIDs in fields no rule
matches on. Well-known SIDs (S-1-5-18) survive, since they're identical on every
host. --no-redact opts out; the summary line tells you which you got.
A fresh capture declares no accepted noise, so anything that fires is reported as a false positive — which is the point. Once you've reviewed them, baseline today's state instead:
rulerecoil ingest powershell --name my_workstation --accept-currentThat records whatever currently fires into expect.fires, so the gate goes green
and then fails if that set ever changes — a rule going quiet is as interesting
as a new one going off.
name: lsass_credential_dump
kind: malicious # malicious | benign
source: sysmon # which normalization adapter to use
attack: [T1003.001]
expect:
fires: [lsass_credential_dump] # must fire, by rule id / title / filename
silent: [] # must NOT fireOn a benign scenario, expect.fires is the tuning allowlist — noise you have
consciously decided to live with, recorded in review rather than buried in a
config file. Accepted noise never counts as proof that a rule works, so it can't
be used to satisfy the untested_rule gate.
events.jsonl takes one JSON record per line, in either shape:
- flat —
{"EventID": 1, "Image": "...", "CommandLine": "..."}, easy to hand-author - EVTX JSON — the nested
{"Event": {"System": {...}, "EventData": {...}}}thatevtx_dumpemits, so telemetry captured off a real host drops straight in
Blank lines and // comments are skipped, because handwritten telemetry is much
easier to review with a note above the interesting record.
pySigma parses Sigma and resolves modifiers — by the time you see a condition
tree, |contains has become a wildcarded SigmaString and
|base64offset|contains has become a SigmaExpansion of three alternatives.
What it does not ship is a backend that answers "does this event match?"; its
backends emit query strings for a SIEM to run. rulerecoil/engine/matcher.py is
that missing backend, compiling the tree into a small evaluable AST so each leaf
can also explain itself.
Two things worth knowing if you read that file:
SigmaRegularExpression.compile()returnsNone. It validates; it is not a pattern factory. Thereobject is built from.to_plain()plus the rule's flags.\*is an escaped literal asterisk, not a wildcard. SoC:\Windows\*means the literal textC:\Windows*and will never match a real path — expressing "C:\Windows\followed by anything" needsC:\Windows\\*.admin_share_mount.ymldepends on exactly this, and|startswithsidesteps it entirely, which is why real rulesets prefer it.
Sigma semantics the unit tests pin down: string comparison is case-insensitive
unless |cased; numbers coerce, so a log carrying "1024" still matches
DestinationPort: 1024; a field holding a list matches if any element does;
Field: null matches an absent or explicitly null field while
Field|exists: false only matches an absent one; and unbound keywords are
full-text searches rather than equality checks.
rulerecoil coverage deliberately refuses to flatter you. A map built from rule
tags counts intent, not capability — a rule tagged attack.t1003.001 might match
nothing at all. So every technique lands in one of three states:
[x]verified — a rule covers it and a fixture proves the rule fires[~]unverified — a rule covers it, nothing proves it works[ ]gap — a fixture exercises it and no rule covers it
That last state is the most actionable thing on the map: telemetry for the behaviour is sitting in the lab and nothing detects it.
The technique-name table in rulerecoil/attack.py is a small local subset rather
than a vendored copy of the ATT&CK corpus, so the lab stays offline. Unknown IDs
render as the bare technique ID.
python -m venv .venv && .venv/Scripts/activate # or source .venv/bin/activate
pip install -e ".[dev]"
pytest -q- Write the rule under
rules/windows/<category>/. - Write a malicious scenario under
fixtures/malicious/that proves it fires. - Add near-miss events to a benign corpus under
fixtures/benign/that it must stay quiet on. - Run
rulerecoil test. Skipping step 2 fails the gate — that'suntested_rule.
examples/ is a complete worked instance of all four steps; copy its shape.
Note that pytest -q runs the suite against examples/, not against your own
lab — it verifies the engine, not your detections. rulerecoil test is the gate
for your content.
Proprietary — Kalyan Gopalam & Pallavi Srinivasappa