Can We Learn to Write Better Detection Rules?

When I started this project, my research question was: can we learn how detection engineers improve their rules, and use that knowledge to train AI systems to write better ones?

Detection rules describe patterns of suspicious activity in system logs, such as unusual PowerShell commands or the creation of administrator accounts. However, their effectiveness is highly environment-dependent, as what looks suspicious in one organization may be normal behaviors in another.

I once spoke with a Splunk detection engineer, and he told me that engineers developing shared detection content often don’t know the environments where their rules will be deployed. They rely on customer feedback to identify noisy rules, but don’t necessarily have access to the logs or context needed to evaluate alternatives directly.

Ideally, I wanted to study how engineers tune rules for specific environments and whether we could learn from those adjustments. Unfortunately, obtaining private enterprise rules and operational logs wasn’t realistic for this project.

So I started with what we could observe: the public Git histories of two widely used detection rule collections, Sigma and Splunk Security Content. These repositories contain years of revisions to thousands of rules. Although they don’t tell us how rules perform in individual environments, they offer a way to study how shared detection logic evolves.

This led me to a more foundational question: what kinds of changes do engineers make to detection rules, and what patterns emerge over time?

At first, that sounded like a job for git diff. It turned out to be more complicated.

A Text Diff Is Not a Logic Diff

Detection rules are essentially logical expressions that define which events should match. However, rule languages are expressive enough that the same detection logic can be written in different ways. For example, A AND B and B AND A are logically equivalent even though they differ in text. We can normalize some of these differences, but a simple text diff still only tells us which lines has changed, not how the underlying logical structure changed.

To study these changes systematically, we parse rules into a common representation of their logical predicates, which leads us to another question: how do we identify which predicates in an older version correspond to those in a newer version? Without these correspondences, we can observe that two rules differ, but cannot easily describe how one evolved into the other.

This was probably the most intellectually demanding part of the project for me. I considered using SMT solvers to check logical equivalence, but knowing whether two expressions are equivalent doesn’t tell us how their predicates correspond when they differ. Since our representation organizes predicates into trees, I started looking into tree edit distance.

I ended up reading work on unordered tree alignment, including approaches from computational biology, to understand how constraints can make these difficult alignment problems tractable.

Our aligner isn’t a perfect model of rule behavior, and it doesn’t fully capture certain operations (e.g. parts of SPL pipelines). Still, it gives us a systematic and interpretable way to describe revisions across thousands of rule histories.

When Rules Keep Changing Their Minds

Once we could measure changes systematically, I found that some rules didn’t simply become broader or narrower over time. I had expected revisions to generally reflect attempts to improve detection, whether by expanding coverage or reducing false positives. Instead, some of them went back and forth.

For example, below we show the Splunk Security Content’s detect_new_local_admin_account rule, one of the case studies in the paper. Version 61 uses a transaction pipeline to correlate events. Version 62 replaces it with a stats pipeline and adds two explicit conditions: evCount = 2 and duration < 7200. Later that same day, version 63 removes those conditions and restores version 61’s detection text exactly.

Show the reversal: detect_new_local_admin_account, v61 → v62 → v63

Read the comparisons from top to bottom. Green highlights mark inserted predicates; red highlights mark deleted predicates. Faded predicates are unchanged.

1. v61 → v62: two conditions added

September 29 → October 13, 2023. Version 62 adds evCount = 2 and duration < 7200.

+ 2 inserted = 6 unchanged precise alignment
v61 2023-09-29
OR
AND
EventCode = 4720
source = XmlWinEventLog:Security
AND
EventCode = 4732
Group_Name = Administrators
Channel = security
eventtype = wineventlog_security
v62 2023-10-13
AND
OR
AND
EventCode = 4720
source = XmlWinEventLog:Security
AND
EventCode = 4732
Group_Name = Administrators
Channel = security
eventtype = wineventlog_security
duration < 7200
evCount = 2

Explore v61 → v62 interactively

2. v62 → v63: the same conditions removed

Later on October 13, 2023, version 63 removes both conditions and restores the detection text from v61.

− 2 deleted = 6 unchanged precise alignment
v62 2023-10-13
AND
OR
AND
EventCode = 4720
source = XmlWinEventLog:Security
AND
EventCode = 4732
Group_Name = Administrators
Channel = security
eventtype = wineventlog_security
duration < 7200
evCount = 2
v63 2023-10-13
OR
AND
EventCode = 4720
source = XmlWinEventLog:Security
AND
EventCode = 4732
Group_Name = Administrators
Channel = security
eventtype = wineventlog_security

Explore v62 → v63 interactively

The predicate view shows the added and then removed conditions. The SPL also switches from a transaction pipeline to a stats pipeline and back (the predicate graph does not capture all pipeline semantics).

This rule is an example of how a detection strategy can change direction instead of simply accumulate refinements. Across the repositories, we found many rules that underwent both expansions and contractions, sometimes years after their initial creation.

What Does It Mean for a Rule to Get Better?

After spending so much time tracing revisions, I still can’t answer the question that originally motivated this work: which version of a rule is actually better? A broader or narrower predicate tells us how the matching conditions changed, but without knowing what happens in the target environment, we can’t tell whether the revision improved detection in practice.

That leaves me with questions I still find worth pursuing. Could engineers use local telemetry to evaluate alternative versions of a shared rule? Could historical revisions help suggest candidate adaptations? Or does repeated manual rewriting point to a limitation of static rules themselves (one that might be better addressed by parameterizing rules for different environments)?

I think of this project as laying a foundation stone. It isn’t the environment-aware rule generator I originally imagined, but it gives us a way to make rule evolution visible and ask more informed questions about it. Whether that eventually helps us write better rules remains to be seen.

If you’re curious, you can read the paper, browse the code and artifacts, or explore a few rule histories in the interactive explorer. I’d be especially interested in hearing how detection engineers interpret the histories that seem to keep changing their minds.