TExcelTAD
Home › Defensive Security: SOC, SIEM, Detection Engineering & Threat Hunting › Sigma Rules: Structure, Modifiers and Field Mapping

Sigma Rules: Structure, Modifiers and Field Mapping

A detection written in Splunk SPL is useless to a team on Microsoft Sentinel, and one written for Elastic has to be rewritten when the company changes SIEM. Sigma is the common answer: a generic, YAML-based format for log detections that describes what to look for in terms of a log source and field values, and converters translate it into each SIEM's query language. Public Sigma repositories hold thousands of community rules, threat reports increasingly ship Sigma rules, and detection-as-code repositories (Detection as Code) often store everything in Sigma. This lesson reads a rule part by part, covers the modifiers and conditions, and shows how field mapping connects a rule to your schema.

A rule, part by part

yaml
title: Office Application Spawns a Command Shell or Script Host
id: 3f1c2a9e-5b7d-4e1a-9c2b-6d8e0f4a7b31
status: test
description: Detects Word, Excel, PowerPoint or Outlook starting a shell or script interpreter, typical of malicious documents.
references:
    - https://attack.mitre.org/techniques/T1204/002/
author: lab.test detection engineering
date: 2026-01-15
tags:
    - attack.execution
    - attack.t1204.002
    - attack.t1059.001
logsource:
    category: process_creation
    product: windows
detection:
    selection_parent:
        ParentImage|endswith:
            - '\winword.exe'
            - '\excel.exe'
            - '\powerpnt.exe'
            - '\outlook.exe'
    selection_child:
        Image|endswith:
            - '\cmd.exe'
            - '\powershell.exe'
            - '\pwsh.exe'
            - '\wscript.exe'
            - '\cscript.exe'
            - '\mshta.exe'
    filter_known_macro:
        CommandLine|contains: 'lab-finance-report.cmd'
    condition: selection_parent and selection_child and not filter_known_macro
falsepositives:
    - Legitimate macros that call scripts (document them as filters with an owner)
level: high
Part Meaning
title, id, status, description, references, author, date Metadata. id is a UUID that stays stable across edits; status is experimental, test, stable, deprecated or unsupported
tags ATT&CK tactic (attack.execution) and technique (attack.t1204.002) tags, used for coverage reports
logsource Which events the rule applies to: category (generic: process_creation, network_connection, dns_query, file_event, registry_event, image_load…), product (windows, linux, aws…), service (security, sysmon, cloudtrail…)
detection Named search identifiers (selection_parent, filter_known_macro) and a condition that combines them
falsepositives, level What benign activity can match, and the severity: informational, low, medium, high, critical

Search identifiers and their logic

Inside a search identifier:

  • A map (field: value pairs) means AND across fields: every field must match.
  • A list of values for one field means OR: any value may match.
  • A list of maps means OR between the maps.
  • Values are case-insensitive by default; * and ? are wildcards in plain values.

