Detection engineering: writing rules that survive contact with reality
JYOTHENDRA · 02 Sept 2025 · 9 min read
A working checklist for detection rules that hold up past the demo: anchoring on technique instead of tool artifacts, testing against tool variation, baselining false-positive rate against real traffic, and documenting what a rule does not cover.
The failure mode this post is about
Most detection rules I've seen fail in one of two ways: they're written against a single attack tool's default output and break the moment an operator changes a flag, or they're tuned only against clean lab traffic and drown in false positives the first week they run against a real environment. Both failures come from the same root cause — the rule was validated against too narrow a slice of reality. This is a working checklist for closing that gap, built from tuning rules that actually had to survive contact with a live SOC queue.
Start from the technique, not the tool
A rule written as "alert if mimikatz.exe runs" survives exactly until an attacker renames the binary or uses a different tool that does the same thing. The fix is to anchor detections on the technique's required behavior, which is much harder to avoid than a specific artifact.
For LSASS credential dumping, for example, the technique-level requirement is: some process opens a handle to lsass.exe with memory-read access it doesn't normally need. That's true whether the tool is Mimikatz, a custom C# loader, or comsvcs.dll's MiniDump export invoked via rundll32:
# Sysmon Event ID 10 (ProcessAccess) targeting lsass.exe
EventID == 10
AND TargetImage ENDSWITH "\lsass.exe"
AND (GrantedAccess CONTAINS "0x1010" OR GrantedAccess CONTAINS "0x1410")
AND SourceImage NOT IN (known_edr_processes, known_backup_agents)
This catches the technique regardless of tooling, at the cost of needing a real allowlist of legitimate LSASS-accessing processes (EDR agents, some backup software, some monitoring agents) built from the actual environment, not a generic list copied from a blog post.
Test against tool variation, not just the default invocation
Before shipping a rule, I run the technique with:
- the tool's default flags
- at least one alternate tool implementing the same technique
- the most common evasion flag or mode the tool documents (e.g.,
-ldapfiltervariants, alternate encryption in Kerberoasting,-Forceflags that skip a normally-detected step)
If the rule only fires on the default invocation, it's not done. A rule that only catches GetUserSPNs.py with no arguments, for instance, misses the same tool run with -outputfile and a slower per-SPN pace, or a PowerShell-native equivalent that generates the same TGS-REQ traffic through a completely different process image.
Baseline against real traffic before shipping
Lab traffic is clean by construction — that's the whole point of a lab. Production traffic has legacy service accounts, monitoring tools, backup jobs, and scheduled tasks that touch the same event IDs a real attack does. Before a rule ships, I run it against at least a week of real (or realistic, sanitized) production log volume and count the false-positive rate. A rule that fires zero times against a week of baseline but also zero times against a red team validation run isn't safe — it might just be too narrow to fire on anything, including the attack.
# quick harness: replay a rule's logic against historical logs
import pandas as pd
logs = pd.read_parquet("baseline_week.parquet")
hits = logs.query(
"event_id == 4769 and ticket_encryption_type == '0x17' "
"and target_account_type == 'user'"
)
print(f"{len(hits)} hits against {len(logs)} baseline events "
f"({len(hits)/len(logs)*100:.3f}%)")
A false-positive rate an analyst can actually triage matters more than a theoretically perfect detection that nobody trusts because it cries wolf.
Document what the rule does not cover
Every detection has a boundary, and writing it down is part of shipping the rule, not an afterthought. For a Kerberoasting detection built on TGS-REQ patterns, the documented gaps look like: it doesn't detect the offline cracking step (that happens with zero network traffic to the domain), it doesn't catch the case where the target service account already has a long random password (the attack succeeds technically but yields nothing crackable), and it depends on sAMAccountType enrichment being present in the log pipeline — if that enrichment breaks upstream, the rule silently degrades to firing on everything or nothing. Analysts inherit a rule faster and trust it more when they know exactly where its edges are.
Build in a decay check
Rules rot. An allowlist of "known EDR processes" goes stale when the EDR agent updates and changes its process name or code-signing certificate. A baseline of "normal SPN request accounts" goes stale as service accounts get provisioned and decommissioned. I schedule a recurring review (quarterly, tied to whatever change-management cadence exists) that re-validates the rule against current baseline traffic and current tooling versions, rather than assuming a rule validated once stays valid indefinitely.
Lessons learned
- Anchor detections on the minimum behavior a technique requires, not on a specific tool's default artifacts — tool renames and flag changes are the first thing a competent adversary tries.
- A rule is not validated until it's been run against tool variation, not just the demo invocation used to write it.
- False-positive rate against real baseline traffic is not optional tuning, it's part of the definition of "done." An alert nobody can triage gets ignored, which is functionally the same as no detection.
- Write down what the rule doesn't catch. Undocumented blind spots get treated as covered ground by whoever reads the alert later.
- Detections decay. Put a review cadence on the calendar instead of assuming a rule that passed validation once stays correct forever.
References
- MITRE ATT&CK framework and detection data sources
- SigmaHQ rule format specification
- Sysmon configuration reference (SwiftOnSecurity baseline)
Tools used
Skills demonstrated