← 返回
未分类 中文

Yara Authoring

Write high-quality YARA-X detection rules for malware hunting. Covers atom selection, string optimization, false positive reduction, module usage (PE, ELF, M...
编写高质量的YARA-X恶意软件检测规则,涵盖原子选择、字符串优化、误报减少及模块使用(PE、ELF、M…)
solomonneas
未分类 clawhub v1.0.2 1 版本 100000 Key: 无需
★ 0
Stars
📥 495
下载
💾 0
安装
1
版本
#latest

概述

YARA-X Rule Authoring

Write detection rules that catch malware without drowning in false positives. Based on Trail of Bits methodology.

Core Principles

  1. Strings must generate good atoms — YARA extracts 4-byte subsequences for fast matching. Strings with repeated bytes, common sequences, or under 4 bytes force slow bytecode scans.
  2. Target specific families, not categories — "Detects ransomware" is useless. "Detects LockBit 3.0 config extraction routine" is useful.
  3. Test against goodware — Validate against clean file sets before deployment.
  4. Short-circuit with cheap checks firstfilesize < 10MB and uint16(0) == 0x5A4D before expensive string searches.
  5. Metadata is documentation — Future you needs to know what this catches and why.

YARA-X Basics

YARA-X is the Rust successor to legacy YARA: 5-10x faster, better errors, built-in formatter, stricter validation, new modules (crx, dex).

Install: brew install yara-x / cargo install yara-x

Commands: yr scan, yr check, yr fmt, yr dump

Rule Template

import "pe"

rule FamilyName_Variant_Technique : tag1 tag2 {
    meta:
        author      = "Your Name"
        date        = "2026-02-14"
        description = "Detects [specific behavior] in [malware family]"
        reference   = "https://..."
        tlp         = "TLP:WHITE"
        hash        = ""
        score       = 75  // 0-100 confidence

    strings:
        // Unique strings from the sample
        $api1 = "VirtualAllocEx" ascii
        $api2 = "WriteProcessMemory" ascii
        $str1 = { 48 8B 05 ?? ?? ?? ?? 48 85 C0 }  // hex with wildcards
        $pdb  = /[A-Z]:\\.*\\Release\\.*\.pdb/ nocase

    condition:
        uint16(0) == 0x5A4D and
        filesize < 5MB and
        (2 of ($api*) and $str1) or
        $pdb
}

Naming Convention

Family_Variant_Technique — examples:

  • Emotet_Loader_DocumentMacro
  • CobaltStrike_Beacon_x64
  • Generic_Cryptominer_XMRig

String Selection

Good strings (unique, specific):

  • Mutex names, PDB paths, C2 URLs
  • Unique byte sequences from disassembly
  • Custom encryption constants
  • Uncommon API call sequences

Bad strings (too common, high FP):

  • http://, https://, common API names alone
  • Single common words, short strings (<4 bytes)
  • Strings found in Windows system files

Condition Patterns

// Performance-ordered (cheap → expensive)
condition:
    uint16(0) == 0x5A4D and     // Magic bytes (instant)
    filesize < 10MB and          // Size filter (instant)
    2 of ($unique*) and          // String matching (fast)
    pe.imports("kernel32.dll")   // Module check (slower)

Common magic bytes:

PlatformCheck
-----------------
PE (Windows)uint16(0) == 0x5A4D
ELF (Linux)uint32(0) == 0x464C457F
Mach-O 64-bituint32(0) == 0xFEEDFACF
PDFuint32(0) == 0x25504446
Office/ZIPuint32(0) == 0x504B0304

Performance Rules

  1. Put filesize and magic byte checks FIRST in condition
  2. Never use unbounded regex like /.*/
  3. Avoid for all with complex conditions on large files
  4. Use ascii or wide, not both unless needed
  5. Hex strings with specific bytes > wildcards > regex
  6. Use at for fixed offsets instead of scanning entire file

Testing

# Validate syntax
yr check rules/

# Scan a sample
yr scan rules/my_rule.yar suspicious_file.exe

# Scan directory
yr scan rules/ samples/ --threads 4

# Format rules consistently
yr fmt rules/my_rule.yar

False Positive Reduction

  • Add filesize constraints (malware has typical size ranges)
  • Require multiple string matches (2 of ($str*) not any of)
  • Exclude known good paths/publishers via not conditions
  • Score-based approach: assign confidence scores in metadata, triage by threshold
  • Test against goodware corpus before deployment

Reference

Full methodology, module docs (pe, elf, crx, dex), and migration guide from legacy YARA:

https://github.com/trailofbits/skills/tree/main/plugins/yara-authoring

版本历史

共 1 个版本

  • v1.0.2 当前
    2026-03-30 20:00 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Pentest Commands

solomonneas
{"answer":"必备渗透测试命令参考。快速查询 nmap、Metasploit、hydra、john、nikto、gobuster 及其他安全工具。涵盖……"}
★ 2 📥 1,528

S³ Pentest Commands

solomonneas
当用户请求执行渗透测试命令、使用nmap扫描、metasploit漏洞利用、hydra或john密码破解等网络安全测试任务时,使用本技能。
★ 0 📥 914

Malware Analyst

solomonneas
专业恶意软件分析,用于防御性安全研究。涵盖静态与动态分析、沙箱分类、IOC提取、脱壳及恶意软件家族识别。
★ 0 📥 767