yara-authoring
YARA Rule Authoring
When to Use
- Writing YARA rules to detect malware samples or families
- Creating detection signatures for indicators of compromise (IOCs)
- Scanning files or directories for known threat patterns
- Building threat hunting rules from intelligence reports
- Classifying unknown samples based on behavioral or structural patterns
When NOT to Use
- Dynamic malware analysis (use sandbox environments)
- Network traffic analysis (use Suricata/Snort rules)
- Static analysis of source code (use Semgrep/CodeQL)
Rule Template
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*))
}
String Types
| Type | Syntax | Use Case |
|---|---|---|
| Text | "string" |
ASCII strings |
| Hex | { AA BB CC } |
Byte patterns, shellcode |
| Regex | /pattern/ |
Flexible text matching |
Modifiers
ascii/wide— encodingnocase— case insensitivefullword— word boundary matchingxor— XOR-encoded stringsbase64— base64-encoded strings
Condition Operators
condition:
all of them // All strings match
any of ($a*) // Any string starting with $a
2 of ($s1, $s2, $s3) // At least 2 of listed strings
#s1 > 3 // String $s1 appears more than 3 times
@s1 < 0x100 // String $s1 found before offset 0x100
filesize < 1MB // File size constraint
uint16(0) == 0x5A4D // Magic bytes at offset
Scanning
# Scan a file
yara rule.yar target_file
# Scan directory recursively
yara -r rules/ /path/to/scan/
# Scan with metadata output
yara -m -s rule.yar target_file
# Compile rules for faster repeated scanning
yarac rules/ compiled.yarc
yara -C compiled.yarc /path/to/scan/
Best Practices
- Always include
metawith author, description, date, and reference - Use
filesizeand magic byte checks to limit scope - Prefer multiple weak indicators over one strong indicator
- Test against known samples AND clean files for false positives
- Use
privaterules for helper conditions - Avoid overly broad regex patterns that cause performance issues
- Version control your rules and track detection rates
Resources
- YARA Documentation — https://yara.readthedocs.io/
- YARA Rules Repository — https://github.com/Yara-Rules/rules
- VirusTotal YARA — https://docs.virustotal.com/docs/yara
More from elizaos/eliza
wacli
Send WhatsApp messages to other people or search/sync WhatsApp history via the wacli CLI (not for normal user chats). Use when the user asks to send a WhatsApp message, text someone on WhatsApp, search WhatsApp chat history, sync WhatsApp conversations, backfill message history, or forward a file via WhatsApp to a third party.
27nano-banana-pro
Generate or edit images via Gemini 3 Pro Image (Nano Banana Pro). Use when the user asks to create an image, generate a picture, produce AI-generated artwork, edit a photo, compose multiple images, or upscale an image to higher resolution. Supports text-to-image generation, single-image editing, and multi-image composition using the Gemini API.
27obsidian
Work with Obsidian vaults (plain Markdown notes) and automate via obsidian-cli. Use when the user asks about notes, vault management, PKM, knowledge base organization, wikilinks, or personal knowledge management in Obsidian.
25session-logs
Search and analyze session logs (older/parent conversations) stored as JSONL files using jq and rg. Use when the user asks about prior chats, previous conversations, conversation history, what was said before, session costs, token usage, or tool usage breakdown across past sessions.
24discord
Use when you need to control Discord from Otto via the discord tool: send messages, react, post or upload stickers, upload emojis, run polls, manage threads/pins/search, create/edit/delete channels and categories, fetch permissions or member/role/channel info, set bot presence/activity, or handle moderation actions in Discord DMs or channels.
241password
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
22