Detection Engineering: Creating Security Alerts and Rules
Learn detection engineering principles including rule development, Sigma rules, testing methodologies, false positive management, and building a detection program for security operations.
The Rule That Caught SolarWinds
In 2020, FireEye discovered SUNBURST — a backdoor planted in SolarWinds Orion software that had evaded every major security vendor's detection rules for months. The malware used legitimate code-signing certificates, blended into normal traffic, and mimicked standard API calls. After the breach was revealed, detection engineers built Sigma rules that could have identified the attack by modeling the adversary's behavior rather than searching for known IOCs. This shift — from signature matching to behavior-based detection — defines modern detection engineering.
Detection engineering is the discipline of designing, developing, testing, and maintaining detection logic that identifies malicious activity. It bridges the gap between threat intelligence and security operations.
Prerequisites
The Detection Engineering Lifecycle
Step 1: Intelligence Gathering
Identify detection opportunities from:
Step 2: Rule Development
Create detection logic as a query in the SIEM language or Sigma format:
# Sigma rule for detecting WMI lateral movement
title: WMI Process Call Create
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects WMI lateral movement via process call creation
references:
- https://attack.mitre.org/techniques/T1047/
tags:
- attack.t1047
- attack.lateral_movement
logsource:
product: windows
service: sysmon
definition: Requires Sysmon Event ID 1
detection:
selection:
EventID: 1
Image|endswith: '\wbem\WmiPrvSE.exe'
ParentImage|endswith: '\svchost.exe'
condition: selection
falsepositives:
- Legitimate WMI administration scripts
level: high
Step 3: Testing
Before deployment, rules must be tested against:
# Test detection with Atomic Red Team
Import-Module AtomicRedTeam
Invoke-AtomicTest T1047 # Test WMI execution
Step 4: Deployment
Deploy rules to production environment. Start with monitoring-only mode (log alerts but do not notify). This allows measurement of true and false positive rates before activation.
Step 5: Tuning
Based on monitoring results:
Step 6: Activation and Review
Activate alerting after tuning. Schedule periodic reviews:
Sigma Rule Format
Sigma is an open standard for writing detection rules in a generic format that can be converted to multiple SIEM languages (Splunk, KQL, Elastic, QRadar, etc.).
# Sigma rule components
title: Human-readable rule name
id: UUID for unique identification
status: experimental/test/stable/deprecated
description: What the rule detects
references: Links to additional context
tags: MITRE ATT&CK mappings
logsource: What log source is required
detection: The detection logic
falsepositives: Known legitimate cases
level: informational/low/medium/high/critical
Converting Sigma to SIEM Queries
# Convert Sigma to Splunk
sigmac -t splunk rule.yml
# Convert Sigma to Elastic
sigmac -t elastic rule.yml
# Convert Sigma to QRadar
sigmac -t qradar rule.yml
Detection Logic Patterns
Pattern Matching
Search for exact or pattern-matched values:
# Detect base64-encoded PowerShell commands
index=windows EventCode=4104 ScriptBlockText="*-enc*"
Threshold-Based
Alert when count exceeds a threshold:
# 10+ failed logons in 5 minutes (brute force)
index=windows EventCode=4625
| bucket span=5m _time
| stats count by _time, src_ip
| where count > 10
Sequence-Based
Detect events occurring in sequence:
# Process creation followed by network connection
index=endpoint
| transaction session_id maxspan=5s
| where mvcount(EventCode) >= 2
| search EventCode=4688 AND network_connect=true
Correlation-Based
Combine events from different sources:
# Failed logon followed by successful logon from different IP
index=windows (EventCode=4625 OR EventCode=4624)
| stats values(EventCode) as events, values(src_ip) as ips by UserName, _time
| where mvcount(ips) > 1 AND "4625" IN events AND "4624" IN events
False Positive Management
Sources of False Positives
Tuning Process
Detection Engineering Program
Maturity Model
Level 1 — Initial: Ad-hoc rules, mostly vendor-supplied, no standardized process.
Level 2 — Defined: Standardized rule format (Sigma), defined lifecycle, basic testing.
Level 3 — Managed: Purple team integration, coverage metrics, false positive tracking, quarterly reviews.
Level 4 — Optimized: Automated rule generation, machine learning augmentation, predictive detection, cross-environment correlation.
Metrics
Real-World Example: Building a Detection Rule
Scenario: A threat report describes a new Cobalt Strike beacon variant.
Common Mistakes
Best Practices
Related Tools
Related Articles
Summary
Detection engineering is the practice of creating and maintaining detection rules that identify malicious activity. The lifecycle includes intelligence gathering, rule development (preferably in Sigma format), testing, deployment, tuning, and regular review. Key concepts include pattern matching, threshold-based, sequence, and correlation detection. Managing false positives and mapping coverage to MITRE ATT&CK are essential for program maturity.