Skip to content

Lesson 6 of 13 · 16m

Detections Are Code — Treat Them Like It

Sigma rules live in git, convert through sigma-cli, get reviewed in PRs, and get regression-tested against saved events — console-tuned rules die silently.

A detection rule is source code: it has logic, it has bugs, it has regressions when the platform changes underneath it, and it rots. The only difference between a rule and the rest of your codebase is that the industry spent a decade editing rules in web consoles with no version history. Detection-as-code fixes the tooling, not the concept.

Sigma's anatomy

Sigma is the shared format — a YAML rule that names what it detects without naming a SIEM:

title: Encoded PowerShell Command Line
status: test
logsource:
  product: windows
  category: process_creation
detection:
  selection:
    Image|endswith:
      - '\powershell.exe'
      - '\pwsh.exe'
    CommandLine|contains:
      - ' -enc'
      - ' -ec '
      - ' -encodedcommand'
      - 'FromBase64String'
  filter_known_good:
    CommandLine|contains: 'C:\Program Files\KnownAutomation\'
  condition: selection and not filter_known_good
level: high
falsepositives:
  - Internal automation scripts that legitimately use encoded commands

logsource scopes the event class, detection holds named selections combined in condition, falsepositives documents known-noise sources, level sets severity, status is the lifecycle marker (experimental, test, stable, deprecated). The filter + not idiom is how you tune without gutting the rule — more on that in the tuning lesson.

sigma-cli (the current tooling; the old sigmac is retired) converts this to Splunk SPL, Sentinel KQL, Elastic EQL or Lucene, and others through backend pipelines — sigma convert -t splunk -p sysmon rule.yml. The same source ships to every target, and the conversion is what CI checks.

The pipeline

The working pattern is the same one you use for application code. Rules in a git repo. A CI job that runs sigma check for schema validity, compiles every rule to every backend you run — a rule that fails to compile is a broken rule before it reaches production — and replays saved event fixtures: captured Sysmon JSON of the known-bad behavior and the known-good near-miss, asserting the first matches and the second does not. Merge deploys to the SIEM through its API or content pipeline. Rollback is git revert.

Why the console model fails

A rule edited in the SIEM console has no diff history, no review, no test, and no signal when the platform changes. The silent-kill class is real: field renames and schema migrations — a vendor renaming ProcessCommandLine to process_command_line, a table schema change in an XDR product — produce no error. The rule just stops matching, and the coverage it represented evaporates while the dashboard still lists it as enabled. Saved fixtures replayed in CI catch this the day it happens; console editing discovers it during the next incident.

Review on a rule is a checklist, not a skim: does it key on durable fields — paths and command-line structure — instead of throwaway strings the actor rotates; does its falsepositives list cover your environment's known-good automation; is severity set to how the org will actually treat it; does it have a fixture proving it fires. A rule without a fixture is an unproven rule.

The shared vocabulary already exists

SigmaHQ's sigmahq/sigma repository is the public corpus — thousands of rules organized by technique, each carrying falsepositives documentation you are expected to tune for your environment, not ship verbatim. Splunk's security_content (ESCU) and Elastic's detection-rules repos ship versioned detections the same way. The mature posture: vendor and community rules vendored in, your rules beside them, one pipeline.

What to actually do

Stand up the repo with CI that compiles and fixture-tests. Put every existing console rule through review as you import it — half will be dead or duplicated. Mark new rules status: test until they have fired on a known-bad fixture, then promote to stable. And audit silence: a rule with zero matches in ninety days is either working on a quiet technique or dead — the fixture test tells you which.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.