Skip to main content
A behavior-driven plugin for authoring high-quality YARA-X detection rules, teaching you to think and act like an expert YARA author.

Overview

The YARA Authoring plugin provides expert-level guidance for writing YARA-X detection rules that catch malware without drowning in false positives. It focuses on decision trees, expert heuristics, and production-tested patterns rather than dumping YARA syntax documentation.
YARA-X Focus: This plugin targets YARA-X, the Rust-based successor to legacy YARA. YARA-X powers VirusTotal’s Livehunt/Retrohunt production systems and is 5-10x faster for regex-heavy rules. Legacy YARA (C implementation) is in maintenance mode.
Key capabilities:
  • Decision trees for common judgment calls
  • Expert heuristics from experienced YARA authors
  • Naming conventions (CATEGORY_PLATFORM_FAMILY_DATE format)
  • Performance optimization (atom quality, short-circuit conditions)
  • Testing workflow with goodware corpus validation
  • YARA-X migration guide for converting legacy rules
  • Chrome extension analysis with crx module
  • Android DEX analysis with dex module

Installation

YARA-X CLI

Python Package (for scripts)

Plugin

When to Use

Use this plugin when:
  • Writing new YARA-X rules for malware detection
  • Reviewing existing rules for quality or performance issues
  • Optimizing slow-running rulesets
  • Converting IOCs or threat intel into detection signatures
  • Debugging false positive issues
  • Preparing rules for production deployment
  • Migrating legacy YARA rules to YARA-X
  • Analyzing Chrome extensions (crx module)
  • Analyzing Android apps (dex module)

When NOT to Use

Do NOT use this plugin for:
  • Static analysis requiring disassembly → use Ghidra/IDA skills
  • Dynamic malware analysis → use sandbox analysis skills
  • Network-based detection → use Suricata/Snort skills
  • Memory forensics with Volatility → use memory forensics skills
  • Simple hash-based detection → just use hash lists

Core Principles

Good Atoms

Strings must generate good atoms. YARA extracts 4-byte subsequences for fast matching. Strings with repeated bytes or under 4 bytes force slow verification.

Specific Families

Target specific families, not categories. “Detects ransomware” catches everything and nothing. “Detects LockBit 3.0 config extraction” is precise.

Test Against Goodware

A rule that fires on Windows system files is useless. Validate against VirusTotal’s goodware corpus or your own clean file set.

Short-Circuit First

Put cheap checks first: filesize < 10MB and uint16(0) == 0x5A4D before expensive string searches or module calls.

Essential Toolkit

An expert uses 5 tools. Everything else is noise.

Rule Structure

Every YARA-X rule follows this format:

Naming Convention

Common prefixes:
  • MAL_ - Malware
  • HKTL_ - Hacking tool
  • WEBSHELL_ - Web shell
  • EXPL_ - Exploit
  • SUSP_ - Suspicious (not definitively malicious)
  • GEN_ - Generic detection
Platforms: Win_, Lnx_, Mac_, Android_, CRX_ Example: MAL_Win_Emotet_Loader_Jan25

Required Metadata

Every rule needs these fields:

Platform-Specific Patterns

YARA works on any file type. Adapt patterns to your target:

Windows PE

macOS Mach-O

Good indicators for macOS:
  • Keylogger: CGEventTapCreate, kCGEventKeyDown
  • SSH tunneling: ssh -D, tunnel, socks
  • Persistence: ~/Library/LaunchAgents, /Library/LaunchDaemons
  • Credentials: security find-generic-password, keychain

npm Supply Chain Attacks

Good strings for JavaScript:
  • Ethereum selectors: { 70 a0 82 31 } (transfer)
  • Zero-width steganography: { E2 80 8B E2 80 8C }
  • Obfuscator signatures: _0x, var _0x
  • C2 patterns: domain names, webhook URLs
Bad strings:
  • require, fetch, axios - too common
  • Buffer, crypto - legitimate uses everywhere
  • process.env alone - need specific env var names

Chrome Extensions (crx module)

Red flags: nativeMessaging + downloads, debugger permission, content scripts on <all_urls>

Android DEX