Value modifiers change how a value is compared: |contains, |startswith, |endswith, |all (all list values must match, turning the list's OR into AND), |re (regular expression), |cidr (address in a network), |base64 and |base64offset (match the Base64 form of a string, for encoded command lines), |windash (also match / and Unicode dash look-alikes for - in Windows command-line switches), and others in the specification. Modifiers chain: CommandLine|contains|all:.

Conditions combine identifiers with and, or, not and parentheses, plus quantifiers: 1 of selection_* (any identifier starting with selection_), all of selection_*, 1 of them, all of them. The common idiom is selection and not filter.

For counting and sequences (thresholds, "N failures then success"), Sigma 2 added correlation rules (types such as event_count, value_count, temporal and temporal_ordered) that reference base rules; support differs between converters, so many teams still write those detections in the SIEM's own language.

Field mapping: from Sigma names to your schema

Sigma rules use generic field names that mostly follow Sysmon's (Image, ParentImage, CommandLine, User). Your SIEM may store the same data as ECS (process.executable, process.parent.executable, process.command_line), as Sentinel's DeviceProcessEvents columns (FolderPath, InitiatingProcessFolderPath, ProcessCommandLine), or as something custom. Processing pipelines in the converter (pySigma, used by sigma-cli) rename fields, add conditions for the log source (for example EventID=1 on the Sysmon channel) and drop unsupported parts. A conversion in your lab looks like:

text
sigma convert -t splunk -p sysmon rules/proc_office_spawns_shell.yml
sigma convert -t lucene -p ecs_windows rules/proc_office_spawns_shell.yml

The program below parses the rule with PyYAML, checks its structure, and applies a small ECS mapping to show the rule in your fields (the evaluation itself is the next lesson).

python · try it yourself
import yaml

RULE = r"""
title: Office Application Spawns a Command Shell or Script Host
id: 3f1c2a9e-5b7d-4e1a-9c2b-6d8e0f4a7b31
status: test
tags: [attack.execution, attack.t1204.002, attack.t1059.001]
logsource: {category: process_creation, product: windows}
detection:
    selection_parent:
        ParentImage|endswith: ['\winword.exe', '\excel.exe', '\powerpnt.exe', '\outlook.exe']
    selection_child:
        Image|endswith: ['\cmd.exe', '\powershell.exe', '\pwsh.exe', '\wscript.exe', '\cscript.exe', '\mshta.exe']
    filter_known_macro:
        CommandLine|contains: 'lab-finance-report.cmd'
    condition: selection_parent and selection_child and not filter_known_macro
level: high
"""
ECS = {"Image": "process.executable", "ParentImage": "process.parent.executable", "CommandLine": "process.command_line"}

rule = yaml.safe_load(RULE)
det = rule["detection"]
missing = [k for k in ("title", "id", "logsource", "detection", "level") if k not in rule]
ids = [k for k in det if k != "condition"]
undefined = [w for w in det["condition"].replace("(", " ").replace(")", " ").split()
             if w not in ("and", "or", "not") and w not in ids]
print("missing fields:", missing or "none", "| identifiers:", ids, "| undefined in condition:", undefined or "none")
print("techniques:", [t.split(".", 1)[1].upper() for t in rule["tags"] if t.startswith("attack.t")])

def ecs_query(name):
    parts = []
    for key, values in det[name].items():
        field, *mods = key.split("|")
        values = values if isinstance(values, list) else [values]
        pattern = {"endswith": "*{}", "startswith": "{}*", "contains": "*{}*"}.get(mods[0] if mods else "", "{}")
        parts.append(f'{ECS[field]}:(' + " OR ".join('"' + pattern.format(v) + '"' for v in values) + ")")
    return " AND ".join(parts)

for name in ids:
    print(f"\n{name}:\n  {ecs_query(name)}")
missing fields: none | identifiers: ['selection_parent', 'selection_child', 'filter_known_macro'] | undefined in condition: none
techniques: ['T1204.002', 'T1059.001']

selection_parent:
  process.parent.executable:("*\winword.exe" OR "*\excel.exe" OR "*\powerpnt.exe" OR "*\outlook.exe")

selection_child:
  process.executable:("*\cmd.exe" OR "*\powershell.exe" OR "*\pwsh.exe" OR "*\wscript.exe" OR "*\cscript.exe" OR "*\mshta.exe")

filter_known_macro:
  process.command_line:("*lab-finance-report.cmd*")

The mapped output is close to what a Lucene/KQL converter produces for Elastic (real converters also escape backslashes and wildcards correctly for the target, which is one reason to use them rather than string templates). Undefined identifiers in a condition are a classic mistake (a typo such as selction_child makes the converter fail or, in hand-written translations, silently drop a clause), so the check belongs in CI.

How Sigma rules are tested and kept correct

  • Validate syntax and metadata with sigma check and the Sigma JSON schema in CI.
  • Convert for every target you deploy to, in CI, so a modifier your backend does not support fails the build instead of production.
  • Run positive and negative fixtures through an evaluator or a test SIEM (Testing Detections).
  • Review the field mapping whenever a log source or parser changes: a correct rule with a wrong mapping never fires.

Pitfalls

  • Assuming the log source exists. A process_creation rule needs Sysmon Event ID 1, EDR data or 4688 with command-line auditing; without it, the rule converts fine and never matches.
  • Over-broad filters. filter: CommandLine|contains: '.cmd' would hide every batch file; filters should be as specific as the benign activity.
  • Trusting community rules blindly. Read the rule, its false positives and its level, and test it on your data before enabling.
  • Case and path differences. Sigma compares case-insensitively, but some backends' default analysers don't; check how \ and wildcards are escaped in your target.

Practice

1. Write a selection for PowerShell command lines containing both `-enc` and `-nop`, whatever the order.

selection: { Image|endswith: '\powershell.exe', CommandLine|contains|all: ['-enc', '-nop'] }. With |windash added before the other modifiers (CommandLine|windash|contains|all) it also matches /enc and /nop.

2. Rewrite the condition with a quantifier so new `selection_*` blocks are included automatically.

condition: all of selection_* and not filter_known_macro (or not 1 of filter_* to allow several filters). Be careful: all of selection_* requires every selection block, 1 of selection_* any of them.

3. Your SIEM stores Sentinel's `DeviceProcessEvents`. Which three columns would the mapping target?

FolderPath (or FileName) for Image, InitiatingProcessFolderPath (or InitiatingProcessFileName) for ParentImage, and ProcessCommandLine for CommandLine. Converters for Microsoft's query languages ship such mappings.

Test yourself

What does Sigma describe?

  1. Network packets
  2. Log detections in a generic YAML format that converters translate into SIEM queries
  3. Malware binaries
  4. Firewall rules

Inside one search identifier, how are a list of values for one field combined?

  1. AND
  2. OR
  3. XOR
  4. They are ignored

What does the logsource section decide?

  1. Where the rule file is stored
  2. Which events the rule applies to (category, product, service)
  3. The alert's colour
  4. The rule's author

Why does a correct Sigma rule sometimes never fire after conversion?

  1. Sigma rules expire
  2. The field mapping or log source does not match how your SIEM stores the data
  3. YAML is too slow
  4. Conditions are random