Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 37 ยท Detection Rules and Correlation

Sigma Rules: Vendor-Neutral Detections

Learn the Sigma rule format: logsource, detection selections, conditions and modifiers. Write rules in YAML and evaluate them with a small Python engine you can run.

Every SIEM has its own query language, so a rule written for Splunk must be rewritten for Sentinel or Elastic. Sigma is an open, vendor-neutral rule format written in YAML. You write a detection once and a converter (such as sigma-cli or pySigma) translates it into the query language of your platform. Sigma plays the role for logs that Snort rules play for network traffic and YARA rules for files.

The Sigma tools themselves are not available on this site, so the rules below are read-only YAML, and we build a small evaluator in Python to show how the logic works.

Anatomy of a rule

YAML
title: Office Application Spawning a Command Shell
id: 11111111-2222-3333-4444-555555555555   # invented UUID
status: experimental
description: Detects a Microsoft Office program starting cmd or PowerShell, a common initial-access behavior.
author: Your Name
date: 2026-11-12
tags:
  - attack.execution
  - attack.t1059
logsource:
  category: process_creation
  product: windows
detection:
  selection_parent:
    ParentImage|endswith:
      - '\winword.exe'
      - '\excel.exe'
      - '\outlook.exe'
  selection_child:
    Image|endswith:
      - '\cmd.exe'
      - '\powershell.exe'
  condition: selection_parent and selection_child
falsepositives:
  - Legitimate macros that call a shell (document and exclude by path)
level: high
Section Purpose
title, id, status Identity and maturity (experimental, test, stable)
description, author, date Documentation
tags ATT&CK mapping
logsource The kind of data: product, service, category
detection Named selections and a condition combining them
falsepositives What benign activity might match
level informational, low, medium, high, critical

Selections and modifiers

A selection is a set of field and value tests. Fields in one selection are joined with AND; a list of values for one field is joined with OR. Modifiers after a pipe change how the value is compared:

Modifier Meaning
contains Substring
startswith, endswith Prefix or suffix
all Every listed value must match
re Regular expression
cidr IP in network
base64, windash Handle encoded or dash variants

Conditions use and, or, not, 1 of selection_*, all of selection_*, and parentheses.

A tiny Sigma evaluator

Python Evaluate Sigma-like detections in Python

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This mirrors what a converter does: turn each selection into a filter and the condition into a boolean expression.

What a converter produces (read-only)

The same rule converted for Splunk, as an illustration:

TEXT
index=windows (EventCode=1 OR EventCode=4688)
(ParentImage="*\\winword.exe" OR ParentImage="*\\excel.exe" OR ParentImage="*\\outlook.exe")
(Image="*\\cmd.exe" OR Image="*\\powershell.exe")

Field names must match your normalized data. Converters use a processing pipeline to map Sigma field names (ParentImage) to your schema (process.parent.executable).

A second rule: encoded PowerShell

YAML
title: PowerShell With Encoded Command
logsource:
  category: process_creation
  product: windows
detection:
  selection:
    Image|endswith: '\powershell.exe'
    CommandLine|contains:
      - ' -enc '
      - ' -encodedcommand '
  condition: selection
level: medium
falsepositives:
  - Some management tools use encoded commands (exclude by parent process)
Python Test your rule against should-match and should-not-match events

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Good habits

  • Start from a public rule repository (the SigmaHQ project) to learn patterns, then adapt and test them for your data. Review license terms before reusing text.
  • Always fill in falsepositives and level honestly.
  • Tag ATT&CK techniques for reporting.
  • Keep rules in Git and run tests in CI.
  • Rules depend on logging being enabled (for example process command lines); note the prerequisites.

A rule you did not test on your own data is a guess. A converter ensures syntax, not correctness or fit for your environment.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Sigma?

    Sigma rules are written once and converted to many SIEM query languages.
  2. 2. How are multiple fields inside one Sigma selection combined?

    Fields in a selection are ANDed; a list of values for a single field is ORed.
  3. 3. What does the endswith modifier do?

    endswith compares the suffix of a field value.
  4. 4. Why is the falsepositives field important?

    Documenting expected benign matches saves triage time and guides tuning.

Summary

  • Sigma describes detections in YAML (logsource, selections, condition, level) and converts them to your SIEM language.
  • Modifiers such as contains, endswith and re control matching; lists mean OR, fields in a selection mean AND.
  • Map Sigma fields to your own schema with a processing pipeline.
  • Test every rule with positive and negative cases before deployment.

Next: Tuning, False Positives and Rule Quality