Blue Teamby OneToSecure
Book a call

Chapter 02 · Detection engineering

Detection engineering: writing detections that detect

A detection rule is a software product: you design it, test it, version it, measure it and retire it when it no longer serves. Here is the method, sample rules and the pitfalls to avoid.

Chapter 02 of 095 min readUpdated

Blue network cables neatly plugged into a white patch panel in a bright data centre
Formats
Sigma · KQL · SPL
Approach
Detection-as-code
Framework
MITRE ATT&CK

From use case to rule

Detection engineering turns knowledge of attackers into reliable, documented and measurable detections. Everything starts with a use case: a precise malicious behaviour you want to spot in a given context.

Detection cycle : Need → Research → Development → Testing → Deployment → Tuning01Need02Research03Development04Testing05Deployment06TuningDetection cycle
  1. 01 · Need — Priority threat, ATT&CK technique, incident or Red Team finding
  2. 02 · Research — Understand the technique and the logs it produces
  3. 03 · Development — Write the rule, document it, define triage
  4. 04 · Testing — Replay the technique, measure false positives
  5. 05 · Deployment — Versioned release, performance monitoring
  6. 06 · Tuning — Justified exclusions, improvement, retirement if obsolete
The lifecycle of a detection

Prioritising: what to detect first?

You cannot detect everything. Prioritisation crosses three dimensions:

  • The threat: techniques used by adversaries targeting your sector (see Threat intelligence);
  • Visibility: do you have the necessary logs? If not, collection comes first;
  • Impact: techniques that lead to critical assets (privileged identities, backups, sensitive data).

Sigma, the universal format

Sigma is an open YAML format for describing detection rules independently of the SIEM. The same rule can be converted into a query for Microsoft Sentinel (KQL), Splunk (SPL), Elastic, QRadar and many others. Thousands of community rules are available and make an excellent starting point.

proc_access_lsass_susp.yml
title: Suspicious access to LSASS memory
id: 4a1c2e3f-8d5b-4e7a-9c2d-1f0e6b7a8c90
status: experimental
description: >
  Detects an unusual process opening LSASS with rights that allow
  reading memory (credential extraction).
references:
  - https://attack.mitre.org/techniques/T1003/001/
tags:
  - attack.credential-access
  - attack.t1003.001
logsource:
  product: windows
  category: process_access
detection:
  selection:
    TargetImage|endswith: '\lsass.exe'
    GrantedAccess|contains:
      - '0x1010'
      - '0x1410'
      - '0x1fffff'
  filter_legit:
    SourceImage|endswith:
      - '\MsMpEng.exe'
      - '\csrss.exe'
      - '\wininit.exe'
  condition: selection and not filter_legit
falsepositives:
  - Legitimate security or backup solutions (exclude them by name)
level: high

The same logic in KQL (Microsoft Sentinel / Defender)

KQL query
DeviceEvents
| where ActionType == "OpenProcessApiCall"
| where FileName =~ "lsass.exe"
| where InitiatingProcessFileName !in~ ("MsMpEng.exe", "csrss.exe", "wininit.exe")
| summarize Attempts = count(), First = min(Timestamp)
    by DeviceName, InitiatingProcessFileName, InitiatingProcessAccountName
| order by Attempts desc

Another example: Kerberoasting

Detecting a burst of RC4 ticket requests
SecurityEvent
| where EventID == 4769
| where TicketEncryptionType == "0x17"          // RC4-HMAC
| where ServiceName !endswith "$"
| summarize Services = dcount(ServiceName), List = make_set(ServiceName, 20)
    by Account = TargetUserName, IpAddress, bin(TimeGenerated, 10m)
| where Services >= 5

Documenting a detection

A rule without documentation is an alert nobody knows how to handle. Each detection must come with a card:

FieldContent
ObjectiveThe targeted behaviour and why it matters
ATT&CKTactic and technique(s)
Data sourcesRequired logs and their configuration
LogicReadable description of the rule
Known false positivesLegitimate situations that trigger the rule
TriageQuestions to ask, data to collect
ResponseRecommended actions depending on the verdict
TestHow to reproduce the technique to validate the rule
Owner and versionWho maintains it, change history

Detection-as-code

Detection-as-code applies software development practices to detection rules: Git repository, code review, automated tests and continuous deployment.

  1. Versioned repository

    All rules (Sigma, KQL, SPL) and their cards live in a Git repository. Each change is traced and peer-reviewed.

  2. Automatic validation

    On every change, a CI pipeline checks syntax, converts Sigma rules and verifies mandatory metadata (ATT&CK, owner, false positives).

  3. Regression tests

    Reference log datasets, or running Atomic Red Team in a lab, prove that the rule fires on the attack and not on usual noise.

  4. Continuous deployment

    Validated rules are pushed automatically to the SIEM via its API. Rollback is instant.

  5. Measurement

    Alert volume, true positive rate and handling time per rule drive tuning or retirement decisions.

.github/workflows/detections.yml (excerpt)
name: detections-ci
on: [pull_request]
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Check Sigma rules
        run: sigma check rules/
      - name: Convert for Microsoft Sentinel
        run: sigma convert -t kusto -p microsoft_xdr rules/ -o build/
      - name: Check mandatory metadata
        run: python tools/lint_metadata.py rules/

Measuring coverage

The MITRE ATT&CK matrix serves as the map. For each priority technique, the coverage level is assessed: no visibility, logged, detected, detected and tested. Tools such as ATT&CK Navigator or DeTT&CT visualise this coverage and track its progress.

The most cost-effective log sources

  • Entra ID and Active Directory authentications
  • EDR telemetry (process, network, registry)
  • Microsoft 365 and email logs
  • Sysmon on critical servers
  • PowerShell Script Block Logging
  • DNS and web proxy
  • Firewall and VPN
  • Admin and cloud consoles (AWS, Azure, GCP)

Frequently asked questions

Should you use the rules provided by the SIEM or EDR vendor?

Yes, as a foundation: they cover many common threats. But they do not know your environment. The most effective detections are often the ones you write for your critical assets, privileged accounts and business processes.

How do you reduce false positives without losing detection?

With precise, justified exclusions (never generic ones), contextual enrichment (asset criticality, user role), correlation of several weak signals and, for very noisy rules, turning them into threat hunting queries rather than alerts.

What is a honeytoken?

A decoy: an account, a file, an API key or a DNS record with no legitimate use. Any use is therefore suspicious by nature. They are very reliable and inexpensive detections.

Does your defence really see what matters?

In 45 minutes, let's review your SOC, your detection coverage and your response capability, and identify the three workstreams that will make the biggest difference.

Book a meeting