Skip to content

Guide 05 of 12

Detection Engineering and Detection-as-Code with Sigma

The detection engineering lifecycle from idea to retirement, and how to run detections as code with Sigma rules, Git, CI validation, tests and deployment.

Published on 6 min read
On this page
  1. The detection lifecycle
  2. Detection-as-code
  3. Testing detections
  4. Tuning and feedback
  5. Prioritizing what to build
  6. References

Detection engineering is the discipline of building, testing and maintaining the logic that turns telemetry into alerts. Done well, it is software engineering applied to detections: requirements, version control, review, tests, deployment and monitoring. Done badly, it is a SIEM full of rules that someone enabled years ago, that nobody understands, and that analysts have learned to ignore.

This guide covers the lifecycle and a concrete detection-as-code setup using Sigma. It assumes the telemetry is in place; see SIEM architecture and log sources for that.

The detection lifecycle

Every detection goes through the same stages, whether you formalize them or not.

  1. Requirement. Why should this detection exist? Sources: the threat model, threat intelligence, a hunt that found something, an incident post-mortem, an ATT&CK coverage gap, a red team finding.
  2. Research. Understand the technique: how it works, what telemetry it leaves, how legitimate activity looks similar. Reproduce it in a lab.
  3. Development. Write the logic, ideally in a portable format, with metadata.
  4. Testing. Prove it fires on the malicious behavior and measure how often it fires on normal activity.
  5. Review. A second engineer checks logic, performance and documentation.
  6. Deployment. Push to the SIEM or EDR through an automated pipeline.
  7. Monitoring and tuning. Track volume, true positive rate and analyst feedback; adjust.
  8. Retirement. Remove detections that no longer apply, are superseded, or never produce value.

Document the strategy, not just the query

Palantir's Alerting and Detection Strategy (ADS) framework is a widely used template for documenting a detection. Each detection gets: goal, categorization (ATT&CK mapping), strategy abstract, technical context, blind spots and assumptions, false positives, validation, priority and response. The "blind spots" and "validation" sections are the ones teams skip and later regret. Writing down "this does not catch the technique if the attacker renames the binary" is what tells a hunter where to look.

Pick the right abstraction level

David Bianco's Pyramid of Pain is the classic reminder: detections on hash values and IP addresses are trivial for attackers to evade, while detections on tools and on tactics, techniques and procedures (TTPs) cost attackers real effort. Indicator matching still has its place (it is cheap and catches commodity threats), but most engineering time should go to behavioral detections.

Detection-as-code

Detection-as-code means detections live in a Git repository as text files, changes go through pull requests, a CI pipeline validates and tests them, and deployment to the SIEM is automated. Benefits:

  • History and blame: who changed this rule, when and why.
  • Peer review before production.
  • Automated tests that catch syntax errors and regressions.
  • Portability across SIEMs when written in a vendor-neutral format.
  • Reproducible environments: the SIEM's rule set can be rebuilt from the repository.

Sigma in one minute

Sigma is an open, generic signature format for log-based detections, maintained by the SigmaHQ project. A rule describes the log source and the detection logic in YAML; backends convert it into Splunk SPL, KQL, Elastic queries, ES|QL and many other targets. The public SigmaHQ repository contains thousands of community rules you can use as a starting point.

A minimal rule for certutil being used to download a file:

title: Certutil Download via URLCache
id: 3f2a4c1e-8b7d-4e0a-9c5f-2d6e1b7a9c40
status: experimental
description: Detects certutil.exe used with -urlcache to download a file, a common living-off-the-land technique.
references:
  - https://attack.mitre.org/techniques/T1105/
author: SOC Detection Engineering
date: 2026-11-08
tags:
  - attack.command-and-control
  - attack.t1105
logsource:
  category: process_creation
  product: windows
detection:
  selection_img:
    - Image|endswith: '\certutil.exe'
    - OriginalFileName: 'CertUtil.exe'
  selection_cli:
    CommandLine|contains|all:
      - 'urlcache'
      - 'http'
  condition: all of selection_*
falsepositives:
  - Rare administrative scripts; document and exclude by parent process or host
