Most detection logic lives as a query someone pasted into a SIEM console. No history, no review, no tests. When it stops firing, nobody can say what changed or why.
Software engineering settled this problem a long time ago. Write the logic in a portable format, keep it in version control, review changes through pull requests, and test everything automatically before it merges. I built two public repositories to work that way.
- detection-engineering (opens in a new tab) is the catalog: one folder per detection with its KQL, a metadata file, and validation notes.
- detection-as-code (opens in a new tab) holds the same logic as Sigma rules, plus the CI pipeline that tests and converts them.
What is covered
| ATT&CK | Detection | Tactic | Status | Sigma rule |
|---|---|---|---|---|
| T1110.003 | Password spray from a single source | Credential Access | Stable | Yes |
| T1110.001 | Brute force against a single account | Credential Access | Stable | Yes |
| T1098.002 | Suspicious inbox rule creation | Persistence | In tuning | Yes |
| T1528 | OAuth consent grant abuse | Credential Access | Experimental | Yes |
| T1078 | Impossible travel | Initial Access | In tuning | Not yet |
Five detections is a small catalog. It is also all identity and mailbox activity, because that is where a Microsoft 365 environment actually gets attacked.
One detection, two formats
The Sentinel version of the password spray detection looks for one source address failing sign-in across many distinct accounts inside a 30-minute window:
let lookback = 1h;
let sprayWindow = 30m;
let accountThreshold = 10; // distinct accounts targeted from one source
SigninLogs
| where TimeGenerated > ago(lookback)
| where ResultType in ("50126", "50053", "50055")
| summarize
FailedAttempts = count(),
TargetedAccounts = dcount(UserPrincipalName),
AccountList = make_set(UserPrincipalName, 100),
ResultCodes = make_set(ResultType)
by IPAddress, bin(TimeGenerated, sprayWindow)
| where TargetedAccounts >= accountThreshold
| order by TargetedAccounts descThe Sigma version describes the same activity in a backend-neutral format, with its false positives written down next to the logic: a shared corporate egress IP behind NAT, and applications replaying stale credentials. Sigma converts to Sentinel, Defender XDR, Elastic, or Splunk, so the rule is written once.
One honest gap: the Sigma rule matches each failed sign-in on its own. The 10-account threshold lives in the KQL version for now.
Four gates before a merge
Every pull request that touches a rule, the pipeline, or the tests, and every push to main, runs four steps in GitHub Actions:
- Rule requirement tests in pytest, checking every rule against the contribution standard.
- Sigma syntax validation.
- Conversion to KQL through a pySigma pipeline that maps each log source to its Sentinel table.
- An uploaded artifact of the generated queries, for review.
If any step fails, nothing merges.
This matters more in a compliance-driven shop than anywhere else. Git history is a timestamped record of what changed, when, and who approved it. That is the kind of evidence an assessor asks for, and a SIEM console does not keep it.
Every rule in the catalog was also tested against real telemetry before I trusted it. That lab is the next post.
The query is the easy part. Knowing exactly what changed, and when, is the part a console never gave me.