Write the rule once, search anywhere
Sigma is an open format for writing detections on logs, in YAML. A converter turns one Sigma rule into the query language of whichever log search a team uses.
Teams share Sigma rules because a rule written once can run in many places. You write rules for a made-up office's Windows events, in your own lab copy only.
By the end of this lesson
Note
I can write a Sigma rule for process events and convert it into a query.
Key words
| Word | What it means | Example |
|---|---|---|
| Sigma | an open format for log detections, written in YAML | |
| Log source | the kind of log a rule is for | process_creation |
| Selection | a named group of field tests that must all pass | |
| Modifier | a word after a field that changes how it compares | endswith |
| Condition | how the selections combine into a match | |
| Backend | the part that turns a rule into one search language |
The cells students fill in are left blank in this preview.
The one rule
Important
These events are made up for the lab. Search real logs only on systems you look after or have written permission to search. Logs about people's work are personal data, so read only what the job needs.
A Sigma rule says where and what
A Sigma rule has a log source, which kind of log it reads, and a detection. The detection holds named selections and a condition that combines them.
The Run prints a rule for a classic attack: a Word or Excel file that starts PowerShell with an encoded command. Each field test has a modifier after a bar.
Move into the lab's folder
cd ~/detectShown here, not run. Press Start lab to type it into your own lab’s terminal.
Read a Sigma rule
cat sigma/office-powershell.ymlShown here, not run. Press Start lab to type it into your own lab’s terminal.
Worked example: the parts of the rule
| Part | In the rule | What it means |
|---|---|---|
| Log source | process_creation, windows | Read Windows process start events |
| Selection parent | ParentImage|endswith, two values | Started by Word or by Excel |
| Selection child | Image|endswith and CommandLine|contains | PowerShell, with " -enc " in its command |
| Condition | parent and child | Both selections must pass |
| Tags | attack.t1059.001 | The ATT&CK technique it detects |
The cells students fill in are left blank in this preview.
A backend turns the rule into a query
sigma convert uses a backend to turn a rule into one search language. The lab has the SQLite backend, so the rule becomes SQL. Look for endswith becoming LIKE with a % in front, a list becoming OR, and a selection becoming AND.
The second Run converts the rule and runs the SQL on the lab's 41 events. One event matches.
Convert the rule into SQL
sigma convert -t sqlite sigma/office-powershell.ymlShown here, not run. Press Start lab to type it into your own lab’s terminal.
Run the rule on the events
det sigma sigma/office-powershell.ymlShown here, not run. Press Start lab to type it into your own lab’s terminal.
A common mistake
Warning
Many people think Sigma is a program that searches logs. It is a format. A backend converts the rule into the search language of the tool that holds the logs. The same rule becomes SQL here and a different query for another tool.
Test a rule against everything near it
The first Run lists every PowerShell start in the events. There are three. Only one came from Word with -enc. An admin ran -enc from the desktop, and Excel ran a script by name. The rule rightly skipped both.
The second Run tries a looser rule, any run of whoami. It matches the attack and an admin. A filter selection with and not filter would remove the admin.
Every PowerShell start in the events
sqlite3 logs/events.db "SELECT Computer, User, ParentImage, CommandLine FROM logs WHERE Image LIKE '%powershell.exe'"Shown here, not run. Press Start lab to type it into your own lab’s terminal.
A looser rule and its matches
det sigma sigma/whoami.ymlShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try it: how the modifiers compare
value = "C:/Windows/System32/whoami.exe"
print("endswith:", value.lower().endswith("whoami.exe"))
print("contains:", "system32" in value.lower())
print("startswith:", value.lower().startswith("d:/"))
print("equals:", value.lower() == "whoami.exe")
# Sigma compares without caring about capitals. Why use lower() on both sides?