Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Lab · 30 min · revision 1

Writing and Converting a Sigma Rule

Author vendor-agnostic Sigma detection rules mapped to MITRE ATT&CK techniques, validate selection logic, explore argument obfuscation evasion techniques, and compile rules into native query dialects using pySigma.

Contentsand lesson path

On this page

  1. Anatomy of a Production-Ready Sigma Rule
  2. Authoring a Sigma Rule and Compiling with pySigma
  3. Practice check
  4. Review prompt

Lessons of Detection Engineering

  1. The Detection Lifecycle and Detections as Code Concept · 15 min
  2. Writing and Converting a Sigma Rule Lab · 30 min
  3. Proving Detections with Adversary Emulation Lab · 30 min
  4. Tuning for Precision Without Blind Spots Worked example · 20 min
  5. Coverage Gaps, Deception and Hypothesis-Driven Hunting Worked example · 25 min
  6. Detection Engineering Check Knowledge check · 8 questions

What you will learn

  • Write a Sigma rule for a specific ATT&CK technique, convert it to a SIEM query, and document its data source, logic and known false positives.

Prerequisites: Security Logging & SIEM

01. Anatomy of a Production-Ready Sigma Rule

Sigma is the universal standard for signature description in computer security — equivalent to Snort for network traffic or YARA for file payloads. Prior to Sigma, threat intelligence teams shared detections as unformatted blog paragraphs or proprietary query snippets tied to a specific commercial vendor. If an advisory shared a Splunk query, organizations running Elastic Security, Microsoft Sentinel, or Wazuh had to manually translate the logic into their respective query languages.

A production-grade Sigma rule is defined in human-readable YAML structured into five mandatory functional sections:

1. Metadata & Identification Defines title, a unique UUID4 id (guaranteeing deterministic tracking across rule version updates), operational status (experimental, test, stable, deprecated), detailed description, and external references to threat reports.

2. Categorization & MITRE ATT&CK Tagging Annotated with standardized tags that map the detection to exact MITRE ATT&CK matrix identifiers: tactics (e.g., attack.execution) and specific technique IDs (e.g., attack.t1059.001 for PowerShell).

3. Log Source Specification (logsource) Explicitly declares the telemetry requirements necessary for rule execution: category (such as process_creation), product (such as windows), and service (such as sysmon). This ensures the rule is only evaluated against relevant telemetry indices.

4. Detection Logic & Modifiers (detection) Specifies field selections, search modifiers, and boolean evaluation logic. Sigma provides powerful string and list modifiers:

  • |contains: Substring matching (case-insensitive by default in most backends).
  • |endswith & |startswith: Prefix and suffix matching, commonly used for image paths and file extensions.
  • |all: Requires all values in a defined list to match simultaneously, rather than default OR semantics.
  • |re: Regular expression matching adhering to PCRE standards.
  • |base64offset: Automatically expands a target search string into all three possible base64-encoded representations, defeating simple base64 command obfuscation.

The condition statement defines the relationship between selections, exclusions, and thresholds (such as selection_process and selection_cli and not filter_admin_tools or 1 of selection_*).

5. False Positives & Severity Rating Every rule must document known benign conditions in falsepositives (such as legitimate administrative management scripts) and assign an operational level (informational, low, medium, high, critical) that informs SOC paging priorities.

02. Authoring a Sigma Rule and Compiling with pySigma

In this hands-on lab, we author a Sigma rule targeting MITRE ATT&CK T1059.001 (PowerShell Download Cradles). Adversaries routinely invoke powershell.exe with hidden window styles and download cradle syntaxes (such as DownloadString, DownloadFile, or Invoke-WebRequest piped into Invoke-Expression / IEX) to execute second-stage payloads entirely in memory.

To make the detection resilient against simple evasion, our rule monitors Windows process creation events (Sysmon Event ID 1 or Security Event ID 4688) for execution of PowerShell with download cradle flags, while explicitly filtering out approved internal management frameworks like Microsoft Intune and SCCM. We will trace how these cradle patterns evade basic filename filters and how structured command-line telemetry reliably exposes them.

The true power of Sigma lies in its compilation toolchain: pySigma. Rather than forcing security teams to maintain separate query files for each technology in their stack, pySigma decouples detection logic from search engine implementations:

  • Abstract Syntax Tree (AST): The pySigma parser ingests the declarative YAML file and converts selections and conditions into an in-memory boolean AST representation.
  • Processing Pipelines: Pipelines apply transformation rules that adapt abstract field names and value formats to target environment realities. For example, the ecs pipeline transforms the abstract Sigma field CommandLine into process.command_line and Image into process.executable, while escaping special characters.
  • Target Backends: Backends (such as pySigma-backend-opensearch, pySigma-backend-splunk, or pySigma-backend-microsoft-sentinel) traverse the transformed AST and serialize it into the target platform's native query syntax (Lucene, SPL, KQL, or AQL).

