Перейти к основному содержимому
Detection Engineering & Portable Rules with Sigma
Урок 9 из 13

Detection Engineering & Portable Rules with Sigma

Design vendor-neutral behavioural detections in Sigma YAML, test modifiers and exclusion filters, and translate rules into target SIEM queries.

Продвинутый 30 мин Blue Team / SOC
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.

Цели обучения

  • Explain how detection engineering turns threat behaviours into version-controlled, testable rules
  • Author a valid Sigma rule with accurate logsource, detection blocks, modifiers and boolean conditions
  • Reduce false positives using structured filter blocks and field-level exclusions
  • Translate portable Sigma rules to target SIEM query languages using processing pipelines

Рекомендуется заранее: SIEM Architecture, Normalization & Correlation RulesAlert Triage, False Positives & Incident EscalationMITRE ATT&CK Mapping, IoCs & Operational Threat Intel

#Why this matters

In earlier lessons you wrote queries directly in Splunk SPL, Elastic KQL and Microsoft Sentinel KQL. Those queries work well inside a single platform, yet security teams rarely stay on one stack forever. An organisation might run Elastic for endpoint telemetry, Splunk in a regional branch, or migrate to Sentinel during a cloud transition. Rewriting hundreds of detections by hand for every platform wastes analyst hours and creates coverage gaps.

Sigma solves this portability problem the same way YARA does for files and Suricata does for network packets: it defines an open, structured YAML format for log-based detections. When you pair Sigma with detection engineering practices -- treating rules like software with version control, peer review and automated validation -- a single rule can be compiled into multiple SIEM backends without losing its underlying logic.

#From ad-hoc queries to detection engineering

An ad-hoc threat hunt query asks a one-off question about historical logs. A production detection rule runs continuously and wakes up an on-call analyst when it fires, so it requires far higher precision.

  1. HypothesisMap attacker behaviour (MITRE ATT&CK)
  2. TelemetryVerify required log fields exist
  3. AuthorWrite portable Sigma YAML with filters
  4. ConvertApply pipeline and compile to SIEM query
  5. ValidateTest against benign and attack logs
  6. TuneSuppress recurring false positives

Before writing a line of YAML, confirm three things:

  1. Behaviour over brittle IoCs: File hashes and IP addresses change in minutes. Target techniques such as suspicious parent-child process chains, encoded command lines or abnormal service creation.
  2. Telemetry availability: A rule checking CommandLine fails silently if Windows process-creation auditing (Event ID 4688) does not include command-line arguments or if Sysmon Event ID 1 is not collected.
  3. Triage context: Every alert needs a clear description, MITRE ATT&CK tags and falsepositives notes so the L1 analyst knows what to verify first.

#Anatomy of a Sigma rule

Every Sigma rule is a YAML document divided into metadata, telemetry scope (logsource) and matching logic (detection).

Section Purpose Common fields
Metadata Identity, ownership and context title, id, status, description, author, date, tags, level
logsource Telemetry type the rule targets category (e.g. process_creation), product (windows, linux), service (security, sshd)
detection Named search blocks and boolean condition selection, filter_*, condition
Triage hints Expected noise and severity falsepositives, level (low, medium, high, critical)

Here is a complete rule detecting certutil.exe abused to download a remote payload on Windows:

yaml
title: Suspicious Certutil Download Activity
id: 6d4e2a10-7b3c-4f8a-9c12-1a2b3c4d5e6f
status: test
description: Detects certutil.exe invoked with URL cache flags to fetch remote files.
references:
  - https://attack.mitre.org/techniques/T1105/
author: CyberSamSU SOC Lab
date: 2026-11-10
tags:
  - attack.command_and_control
  - attack.t1105
logsource:
  category: process_creation
  product: windows
detection:
  selection_img:
    Image|endswith: '\certutil.exe'
  selection_flags:
    CommandLine|contains:
      - 'urlcache'
      - 'verifyctl'
  selection_url:
    CommandLine|contains: 'http'
  filter_local_update:
    CommandLine|contains: 'http://pki.lab.local/'
  condition: all of selection_* and not filter_local_update
