A threat report lands in your inbox: a new malware family, a few strings found inside its files, a suspicious command line it runs. How do you check whether it is on your systems? You could search by hand. Or you could write a rule once and let your tools search everywhere, every day. That is what YARA and Sigma are for.
YARA describes itself as "the pattern matching swiss knife for malware researchers (and everyone else)". It is a tool aimed at helping researchers identify and classify malware samples, by describing what the files look like inside: text strings, byte sequences and conditions that combine them. Its question is: does this file match what we know about this threat?
Sigma is an open format for detection rules that run against logs. The SigmaHQ project describes Sigma rules as YAML files containing all the information required to detect odd, bad or malicious behaviour in log data, usually in a SIEM. Its question is: did something happen on our systems that looks like this attack?
The power of both is portability. A YARA rule written by one researcher can be run by thousands of others. A Sigma rule written once can be converted into the query language of whichever SIEM you use.
A YARA rule has three main parts: meta (information about the rule), strings (what to look for) and condition (when to match). Here is a safe first rule that detects the EICAR test file, a harmless string that antivirus vendors agreed to treat as a test "virus":
rule EICAR_Test_File
{
meta:
description = "Detects the harmless EICAR antivirus test file"
author = "Cyber Insight"
strings:
$eicar = "EICAR-STANDARD-ANTIVIRUS-TEST-FILE"
condition:
$eicar and filesize < 1KB
}
Save it as eicar.yar and scan a folder with the classic YARA tool (yara eicar.yar C:\Downloads) or with YARA-X (yr scan eicar.yar C:\Downloads). Every file that matches is listed.
Real rules follow the same shape. Analysts pick strings that are distinctive to a malware family, such as unusual text, configuration markers or byte sequences from its code, and combine them in conditions like "any two of these strings, in a Windows executable, under 2MB". The better the strings, the fewer the false matches.
A note on YARA-X. VirusTotal, which maintains YARA, has rewritten it in Rust as YARA-X, aiming to be faster, safer and more user-friendly. The project says YARA-X is mature and stable, and that while the original YARA will still receive bug fixes, future development is focused on YARA-X. New users should start there.
Sigma rules describe a log source and the field values to match. Here is a simple rule for a pattern behind many malware infections: a Microsoft Office application starting PowerShell, which often means a malicious document is running code.
title: Office Application Starting PowerShell
id: 3f6c1d52-8a4e-4b7a-9d0c-2e5f7a1b9c34
status: experimental
description: Detects Word, Excel or PowerPoint launching PowerShell
author: Cyber Insight
logsource:
category: process_creation
product: windows
detection:
selection:
ParentImage|endswith:
- '\WINWORD.EXE'
- '\EXCEL.EXE'
- '\POWERPNT.EXE'
Image|endswith: '\powershell.exe'
condition: selection
falsepositives:
- Legitimate macros or add-ins that use PowerShell
level: high
The logsource says which logs to search: process creation events on Windows, such as Sysmon's Event ID 1 from Tool Spotlight, Episode 03. The detection section defines what to match, and the condition combines selections. The falsepositives and level fields tell analysts how much to trust an alert.
To use it, convert it with sigma-cli, the official command-line tool. For example, after installing it with python -m pip install sigma-cli and adding a backend with sigma plugin install splunk, the command sigma convert -t splunk -p sysmon rule.yml produces a Splunk search. Backends exist for many platforms, including Elasticsearch, Microsoft Sentinel and Grafana Loki.
You do not have to start from scratch. The SigmaHQ repository contains a large, maintained collection of Sigma rules, many tagged with MITRE ATT&CK techniques, and is an excellent way to learn how good rules are written. Many security vendors and researchers publish YARA rules alongside their threat reports, and VirusTotal lets you run YARA rules against its file collection through its hunting features.
A good habit: when you read a threat report, such as one in our Threat of the Week series, check whether it includes YARA or Sigma rules, and try them in your environment.
Writing detection rules sounds like specialist work, and at scale it is. But your first YARA rule and your first Sigma rule are each about a dozen lines. Write the two examples above, test them, then pick one technique from a recent threat report and write a rule for it. That is the moment you stop only reading about threats and start hunting for them.
Cyber Insight | Tool Spotlight · Season 1
Making cybersecurity easier to understand, one issue at a time.
Free and open-source security tools: what they do and where they fall short.
Have a question or a suggestion? Prepare an email below. Feedback is private and is sent only when you press Send in your email app.
Likes and claps are your personal reactions on this device.
You can also email Poorna directly.
Your feedback stays private. Nothing is sent from this page automatically.
I started Cyber Insight because everywhere online people only talk about cybersecurity in technical terms — and most people are left without a proper understanding of how the digital world works. I work in cybersecurity, but I write here for everyone. No jargon. Just clear, honest explanations.