Writing Your First Sigma Rule

· Detections · 1 min

Writing Your First Sigma Rule

Sigma is to log detections what YARA is to files: a generic, vendor-neutral way to describe what you want to detect, which you then convert into the query language your SIEM actually speaks.

Why a portable format?

Detections written directly in one query language are stuck there forever. Sigma lets you write once and compile to many backends:

  • One rule, many targets (Splunk, Elastic, Sentinel, …)
  • Reviewable in pull requests like any other code
  • Shareable with the community without leaking your stack

A detection you cannot test, version, and review is a liability, not an asset.

Anatomy of a rule

The core of every rule is a detection block with one or more selections and a condition that combines them:

title: Suspicious whoami Execution After Service Install
status: experimental
logsource:
  product: windows
  category: process_creation
detection:
  selection:
    Image|endswith: '\whoami.exe'
    ParentImage|endswith: '\services.exe'
  condition: selection
level: medium

Field reference

The modifiers after the pipe (|) change how a value is matched:

ModifierMatchesExample
endswithsuffix of the fieldImage|endswith
containssubstring anywhereCommandLine|contains
rea regular expressionCommandLine|re
allevery value in a listCommandLine|contains|all

Once it compiles cleanly and fires on a known-bad sample, commit it. The cheapest detection is the one you never had to debug in production at 3 a.m.