Detections as code, and a map of what you cover

Unit 5 of 5 in Detection engineering.

You will be able to describe how detections are kept as reviewed, tested code and how to map and review your coverage.

Lesson

Rules are code: store, review, version

Palantir's project page says each production or draft alert based on the ADS framework is stored in a durable, version-controlled, centralized location, such as a wiki or a repository, and peer-reviewed before it reaches production. That is detection as code: the rule, its documentation and its test live together, changes are proposed and reviewed, and history shows who changed what and why.

Sigma's own repository shows the habit at scale. Its contributing guide asks authors to fork, branch, test and open a pull request. It also separates rule folders by purpose, listing rules, emerging-threat rules, threat-hunting rules and compliance rules, so a noisy hunting rule is not mistaken for a production alert.

Test automatically

The Sigma contributing guide lists the checks a rule must pass before it is accepted. One test checks that every rule references a valid log source and field names. Another checks for structural problems and common mistakes. The Sigma command-line tool can run validation with options that make the run fail on errors or issues. An optional check runs the rules against clean Windows event log baselines to surface false positives, and optional regression tests run rules against recorded event files.

Each check maps to a lesson in this class: valid structure (the rule is well formed), baseline (false positives), regression (true positives and variants still fire). A pipeline that runs them on every change catches the day someone edits a rule so it stops firing, or starts matching normal activity. The lab for this unit builds such a pipeline and breaks it on purpose to watch it fail.

Convert and deploy for your own tools

Sigma rules are tool-neutral, so something must turn them into your SIEM's language. Backends are the drivers of that conversion, and the pySigma library provides the programming interface that each backend uses. With the command-line tool, a typical conversion names the target backend and, optionally, a processing pipeline that adapts the rules to how your logs are set up (its own example uses one for Sysmon logs), followed by a rule file or folder. Backends are installed as plugins, and the tool can list what is available.

The tool can also write one output file per rule, which its documentation describes as useful for version control or selective deployment. Keep the converted output out of hand-editing: if a converted query needs a fix, fix the rule, the filter or the pipeline, and convert again.

Map your coverage, honestly

A coverage map answers 'which techniques could we see, and which could we not?' The ATT&CK Navigator lets you create layers: custom views of the ATT&CK knowledge base that you can use to visualize your defensive coverage. DeTT&CT is a framework built on it that aims to help blue teams score and compare data source quality, visibility coverage and detection coverage, and to compare them with the behaviours of threat actors, so you can prioritise improvements. It produces layer files you open in the Navigator.

Read the map with care. This is our reasoning, not a quote from either project: a technique shown as covered may be covered by a single rule that catches one variation, so coverage is a statement about effort and evidence, not a promise of detection. Pair every coloured cell with a test result.

Own it, date it, retire it

Sigma's specification gives rules the vocabulary of a lifecycle: a modified date that you change when the title, detection, level or log source changes; a status that moves from experimental to test to stable and can end at deprecated; and a related field that records that one rule obsoletes or was derived from another. Palantir adds the human side: a response section so the next responder knows what to do, and a priority section that says why a rule has its level.

Give every rule an owner and a review date. When a rule stops being useful, mark it deprecated and say which rule replaces it, rather than deleting it, so that the history and the reason survive.

Key points

Sources

Practice in the labs

Build a rule pipeline that fails when a rule breaks, map your coverage, check that your telemetry has not gone silent, and prove a drafted rule before you trust it.

Knowledge check

  1. Why does Sigma's repository keep hunting rules in a different folder from its main rules? Answer: So a noisy hunting rule is not mistaken for a production alert. The contributing guide lists separate folders for rules, emerging threats, threat hunting and compliance. Keeping purposes apart lets readers tell a rule meant for alerting from one meant for analyst-led searching.
  2. What does a pipeline step that runs rules against clean baseline logs catch? Answer: Rules that match normal activity, which would be false positives. The Sigma contributing guide describes a baseline check that runs your rules against clean Windows event log baselines to surface false positives before the rule is accepted.
  3. A converted SIEM query has a small bug. What is the best fix? Answer: Fix the Sigma rule, filter or pipeline and convert again. The rule is the source of truth. Editing only the converted output means the next conversion brings the bug back and the reviewed rule no longer matches what runs.
  4. Why is a technique shown as covered on a coverage map not a guarantee? Answer: One rule may catch only one variation, so a coloured cell needs a test result behind it. Coverage layers record your own scores for data and detection. They show effort and evidence, and a single passed test proves one variation of a technique, not the technique.

Back to the syllabus or see all classes.

Related