writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
yara-rule-authoringGuides authoring, review, optimization, and false-positive debugging of YARA-X detection rules for malware identification across PE, script, npm, Office, Chrome extensions (crx module), and Android DEX (dex module). Covers string and atom quality, condition short-circuiting, legacy YARA migration, yarGen/FLOSS workflows, goodware validation, and production …
Independent GitHub snapshot · Automated classification · Original documentation governs
Write YARA-X rules that catch the intended family without drowning analysts in false positives.
Target runtime: YARA-X (Rust successor to legacy YARA). Install:
brew install yara-xorcargo install yara-x. Essential CLI:yr check,yr scan,yr fmt,yr dump.
any of / all of logiccrx) or Android DEX (dex) module rulesreverse-engineerdigital-forensics-analystcybersecurity, compliance-engineerdevsecopsai-redteam| Need | Skill |
|---|---|
| Security program, IR strategy, detection philosophy | cybersecurity |
| SIEM/EDR rules, logging, control implementation | information-security-engineer |
| Audit evidence, control mapping, CCM | compliance-engineer |
| Pipeline gates, artifact scanning, SBOM | devsecops |
| Binary RE, unpacking, patch diff | reverse-engineer |
| SOC alert triage and detection tuning (non-YARA) | defensive-security-analyst, soc-analyst |
| Proactive threat hunts and ATT&CK campaigns | threat-hunter |
| CTI briefs, IOC/TTP production | cti-analyst |
| Adversarial AI / prompt injection testing | ai-redteam |
| Disk imaging and forensic reports | digital-forensics-analyst |
filesize → magic bytes → strings → modules.| Tool | Purpose |
|---|---|
| yarGen | Candidate strings from samples (--excludegood); always yr check output |
| FLOSS | Obfuscated/stack strings when yarGen fails |
| yr | yr check, yr scan -s, yr fmt, yr dump -m pe|crx|dex |
| YARA-CI / VT retrohunt | Goodware corpus testing before deploy |
import "crx" / import "dex"See references/yara_x_scope_and_tooling.md for install, CLI workflow, and migration.
C:\Windows\, format strings, require/fetch aloneSee references/string_selection_and_atoms.md for decision trees and modifiers.
rule MAL_Win_Example_Loader_Jan26
{
meta:
description = "Detects Example loader via unique mutex and config path"
author = "Team <team@example.com>"
reference = "https://example.com/analysis"
date = "2026-01-15"
strings:
$mutex = "Global\\ExampleMutex" ascii wide
$cfg = "/api/beacon/check" ascii
condition:
filesize < 10MB and
uint16(0) == 0x5A4D and
all of ($mutex, $cfg)
}
Condition order: filesize → magic bytes → string matches → module calls (pe, crx, dex).
See references/conditions_and_performance.md for atom theory, regex bounds, and loops.
yr check rule.yar && yr fmt -w rule.yar
yr scan -s rule.yar malware_samples/ # must match all targets
yr scan -c rule.yar goodware_corpus/ # must be zero
FP flow: yr scan -s on false positive → identify matching string → tighten, exclude vendor, or pivot to structure.
See references/testing_goodware_and_fp_debugging.md for corpus selection and investigation.
import "crx" — permissions, permhash() (v1.11.0+). Always crx.is_crx first.import "dex" — dex.contains_class(), contains_method(), contains_string(). API differs from legacy YARA dex module.See references/platform_modules_pe_crx_dex.md.
{CATEGORY}_{PLATFORM}_{FAMILY}_{VARIANT}_{DATE} (e.g. MAL_Win_Emotet_Loader_Jan26)See references/style_metadata_and_deployment.md.
< 4 bytes? → reject
Repeated bytes (0000, 9090)? → reject
API name or common path? → reject
Unique to family? → use
Common across malware? → combine with family-specific marker
any of vs all ofany of ($a*)all of ($a*)all of ($core_*) and any of ($variant_*)Production lesson: any of ($network_*) with fetch, axios, http matches most web apps — require credential path and exfil destination and network call.
Use yr dump -m pe for sections, imports, imphash, resources; math.entropy() on sections; packer signatures. If nothing unique remains, YARA alone may not be the right control.
yr check --relaxed-re-syntax rules/ # diagnostic only
yr check rules/ # fix until clean
Common fixes: escape \{ in regex; base64 strings need 3+ chars; @a[-1] → @a[#a - 1]; remove duplicate modifiers.
| Thought | Reality |
|---|---|
| "yarGen gave me these strings" | yarGen suggests; you validate each string |
| "It works on 10 samples" | Test goodware corpus before deploy |
| "I'll tighten after FPs" | FPs burn trust — write tight rules upfront |
| "This API name is malicious" | Legitimate software uses the same APIs |
| "any of them is fine" | Common strings + any = FP flood |
{CATEGORY}_{PLATFORM}_{FAMILY}_{VARIANT}_{DATE}.*)filesize and magic bytes before modulesyr check and yr fmt --check pass| Topic | Reference |
|---|---|
| YARA-X install, CLI, migration, toolkit | references/yara_x_scope_and_tooling.md |
| String quality, types, modifiers | references/string_selection_and_atoms.md |
| Atoms, condition order, regex, loops | references/conditions_and_performance.md |
| PE, macOS, JS, crx, dex patterns | references/platform_modules_pe_crx_dex.md |
| Goodware testing, FP debugging | references/testing_goodware_and_fp_debugging.md |
| Naming, metadata, deployment | references/style_metadata_and_deployment.md |