falsepositives:
  - Legitimate internal PKI or certificate revocation list checks
level: high

Notice the id field: a UUIDv4 string that stays fixed even if the title changes, allowing SIEM pipelines and Git repositories to track rule revisions cleanly. Inside detection, list items under a single field act as logical OR (urlcache OR verifyctl), whereas multiple fields inside the same block act as logical AND.

#Modifiers and condition logic

Plain string matching in Sigma is case-insensitive by default, which helps across Windows paths, yet attackers routinely alter flag prefixes, encodings and spacing. Field value modifiers appended with a pipe (|) handle these variations cleanly.

Modifier Behaviour Example use
contains Substring match anywhere in field `CommandLine
startswith / endswith Anchored prefix or suffix match `Image
all Requires every listed item to match (AND instead of OR) `CommandLine
windash Matches both - and / before Windows flags `CommandLine
base64offset Generates all three Base64 byte-alignment variants `CommandLine
wide Encodes target string as UTF-16LE before applying next modifier `CommandLine
re Evaluates a regular expression `CommandLine

The condition expression combines selection and filter blocks using and, or, not, parentheses and wildcard selectors such as all of selection_* or 1 of filter_*. Keep filter blocks separate from selection blocks so analysts can add new exclusions without accidentally breaking core detection logic.

#Translating rules with pipelines and sigma-cli

Sigma rules use generic field names (Image, CommandLine, ParentImage) defined by the Sigma taxonomy. Your SIEM might store those fields as process.executable (Elastic ECS) or ProcessCommandLine (Microsoft Sentinel DeviceProcessEvents).

A processing pipeline bridges that gap by mapping generic Sigma fields and log sources to a specific telemetry schema before compilation. Today, sigma-cli (sigma) is the maintained SigmaHQ tool that replaces the older legacy sigmac script, though you will still encounter sigmac in older playbooks.

Checking and converting a Sigma rule in a lab environment
$ sigma check rules/certutil_download.yml
Checked 1 rules: 0 errors, 0 warnings

$ sigma convert -t splunk -p sysmon rules/certutil_download.yml
index=sysmon EventCode=1 Image="*\\certutil.exe" (CommandLine="*urlcache*" OR CommandLine="*verifyctl*") CommandLine="*http*" NOT CommandLine="*http://pki.lab.local/*"

Always review the generated query before pushing it to production. Check whether case sensitivity, wildcard cost or missing index constraints could slow down SIEM searches over 24-hour windows.

#Defending and common mistakes

  • Matching filenames only: Relying solely on Image|endswith: '\powershell.exe' misses renamed binaries (copy powershell.exe helper.exe). Combine OriginalFileName (from PE metadata in Sysmon) with CommandLine patterns where available.
  • Unbounded |re patterns: Complex regular expressions with catastrophic backtracking slow down SIEM backends and fail Sigma linting. Prefer |contains, |startswith and |endswith whenever possible.
  • Mixing legacy sigmac and sigma-cli flags: If an older tutorial references sigmac -c, check sigma list pipelines and sigma convert --help in sigma-cli rather than guessing pipeline names.
  • No validation corpus: A rule that never ran against both benign baseline logs and an Atomic Red Team or lab test trace is an untested hypothesis. Store sample positive and negative JSON log fixtures beside every rule in Git.

#Summary

  • Sigma provides a portable YAML format for log-based detections, separating detection intent from SIEM query syntax.
  • Strong rules combine logsource, selection blocks, value modifiers (|contains, |all, |windash, |base64offset) and narrow filter exclusions.
  • Processing pipelines in sigma-cli (which replaced legacy sigmac) translate generic Sigma fields into platform-specific queries such as Splunk SPL, Elastic KQL or Sentinel KQL.
  • Treating detections as code -- with UUID tracking, MITRE ATT&CK tags and baseline log tests -- keeps false positives low as telemetry changes.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания