YARA and Sigma
YARA and Sigma are detection rule formats used by defenders to describe malicious patterns and suspicious behavior.
YARA is commonly used for files, malware samples, and memory. Sigma is commonly used for logs and SIEM detections.
Overview
| Tool | Focus | Common Use |
|---|---|---|
| YARA | File and memory pattern matching | Malware detection and hunting |
| Sigma | Log-based detection logic | SIEM and EDR detections |
| Chainsaw | Offline Sigma hunting | Local EVTX investigation |
Simple summary:
YARA
YARA is a pattern-matching engine used to detect and classify files or memory based on strings, byte patterns, and logical conditions.
Common uses:
- Malware classification
- Threat hunting
- Incident response
- Memory scanning
- File triage
- Email attachment scanning
- Malware family detection
- IOC-based hunting
YARA Rule Structure
Basic structure:
rule Rule_Name
{
meta:
author = "Analyst"
description = "Example YARA rule"
strings:
$s1 = "malicious string"
$h1 = { 4D 5A }
condition:
all of them
}
Main sections:
| Section | Purpose |
|---|---|
rule |
Names the rule |
meta |
Documentation and context |
strings |
Text, hex, or regex patterns |
condition |
Logic required to match |
Meta Section
The meta section does not affect matching. It documents the rule.
Common fields:
meta:
author = "Analyst"
description = "Detects suspicious sample"
reference = "Internal case"
date = "2026-05-06"
hash = "..."
Use meta to track:
- Author
- Description
- Version
- Case number
- Malware family
- Hashes
- References
Strings Section
YARA strings define what to search for.
Text string:
Case-insensitive:
Full word:
Wide and ASCII:
Hex bytes:
Regex:
Condition Section
The condition controls when the rule matches.
Examples:
PE Magic Bytes
Windows PE files start with MZ.
YARA condition:
This helps limit a rule to Windows executables.
Example:
Example YARA Rule
rule Suspicious_Invoke_Mimikatz_PE
{
meta:
description = "Detects small PE files containing Invoke-Mimikatz"
author = "Security Fieldbook"
strings:
$s1 = "Invoke-Mimikatz" ascii wide nocase
$s2 = "sekurlsa::logonpasswords" ascii wide nocase
condition:
uint16(0) == 0x5A4D and filesize < 500KB and any of ($s*)
}
YARA Modules
YARA modules extend detection capabilities.
Common modules:
| Module | Purpose |
|---|---|
pe |
Windows PE structure |
math |
Entropy and math functions |
dotnet |
.NET metadata |
hash |
Hashing support |
Example:
import "pe"
rule Suspicious_Imphash
{
condition:
uint16(0) == 0x5A4D and
pe.imphash() == "414bbd566b700ea021cfae3ad8f4d9b9"
}
Entropy
Entropy measures randomness.
High entropy may indicate:
- Packing
- Compression
- Encryption
- Embedded payloads
Entropy range:
Very high entropy:
Example:
import "math"
rule High_Entropy_PE
{
condition:
uint16(0) == 0x5A4D and
math.entropy(0, filesize) > 7.5
}
Imphash
An import hash clusters Windows PE files by imported APIs.
Useful when:
- Malware variants change strings
- Family still uses similar imports
- You need resilient clustering
Example:
import "pe"
rule Detect_By_Imphash
{
condition:
pe.imphash() == "414bbd566b700ea021cfae3ad8f4d9b9"
}
.NET Detection
.NET assemblies include specific metadata.
Common indicator:
Example:
rule DotNet_Assembly_Indicator
{
strings:
$dotnet = "BSJB"
condition:
uint16(0) == 0x5A4D and $dotnet
}
Useful for detecting:
- C# tools
- In-memory assemblies
- Malware written in .NET
- Red-team tools such as Seatbelt/Rubeus-like assemblies
yarGen
yarGen helps generate YARA rules automatically from malware samples.
It extracts strings and filters out common goodware strings.
Example:
Use generated rules as a starting point. Always review and tune them.
YARA Scanning
Scan a file:
Scan a directory recursively:
Show matching strings:
Compile rules:
YARA on Memory
YARA can scan process memory or memory dumps.
Scan a process by PID:
Scan all processes with PowerShell:
Use cases:
- Injected shellcode
- Fileless malware
- Unpacked malware in memory
- Process hollowing
- Suspicious .NET payloads
YARA with Volatility
Volatility can scan memory images with YARA and provide process context.
Inline string search:
Rule file scan:
Why Volatility helps:
YARA with ETW
YARA can be paired with ETW event streams using tools such as SilkETW.
Useful ETW providers:
| Provider | Hunting Value |
|---|---|
| Microsoft-Windows-PowerShell | Script activity |
| Microsoft-Windows-DNS-Client | DNS queries |
| Microsoft-Windows-Kernel-Process | Process activity |
| Microsoft-Windows-Kernel-Network | Network activity |
Example use cases:
- Detect PowerShell strings in script block events
- Match known C2 domains in DNS events
- Detect suspicious command patterns in event streams
YARA Rule Quality
Good YARA rules should:
- Use unique strings
- Avoid common strings
- Combine multiple indicators
- Use file type checks
- Include metadata
- Avoid overly broad conditions
- Be tested against goodware and malware
- Be reviewed before production deployment
Weak rule:
Better rule:
Sigma
Sigma is a generic rule format for log-based detections.
It lets analysts write one detection rule and convert it into SIEM-specific queries.
Common targets:
- Splunk
- Elastic
- Sentinel
- QRadar
- PowerShell
- Logpoint
Sigma Rule Structure
Basic structure:
title: Suspicious LSASS Access
id: 00000000-0000-0000-0000-000000000000
status: experimental
description: Detects suspicious access to LSASS
logsource:
product: windows
category: process_access
detection:
selection:
TargetImage|endswith: '\lsass.exe'
GrantedAccess|endswith:
- '0x1010'
- '0x1410'
condition: selection
level: high
Sigma Sections
| Section | Purpose |
|---|---|
title |
Detection name |
id |
Unique rule ID |
status |
Rule maturity |
description |
What it detects |
references |
Supporting links |
tags |
ATT&CK mappings |
logsource |
Required log data |
detection |
Matching logic |
falsepositives |
Expected benign cases |
level |
Severity |
Sigma Detection Logic
Simple selection:
Multiple values:
Exclusion filter:
detection:
selection:
TargetImage|endswith: '\lsass.exe'
filter_defender:
SourceImage|contains: '\Windows Defender\'
condition: selection and not filter_defender
Optional filters:
Sigma Field Modifiers
| Modifier | Meaning |
|---|---|
contains |
Field contains value |
endswith |
Field ends with value |
startswith |
Field starts with value |
re |
Regex |
all |
All values must match |
base64 |
Base64 encoded form |
windash |
Windows dash variants |
Example:
LSASS Access Sigma Example
title: Suspicious LSASS Process Access
status: experimental
description: Detects suspicious access to LSASS memory
logsource:
product: windows
category: process_access
detection:
selection:
TargetImage|endswith: '\lsass.exe'
GrantedAccess|endswith:
- '0x1010'
- '0x1410'
filter_optional_defender:
SourceImage|contains: '\Windows Defender\'
condition: selection and not 1 of filter_optional_*
falsepositives:
- Security software
- Backup tools
- EDR products
level: high
Password Spraying Sigma Concept
Password spraying can be detected by aggregation.
Idea:
Count distinct target usernames by source workstation.
Alert when one workstation fails authentication for many users.
Relevant event:
Conceptual Sigma logic:
Sigma Rule Development Workflow
- Understand the attack.
- Identify required telemetry.
- Execute or simulate in a lab.
- Review logs.
- Identify unique fields.
- Write a basic selection.
- Add filters for false positives.
- Convert to SIEM query.
- Test on known data.
- Tune before production.
Sigma Conversion
Sigma rules can be converted into SIEM queries using tools such as:
Example concept:
Converted outputs may target:
- Splunk SPL
- Elastic Query DSL
- Microsoft Sentinel KQL
- PowerShell
- QRadar AQL
Chainsaw
Chainsaw is a command-line tool for hunting through Windows Event Logs using Sigma rules.
It is useful for:
- Offline incident response
- Local EVTX analysis
- Rapid triage
- Running Sigma detections without a SIEM
- Searching forensic evidence
Chainsaw Commands
Core commands:
| Command | Purpose |
|---|---|
hunt |
Run rules against logs |
search |
Keyword or regex search |
dump |
Convert artifacts |
lint |
Validate rules |
Basic hunt:
Hunt with JSON output:
Search for keyword:
Search for Event ID:
Chainsaw Mapping Files
Mapping files translate generic Sigma field names into actual Windows Event Log fields.
If a Sigma rule is valid but returns no results, check:
- Correct log source
- Correct Event ID
- Correct field mapping
- Correct EVTX file
- Correct timestamp range
Common problem:
Brute Force Detection with Chainsaw
Use case:
Relevant event:
Example finding:
Abnormal PowerShell Detection with Chainsaw
Use case:
Relevant event:
Rule idea:
If detection fails despite visible evidence, inspect the Chainsaw mapping file.
YARA vs Sigma
| Feature | YARA | Sigma |
|---|---|---|
| Detects | File/memory content | Log events |
| Format | .yar, .yara |
.yml, .yaml |
| Best for | Malware and artifacts | Behavior and telemetry |
| Example target | PE file, memory dump | Windows logs, Sysmon, SIEM |
| Common output | Matched file/process | Alert/search result |
Combined Hunting Workflow
Example incident workflow:
1. Sigma detects suspicious PowerShell.
2. Analyst collects process tree and files.
3. YARA scans dropped files.
4. YARA scans memory for injected payloads.
5. Sigma/Chainsaw hunts EVTX for lateral movement.
6. Findings are documented and converted into detections.
Quick Reference
| Goal | Tool / Command |
|---|---|
| Scan file with YARA | yara rule.yar file.exe |
| Recursive YARA scan | yara -r rule.yar directory/ |
| Show matching strings | yara -s rule.yar file.exe |
| Compile YARA rules | yarac rules.yar rules.yrc |
| Volatility YARA scan | vol.py -f memory.raw yarascan -y rule.yar |
| Inline Volatility search | vol.py -f memory.raw yarascan -U "string" |
| Sigma conversion | sigmac -t splunk rule.yml |
| Chainsaw hunt | chainsaw hunt evtx/ -s sigma/ --mapping map.yml |
| Chainsaw keyword search | chainsaw search mimikatz -i evtx/ |
Notes to Remember
- YARA detects static and memory patterns.
- Sigma detects suspicious log behavior.
- YARA rules need strong strings and careful conditions.
- Sigma rules need correct log sources and field mappings.
- False positive tuning is part of rule development.
- Chainsaw is useful for offline EVTX hunting.
- Use YARA and Sigma together for stronger detection coverage.