Testing Sigma rules like code
- - ' -en'
+ - ' -enco'
That’s the kind of change you’d wave through in code review. It “tightens” a pattern in the Sigma rule from the PowerShell -EncodedCommand post. Narrower, so fewer false positives. Sounds sensible.
It also makes the rule lose all six detections it produces on a corpus of public logs. Every one of them. Without a test, nobody would notice until the day a real encoded PowerShell slipped through without a sound.
A detection rule is code. It has bugs, it regresses, and it should be tested like code. Here’s how I go about it, applied to the four Sigma rules published on this blog.
The problem: rules never fail loudly
Broken software crashes or throws an error. A broken detection rule does nothing at all. It keeps running, stops matching, and the silence looks exactly like “nothing bad is happening”. For a security control that’s the worst possible failure mode: invisible by design.
sigma check is a useful first gate. It validates syntax, ATT&CK tags and identifiers. It doesn’t check that the rule detects what it claims to detect. For that you have to run it against logs whose content you already know.
The pipeline, in four stages

Stages 1, 3 and 4 are standard tooling. Stage 2 takes more work, because it needs data, and it’s the one this post is about.
The corpus: logs you know the answers to
Testing a rule needs logs that contain what it’s looking for, and logs that don’t. I’m reusing the set from previous posts: the 29 datasets under lateral_movement/host in OTRF Security-Datasets, MIT-licensed. Loaded up, that’s 196,869 real Windows events, Sysmon and Security, recorded during documented attack simulations.
It makes a good test corpus for one simple reason: you know what happened in it. Every dataset is named after the technique it simulates. And those 196,869 events also carry a lot of ordinary activity, which is where false positives would show up.
Running it: Sigma to SQLite
To run a Sigma rule against logs you need an engine. I first tried Zircolite, an open source tool built for exactly this. Its dependencies wouldn’t resolve with my Python version, so instead of fighting it I went straight to the mechanism it uses internally: pySigma’s SQLite backend, which turns a rule into a SQL query. Here’s the NTLM V1 rule from the Event 4624 post after conversion:
SELECT * FROM logs WHERE EventID=4624 AND AuthenticationPackageName='NTLM' AND LmPackageName='NTLM V1'
The test script does the rest in about fifty lines: load every JSON event into a SQLite table, convert each rule, run the query, count hits per dataset.
Expectations, versioned with the rules
The key piece isn’t the script. It’s a small file that lives in the same repository as the rules and states, for each rule, how many hits it must produce and on which dataset:
proc_creation_win_powershell_encoded_cmd_prefix:
empire_dcom_shellwindows_stager: 1
empire_msbuild_dcerpc_wmi_smb: 1
empire_psexec_dcerpc_tcp_svcctl: 1
empire_psremoting_stager: 1
empire_smbexec_dcerpc_smb_svcctl: 1
empire_wmi_dcerpc_wmi_IWbemServices_ExecMethod: 1
proc_creation_win_schtasks_remote_create:
schtask_create: 1
win_security_logon_ntlmv1:
covenant_dcom_executeexcel4macro_allowed: 3
covenant_dcom_iertutil_dll_hijack: 3
covenant_dcom_registerxll: 2
purplesharp_ad_playbook_I: 3
win_security_scheduled_task_microsoft_path_by_user:
schtask_create: 1
Any difference fails the test, in either direction. One hit fewer is a regression. One hit more is either a new false positive or an improvement; either way, someone has to look and update the file on purpose.
I didn’t make those numbers up. They come from the first run, checked by hand before being frozen. The six PowerShell hits, for instance, are all true positives: Empire launchers along the lines of powershell -noP -sta -w 1 -enc …, with a different parent depending on the vector (MSBuild.exe, WmiPrvSE.exe, wsmprovhost.exe, cmd.exe). That’s also a validation the rule published in October hadn’t had yet: it works on real payloads, not just on my lab example.

The regression, caught
Back to the change from the top. Apply it, rerun:

Zero out of six. The reason is mundane, as it usually is: Empire launchers write -enc, and ' -enco' doesn’t match ' -enc '. The test lists exactly which datasets were lost, and the non-zero exit code is all any CI system needs to block the merge.
When the corpus isn’t enough: fixtures
Every Empire launcher in the corpus writes -enc with a plain ASCII hyphen. Nothing in those 196,869 events exercises the variants the first post turned up in the lab: the forward slash, the Unicode dashes, the renamed binary. If someone dropped the windash modifier from the rule tomorrow, the OTRF corpus wouldn’t notice.
The fix is a handful of hand-written events, fixtures, stored next to the rules. Three lines of JSON do it: a powershell.exe –enc with an en dash, a powershell.exe renamed to update.exe and run with /e, and a perfectly ordinary -ExecutionPolicy Bypass -File line that must not fire. The matching expectations file says two hits on the PowerShell rule, zero everywhere else. The test passes, two out of two.
Those events are synthetic, and the repository should say so plainly. They don’t prove an attacker will use those variants; they guarantee the rule keeps seeing them. That’s all they’re for. Writing them also exposed a bug in my own script, which crashed when a rule referenced a field missing from the corpus instead of counting zero. Fixed, and one more reason to test your test tooling.
An error caught along the way
Running these rules for real also taught me something about one of my own posts. In the scheduled tasks one, I’d first written that the schtasks rule caught the remote creation twice, via Sysmon and via event 4688. In a real execution it catches it once. Event 4688 calls the field NewProcessName, not Image, and only triggers the rule if the SIEM maps one onto the other. My first replay did that mapping by hand without saying so. The post was fixed before going live. That’s exactly the kind of mistake an executed test catches and a proofread misses.
Where this falls short
This harness isn’t your SIEM, and that’s worth keeping in mind. Two concrete differences. It applies no field-mapping pipeline, so it tests the rule as written against raw field names. And in SQLite, = is case-sensitive while Sigma compares strings case-insensitively. A value written as lowercase ntlm v1 would slip past the harness where a properly configured SIEM would catch it. Values are consistent in this corpus so it doesn’t bite here, but I wouldn’t count on that in general.
The corpus has limits too. Twenty-nine lab datasets aren’t thirty days of production. They catch regressions; they don’t measure your real false positive rate. For that, see the alert fatigue post.
Getting started
You don’t need all of it at once. A Git repository for your rules, sigma check in a hook or a CI job, and a first expectations file with three rules and one public dataset. The day someone “tightens” a rule without realising what it breaks, the test will say so before production does.
References
- OTRF, Security-Datasets,
datasets/atomic/windows/lateral_movement/host(MIT licence) - SigmaHQ, pySigma and pySigma-backend-sqlite
- wagga40, Zircolite (LGPL-3.0 licence)