Write and test YARA rules for malware detection and threat hunting. Use when creating YARA signatures, detecting malware families, scanning files or memory for indicators of compromise, or building detection rules for threat intelligence.
rule MalwareFamily_Variant : tag1 tag2 {
meta:
author = "analyst"
description = "Detects MalwareFamily variant based on unique strings"
date = "2024-01-01"
reference = "https://example.com/report"
hash = "abc123..."
severity = "high"
strings:
$s1 = "unique_malware_string" ascii
$s2 = { 4D 5A 90 00 03 00 } // hex pattern
$s3 = /https?:\/\/[a-z0-9]+\.evil\.com/ nocase // regex
condition:
uint16(0) == 0x5A4D and // MZ header (PE file)
filesize < 5MB and
(2 of ($s*))
}
| Type | Syntax | Use Case |
|---|---|---|
| Text | "string" | ASCII strings |
| Hex | { AA BB CC } | Byte patterns, shellcode |
| Regex | /pattern/ | Flexible text matching |
ascii / wide — encodingnocase — case insensitivefullword — word boundary matchingxor — XOR-encoded stringsbase64 — base64-encoded strings