When engineering detections against command-line activity, engineers must anticipate common adversary evasion techniques. Attackers rarely execute clean, textbook commands like powershell.exe -Command "DownloadString". Instead, they leverage shell flexibility to bypass naive substring matching:

  • Argument Obfuscation: PowerShell accepts non-standard flag shorthands and case variations (e.g., -w hidden, -WindowStyle 1, -e, -ec, -enc, -EncodedCommand). Attackers insert backticks, caret symbols, or variable formatting to split strings across execution tokens.
  • Piping & In-Memory Execution: By piping payloads directly into standard input (Get-Content payload.txt | powershell -) or executing via reflective DLL loading, adversaries minimize command-line footprints.
  • Defense in Depth with Script Block Logging: Process creation telemetry (Event 4688 / Sysmon 1) only captures initial launcher arguments. If an attacker passes an encoded string, the process creation log contains only base64 characters. To counter this, robust defense-in-depth pairs process creation rules with PowerShell Script Block Logging (Event ID 4104), which captures the completely de-obfuscated code block immediately prior to execution in the Common Language Runtime (CLR) engine.
Sigma rule detecting suspicious PowerShell download cradle execution
title: Suspicious PowerShell Download Cradle Execution
id: 4a2d3e1f-8c9b-4f7a-8b1e-3c2d1e0f9a8b
status: test
description: Detects PowerShell executing remote download cradle commands
references:
  - https://attack.mitre.org/techniques/T1059/001/
author: Security Engineering Team
date: 2026/11/09
tags:
  - attack.execution
  - attack.t1059.001
logsource:
  category: process_creation
  product: windows
detection:
  selection_process:
    Image|endswith:
      - "\powershell.exe"
      - "\pwsh.exe"
  selection_cli:
    CommandLine|contains:
      - "DownloadString"
      - "DownloadFile"
      - "Invoke-WebRequest"
      - "Net.WebClient"
  filter_admin_tools:
    CommandLine|contains:
      - "C:\Program Files\Microsoft Intune Management Extension"
  condition: selection_process and selection_cli and not filter_admin_tools
falsepositives:
  - Legitimate automated administrative deployment scripts
level: high
Compiling Sigma rule into OpenSearch Lucene and Splunk SPL using pySigma CLI
# 1. Compile Sigma rule to OpenSearch Lucene format with ECS mapping
sigma convert \
  -t opensearch-lucene \
  -p ecs \
  rules/proc_creation_win_powershell_download_cradle.yml

# 2. Compile same Sigma rule to Splunk SPL query format
sigma convert \
  -t splunk \
  rules/proc_creation_win_powershell_download_cradle.yml

# 3. Compile to Microsoft Sentinel KQL (Kusto Query Language)
sigma convert \
  -t microsoft-sentinel \
  rules/proc_creation_win_powershell_download_cradle.yml
Expected output of the pySigma multi-target compilation commands
=== TARGET: OPENSEARCH LUCENE (ECS MAPPING) ===
(process.executable:*\\powershell.exe OR
 process.executable:*\\pwsh.exe) AND
(process.command_line:*DownloadString* OR
 process.command_line:*DownloadFile* OR
 process.command_line:*Invoke\-WebRequest* OR
 process.command_line:*Net.WebClient*) AND NOT
(process.command_line:*Microsoft\ Intune*)

=== TARGET: SPLUNK SPL ===
(Image="*\\powershell.exe" OR Image="*\\pwsh.exe") AND
(CommandLine="*DownloadString*" OR
 CommandLine="*DownloadFile*" OR
 CommandLine="*Invoke-WebRequest*" OR
 CommandLine="*Net.WebClient*") NOT
(CommandLine="*Microsoft Intune*)

=== COMPILATION STATUS ===
Parsed 1 rule | Validated: 1 | Backend conversions: 3 | Errors: 0

03. Practice check

Practice check · 2 questions

Practice check

Validate your understanding of Sigma rule specification, field modifiers, and pySigma compilation targets.

Q1. In Sigma rule syntax, how does the `|contains` field modifier affect the underlying search translation?
Q2. Why is pySigma conversion valuable in multi-cloud or hybrid enterprise security environments?
Practice only: not graded, not saved, not evidence.

04. Review prompt

Deconstruct the core architectural sections of a production Sigma rule (metadata, MITRE ATT&CK tags, logsource, detection logic, false positives, and severity level), explaining why each section is critical for operational clarity.

Explain the technical mechanics of the pySigma conversion engine, detailing how pipelines map abstract field names (like CommandLine and Image) into concrete target schemas (such as ECS process.command_line and process.executable). Outline the steps for compiling a single Sigma rule into OpenSearch Lucene, Splunk SPL, and Microsoft Sentinel KQL without altering the source YAML.

Describe how to manage detection rule versioning and deprecation in enterprise Git repositories, explaining why UUID4 rule IDs must remain constant across logic revisions while rule status transitions from experimental to stable.

Discuss the role of custom pySigma processing pipelines in handling proprietary internal logging schemas, explaining how organizations author custom YAML pipeline extensions to remap organizational log fields without modifying open-source upstream community rules.

Explain how detection engineering teams measure the operational trade-offs between detection precision and recall when designing Sigma rules, describing how overly broad substring matches trigger devastating SOC alert fatigue while excessively narrow command-line constraints allow trivial adversary string evasion through backtick insertion and variable splitting.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check