level: high

Note the OriginalFileName selection: it still matches if an attacker copies and renames the binary, which is exactly the kind of blind spot the ADS documentation should call out.

Converting rules

The sigma-cli tool installs backends as plugins and converts rules, applying processing pipelines that map Sigma's generic field names to your schema:

pip install sigma-cli
sigma plugin install splunk
sigma list pipelines
sigma convert -t splunk -p sysmon rules/windows/process_creation/

For other targets, install the relevant plugin and use sigma list targets and sigma list pipelines to find the identifiers. Field mapping is where most conversion bugs live: if your process creation events come from an EDR with different field names, write or adapt a processing pipeline instead of editing every rule.

A repository layout

detections/
  rules/
    windows/
      process_creation/
        proc_creation_win_certutil_urlcache.yml
    cloud/
      aws/
    identity/
  pipelines/
    corp_edr_fields.yml
  tests/
    proc_creation_win_certutil_urlcache/
      true_positive.json
      false_positive_admin_script.json
  docs/
    ads/
  .github/workflows/detections.yml

A CI pipeline

A minimal GitHub Actions workflow that validates every rule and converts the set on each pull request:

name: detections
on:
  pull_request:
    paths: ["rules/**", "pipelines/**"]
  push:
    branches: [main]
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install sigma-cli
      - run: sigma plugin install splunk
      - name: Lint and validate rules
        run: sigma check rules/
      - name: Convert rules
        run: sigma convert -t splunk -p sysmon -p pipelines/corp_edr_fields.yml rules/ > build/queries.spl

On merge to main, a deployment job pushes the converted queries to the SIEM through its API (saved searches, analytics rules or detection rules, depending on the product). Several SIEMs also support their own native detection-as-code tooling, for example Elastic's detection-rules repository and CLI, or Splunk's security_content project; those are good references for test and metadata conventions even if you use Sigma.

Testing detections

Syntax validation is not testing. A detection is tested when you have evidence it fires on the behavior and stays quiet enough on normal activity.

True positive tests. Execute the technique in a lab or in a controlled production test and confirm the alert appears. Atomic Red Team provides small, scriptable tests mapped to ATT&CK techniques; for example, with the Invoke-AtomicRedTeam PowerShell module:

Invoke-AtomicTest T1105 -ShowDetailsBrief
Invoke-AtomicTest T1105 -TestNumbers 7

Check the test details before running anything, and run only in environments where you have approval.

Replay tests. Store sample events (from the lab or sanitized from incidents) as fixtures and replay them into a test index in CI. Public datasets such as OTRF's Security-Datasets contain recorded telemetry for many techniques.

False positive estimates. Before deploying, run the query over the last 30 days of production data. If it returns hundreds of hits, tune it before analysts ever see it.

Continuous validation. Schedule a subset of atomic tests weekly, or use a breach and attack simulation platform, and alert when an expected detection does not fire. This catches silent breakage from parser changes and log source outages.

Tuning and feedback

Every alert closure should carry a reason code (true positive, benign true positive, false positive with cause). Detection engineers review per-rule statistics weekly:

  • Rules with a very low share of actionable alerts and high volume get tuned or demoted to a hunting query.
  • Rules that never fired in six months get a test: either they still work and the behavior is rare (keep), or they are broken (fix or retire).
  • Exclusions are code too: add them in the rule or a shared filter file with a comment explaining who approved them and why.

The triage guide describes the analyst side of this loop.

Prioritizing what to build

With limited engineering capacity, prioritize detections that are:

  1. Mapped to techniques used by adversaries in your threat model.
  2. Covering a gap: no existing detection, ideally confirmed through ATT&CK coverage mapping (see the maturity guide).
  3. Feasible with data you already collect.
  4. Likely to produce a manageable volume.

Keep a backlog in the same issue tracker as the repository, with the requirement source linked to each item.

References

Filed underdetectionsiemsoc

Written by

Florian Amette

Security engineer writing practical, vendor-neutral guidance on building and running Security Operations Centers: detection engineering, SIEM, triage, incident response and SOC metrics.