0Pricing
Cyber Security Academy · Lesson

Writing Sigma Rules

Portable detection rule syntax.

Writing Sigma Rules is a free Cyber Security Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cyber Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Sigma Is

Sigma is a generic, vendor-neutral signature format for log-based detections. You write the detection logic once in YAML, then convert it to Splunk SPL, Elastic queries, Sentinel KQL, and many other backends.

Sigma is to log detection what YARA is to file detection: a portable lingua franca. It lets teams share rules publicly and avoid rewriting the same idea per SIEM.

Anatomy of a Rule

A Sigma rule is a YAML document with required and optional sections. The essentials are title, logsource, and detection.

title: Suspicious PowerShell Encoded Command
id: 7e3f3c1a-1f2b-4c3d-9a8b-1234567890ab
status: experimental
logsource:
  category: process_creation
  product: windows
detection:
  selection:
    Image|endswith: '\\powershell.exe'
    CommandLine|contains: '-enc'
  condition: selection
level: high

The logsource Block

The logsource block tells the converter which logs the rule applies to. It does not query data directly; it selects the right field mapping and index during conversion.

Common keys:

  • product — e.g. windows, linux, aws
  • category — e.g. process_creation, network_connection, file_event
  • service — e.g. sysmon, security, sshd

Pick the most specific combination your data supports so the pipeline maps fields correctly.

Selections and Search Identifiers

Inside detection you define one or more named search identifiers (selections). Each is a map of field-to-value criteria. Multiple fields inside one selection are joined with logical AND.

Here both conditions must be true for selection to match.

detection:
  selection:
    EventID: 4688
    NewProcessName|endswith: '\\whoami.exe'
  condition: selection

Field Modifiers

Modifiers refine how a value is matched. They attach to the field name after a pipe.

  • contains — substring match
  • startswith / endswith — anchored match
  • all — every value in a list must be present
  • re — regular expression
  • base64offset|contains — match base64-encoded substrings

Modifiers chain left to right, applied in order.

detection:
  selection:
    CommandLine|contains|all:
      - 'Invoke-WebRequest'
      - 'DownloadString'
  condition: selection

Lists and Maps as OR / AND

Two rules govern logic inside a selection:

  • A list of values under one field is OR — any value matches.
  • A map of multiple fields is AND — all fields must match.

Below, Image matches either binary, and User must also equal SYSTEM.

detection:
  selection:
    Image|endswith:
      - '\\net.exe'
      - '\\net1.exe'
    User: 'SYSTEM'
  condition: selection

The condition Expression

The condition combines your named selections with boolean logic. This is where you express filters and exclusions.

Operators include and, or, not, parentheses, and aggregations like count(). You can also use 1 of selection* / all of selection* to reference groups of identifiers by prefix.

detection:
  selection:
    EventID: 4625
  timeframe: 5m
  condition: selection | count() by SourceIp > 10

Filtering Out Noise

To suppress known-good activity, define a separate identifier and subtract it in the condition with not. This keeps the malicious logic readable and the exclusions explicit.

Here the rule fires on rundll32 spawning a network connection, except for a known legitimate update process.

detection:
  selection:
    Image|endswith: '\\rundll32.exe'
  filter_legit:
    ParentImage|endswith: '\\MicrosoftEdgeUpdate.exe'
  condition: selection and not filter_legit

Metadata for Triage

Beyond logic, good rules carry metadata that helps responders act fast and helps engineers maintain coverage.

  • level — informational, low, medium, high, critical
  • tags — ATT&CK techniques, e.g. attack.t1059.001
  • falsepositives — known benign triggers
  • references — threat reports or docs
  • author and date

These fields cost minutes to write and save hours during an incident.

Correlation Rules

Single-event rules cannot express multi-step attacks. Sigma correlation rules combine multiple base rules over time to catch sequences and patterns.

Supported types include event_count (N matches in a window), value_count (distinct values, e.g. many failed users), and temporal (rule A then rule B). This lets you detect, say, a successful login right after a burst of failures.

name: bruteforce_then_success
correlation:
  type: temporal
  rules: [failed_logins, successful_login]
  group-by: [SourceIp, TargetUser]
  timespan: 10m

Converting to a Backend

With sigma-cli you convert a rule to your target query language. A processing pipeline maps Sigma field names to your real schema.

The output is a ready-to-deploy query you can paste or push via API.

sigma convert -t splunk -p sysmon \
  -f default rule.yml

# Example output (Splunk SPL):
# Image="*\\powershell.exe" CommandLine="*-enc*"

Quick Check

Check your grasp of Sigma detection logic.

Recap

You can now author portable Sigma rules:

  • logsource selects which logs and field mappings apply
  • Selections are named field-value criteria (fields = AND, value lists = OR)
  • Modifiers like contains, endswith, all, re refine matching
  • condition joins selections with and/or/not, filters, and aggregations
  • Separate filter identifiers subtract known-good noise
  • Metadata (level, tags, falsepositives) speeds triage
  • sigma convert compiles the rule to your SIEM backend

Next, you will tie these rules to adversary techniques with MITRE ATT&CK.

Frequently asked questions

Is the “Writing Sigma Rules” lesson free?

Yes — the full text of “Writing Sigma Rules” is free to read here on the web, and the Cyber Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cyber Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “Writing Sigma Rules”?

Portable detection rule syntax. You practise Cyber Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cyber Security Academy?

No prior experience is required. Cyber Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Writing Sigma Rules” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cyber Security Academy lesson?

Yes. Every Cyber Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Detection-as-Code Principles
  2. Writing Sigma Rules
  3. Mapping to MITRE ATT&CK
  4. Testing and Tuning Detections
← Back to Cyber Security Academy