Season 1 Part of Tool Spotlight · Episode 05 of 10
View all 10 episodes →
Tool Spotlight · Episode 05 · YARA · Sigma · Detection Engineering · Threat Hunting · September 13, 2027 · 10 min read

YARA and Sigma Rules: Writing a First Detection

Tool Spotlight · Ep 05 YARA Sigma Detection Engineering Threat Hunting · 10 min read
💬 Feedback
Files
What YARA rules look inside
Text and byte patterns plus conditions, to identify and classify malware
Logs
What Sigma rules search
Written once in YAML, then converted for Splunk, Elastic, Sentinel and more
Free
Both are open source
With large community rule collections to learn from

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.

Tool card What they are: two open rule formats for describing threats: YARA for files, Sigma for logs
Cost: free and open source
YARA runs: as a command-line tool and inside many security products; its Rust rewrite is YARA-X
Sigma runs: wherever you convert it to: Splunk, Elastic, Microsoft Sentinel and other SIEMs
Good for: hunting for known threats, sharing detections, turning threat reports into action
Skill level: intermediate

Two Tools, Two Questions

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.

YARA looks at what a file is. Sigma looks at what a system did. Good defenders use both.

Writing Your First YARA Rule

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.

Writing Your First Sigma Rule

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.

Testing Before You Trust a Rule

  • Test that it fires. Run the rule against something that should match: the EICAR file, or a test document that launches PowerShell in a lab. A rule that never fires might simply be broken.
  • Test that it stays quiet. Run it against a large set of normal files or a week of normal logs. Every match is either a real finding or a false positive to tune out.
  • Start in "alert only" mode. Never let a new rule block or delete anything until you trust it.
  • Record what you learn. Update the falsepositives field and add exclusions for legitimate software, rather than switching the rule off.
  • Version your rules in a Git repository, so changes are reviewed and reversible.

Learn From the Community

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.

Limits to Keep in Mind

  • Rules only find what they describe. Attackers change strings and command lines to evade known rules.
  • Sigma needs the right logs. A process-creation rule is useless if you are not collecting process-creation events.
  • Too broad and they flood you with false positives; too narrow and they miss slight variations.
  • Untested community rules can be noisy or wrong for your environment. Review before deploying.

Final Thoughts

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.

A threat report tells you what happened to someone else. A rule checks whether it is happening to you.

Sources and Further Reading

Cyber Insight | Tool Spotlight · Season 1

Making cybersecurity easier to understand, one issue at a time.

Season 1

Tool Spotlight · All 10 Episodes

Free and open-source security tools: what they do and where they fall short.

01
Wireshark basics for spotting suspicious traffic Episode 01 · Published
02
Have I Been Pwned and breach-monitoring tools Episode 02 · Published
03
Sysmon for endpoint visibility on Windows Episode 03 · Published
04
Nmap for checking your own network exposure Episode 04 · Published
05
YARA and Sigma rules: writing a first detection Episode 05 · Now reading
06
CyberChef for decoding and analysing data Episode 06 · Published
07
VirusTotal: using it well and its limits Episode 07 · Coming soon
08
Process Explorer and Autoruns for finding persistence Episode 08 · Coming soon
09
OWASP ZAP for testing your own web app Episode 09 · Coming soon
10
Wazuh: open-source monitoring for a small network Episode 10 · Coming soon
PS
Poorna Sujampathi Rathnayaka
Writer · Cyber Insight · Digital Literacy

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.