Red flags: Single-letter class names (obfuscation), DexClassLoader reflection, encrypted assets

Decision Trees

Is This String Good Enough?

When to Use “all of” vs “any of”

When to Abandon a Rule Approach

Stop and pivot when:
  • yarGen returns only API names and paths → Pivot to PE structure, entropy, or imphash
  • Can’t find 3 unique strings → Probably packed. Target the unpacked version or detect the packer
  • Rule matches goodware files
    • 1-2 matches = investigate and tighten
    • 3-5 matches = find different indicators
    • 6+ matches = start over
  • Performance is terrible → Split into multiple focused rules or add strict pre-filters
  • Description is hard to write → Rule is too vague. If you can’t explain what it catches, it catches too much

Real-World Example

Here’s a production-quality rule detecting npm supply chain attacks:
Why this works:
  • Function names (runmask, checkethereumw) are unique to the attack
  • Ethereum function selector adds context
  • all of them prevents false positives
  • Small filesize pre-filter improves performance

Expert Heuristics

Gold tier: Mutex names, PDB paths, stack strings (almost always unique)Silver tier: C2 paths, configuration markers, error messagesBronze tier: API sequences, unusual importsGarbage tier: Single API names, common paths, format specifiersIf you need >6 strings, you’re over-fitting.
Never use nocase or wide speculatively — only when you have confirmed evidence the case/encoding varies in samples.
  • nocase doubles atom generation
  • wide doubles string matching
  • Both have real performance costs
“If you don’t have a clear reason for using those modifiers, don’t do it” — Kaspersky Applied YARA
Regex without a 4+ byte literal substring evaluates at every file offset — catastrophic performance.
If you can’t anchor, consider hex pattern with wildcards instead.
Always bound loops with filesize:
Unbounded #a can be thousands in large files — exponential slowdown.

Rationalizations to Reject

When you catch yourself thinking these, stop and reconsider:

Performance Optimization

Quick Wins

  1. Put filesize first — instant check
  2. Avoid nocase — doubles atom generation
  3. Bound regex — use {1,100} not .*
  4. Prefer hex over regex — faster matching

Red Flags

  • Strings less than 4 bytes
  • Unbounded regex (.*)
  • Modules without file-type filter
  • any of with common strings

Condition Ordering

Order conditions for short-circuit evaluation:

Migrating from Legacy YARA

YARA-X has 99% rule compatibility, but enforces stricter validation. Quick migration:
Common fixes:
Use --relaxed-re-syntax only as a diagnostic tool. Fix issues rather than relying on relaxed mode permanently.

Included Scripts

The plugin includes two Python scripts with PEP 723 inline metadata (dependencies auto-resolved by uv run):

yara_lint.py

Validates YARA-X rules for style, metadata, compatibility issues, and anti-patterns:

atom_analyzer.py

Evaluates string quality for efficient atom extraction:

Workflow

1

Gather samples

Multiple samples required. Single-sample rules are brittle.
2

Extract candidates

Run yarGen -m samples/ --excludegood
3

Validate quality

Use decision trees. yarGen needs 80% filtering.
4

Write initial rule

Follow template with proper metadata.
5

Lint and test

Run yr check, yr fmt, linter script.
6

Goodware validation

Test against VirusTotal corpus or local clean files.
7

Deploy

Add to repo with full metadata, monitor for FPs.

Quality Checklist

Before deploying any rule:
  • Name follows {CATEGORY}_{PLATFORM}_{FAMILY}_{VARIANT}_{DATE} format
  • Description starts with “Detects” and explains what/how
  • All required metadata present (author, reference, date)
  • Strings are unique (not API names, common paths, or format strings)
  • All strings have 4+ bytes with good atom potential
  • Base64 modifier only on strings with 3+ characters
  • Regex patterns have escaped { and valid escape sequences
  • Condition starts with cheap checks (filesize, magic bytes)
  • Rule matches all target samples
  • Rule produces zero matches on goodware corpus
  • yr check passes with no errors
  • yr fmt --check passes (consistent formatting)
  • Linter passes with no errors
  • Peer review completed

Additional Resources

Quality YARA Rule Repositories

Guides

Official Documentation

Author