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.
Knowledge Check
Frequently Asked Questions
Continue Learning
Security Monitoring: Building Detection Capabilities
Learn how to build effective security monitoring capabilities including alert triage, monitoring strategy, tool selection, and creating a detection roadmap for security operations.
Security Operations · AdvancedIncident Response: Structured Approach to Security Breaches
Learn the incident response lifecycle including preparation, detection, containment, eradication, recovery, and lessons learned with practical frameworks and real-world scenarios.
Security Operations · AdvancedSIEM Fundamentals: Security Information and Event Management
A comprehensive introduction to SIEM systems covering architecture, log collection, correlation rules, deployment considerations, and how SIEM powers modern security operations centers.
Security Operations · AdvancedDigital Forensics Basics: Collecting and Analyzing Evidence
Learn digital forensics fundamentals including evidence collection, forensic imaging, memory analysis, timeline analysis, and proper chain of custody procedures for investigations.
Related Security Tools
Nmap
Learn how to use Nmap, the free open-source network scanner: run your first port scan, discover live hosts, detect services and operating systems, and check for vulnerabilities with NSE scripts — a beginner tutorial for Kali Linux.
Sniffing & SpoofingWireshark
Wireshark tutorial for beginners: capture packets, read the three panes, filter traffic and follow TCP streams — a hands-on guide to the world's foremost network protocol analyzer.
Sniffing & Spoofingtcpdump
tcpdump is a powerful, lightweight command-line packet analyzer that allows users to capture, parse, and filter TCP/IP and other packets transmitted or received over a network.
ExploitationMSFVenom
MSFVenom is a standalone payload generator and encoder utility within the Metasploit Framework, first introduced in Metasploit 4.0 (2015) to replace the legacy msfpayload and msfencode tools with a single unified interface. It enables security professionals, penetration testers, and students to create, customize, and encode payloads for multiple platforms including Windows, Linux, macOS, Android, and PHP. MSFVenom is widely used in CTF competitions, security training labs, authorized penetration testing engagements, and red team operations to generate reverse shells, Meterpreter payloads, shellcode, and encoded executables. Understanding MSFVenom helps both offensive and defensive security professionals learn payload construction techniques, encoding methods, and detection strategies used in modern cybersecurity.