Skip to content

hypnguyen1209/offensive-claude / skills/malware-analysis

malware-analysis

Unverified

Use when reverse-engineering or detecting malware — static triage + capa/YARA-X, emulation/DBI/.NET unpacking, dynamic/fileless/Volatility 3 memory analysis, C2 config extraction (Cobalt Strike/CAPE), C2 traffic detection (JA4+, beaconing)

references/yara-detection-engineering.md

View on GitHub
# YARA Detection Engineering

Goal: turn analysis findings into durable, low-false-positive detection signatures — for files, memory,
and at-scale hunting. YARA is the lingua franca; the engine has shifted to **YARA-X** in 2025.

## Theory / mechanism

A good rule targets **stable, discriminating** features — not trivially mutable strings:

- **Code/byte features** > ASCII strings: opcode patterns, decrypt-loop bytes, API-hashing stubs,
  unique constants (XOR/AES keys, magic bytes) survive recompiles and string edits.
- **Structural anchors**: `uint16(0)==0x5A4D` (MZ), section names, imphash/PE module conditions,
  entropy via the `math` module.
- **Threshold logic**: `N of ($s*)` and weighted combinations resist single-string changes and
  reduce false positives.
- **Validate against goodware**: a rule is only as good as its FP rate on a clean corpus.
- **Memory vs disk**: rules that match the *unpacked* payload or decoded config (config table,
  decrypt key) catch families that are packed differently per build — scan memory dumps and unpacked
  output, not just the dropper.

## Modern 2024-2026: YARA-X

**YARA-X 1.0.0** (stable, June 2025) is a Rust rewrite. **YARA 4.x is in maintenance** — new
features land only in YARA-X; VirusTotal runs it in production over billions of files.

Key facts for rule authors:
- **~99% of existing YARA rules run unmodified.** Most rule sets just work.
- **Safety + maintainability**: Rust core, decoupled parser/scanner, official Python/Go/C bindings,
  built-in `yara-x fmt` formatter, and **WASM** compilation (browser/serverless/edge scanning).
- **Performance caveat**: gains aren't uniform — pure simple text/hex patterns can be marginally
  faster in classic YARA's Aho-Corasick; YARA-X wins when rules mix patterns with heavy regex/loops.
  Practical guidance: prefer hex/byte patterns over expensive regex; anchor with `at`/offsets.
- `capa` rules are complementary code-level detections sharing format DNA — pair both.

## Complete working rules & workflow

### A. Generate + validate a family rule

```bash
# auto-extract discriminating strings/imphash from a family folder, filter against goodware,
# emit a YARA-X-compatible rule, then measure TP/FN/FP
python3 scripts/yara_gen.py --family samples/latrodectus/ --name Latrodectus_Loader \
    --goodware /usr/bin --out rules/latrodectus.yar --min-share 0.8

# scan with YARA-X
yara-x scan rules/latrodectus.yar /samples/             # CLI
yara-x fmt rules/latrodectus.yar                        # auto-format/lint
yara-x compile rules/*.yar -o rules.bin && yara-x scan rules.bin /corpus/   # precompile for speed
```

### B. Robust hand-written family rule (YARA-X compatible)

```yara
import "pe"
import "math"

rule Loader_DynResolve_HighEntropy {
    meta:
        author      = "offensive-claude"
        description = "Generic packed loader: tiny imports, dynamic resolution, high-entropy payload section"
        reference   = "static-triage-capa.md"
        yara_x      = "compatible"
    strings:
        $resolve1 = "GetProcAddress" ascii
        $resolve2 = "LoadLibraryA"  ascii
        $alloc    = "VirtualProtect" ascii
        // common API-hashing stub: push imm32 ; call rel32
        $apihash  = { 68 ?? ?? ?? ?? E8 ?? ?? ?? ?? }
    condition:
        uint16(0) == 0x5A4D and
        pe.number_of_imports < 15 and
        all of ($resolve*) and $alloc and
        $apihash and
        // any executable-ish section with packed entropy
        for any s in pe.sections : ( math.entropy(s.raw_data_offset, s.raw_data_size) > 7.0 ) and
        filesize < 3MB
}

rule CobaltStrike_Beacon_Indicators {
    meta:
        description = "Cobalt Strike beacon: encoded config table + default artifacts"
        reference   = "config-c2-extraction.md"
    strings:
        $cfg_v4   = { 2e 2f 2e 2f 2e 2c }            // BeaconType TLV XOR 0x2e
        $cfg_v3   = { 69 68 69 68 69 6b }            // BeaconType TLV XOR 0x69
        $pipe     = "\\\\.\\pipe\\MSSE-" ascii
        $spawn    = "%windir%\\sysnative\\" ascii
    condition:
        any of ($cfg_*) or 2 of ($pipe,$spawn)
}
```

### C. Memory / unpacked-payload rule (scan the decoded artifact)

```bash
# scan a memory image's process dumps and the unpacker output, not just the dropper
yara-x scan rules/family.yar out/dumps/            # auto_unpack.py output
yara-x scan rules/family.yar out/vol_dumps/        # vol windows.vadinfo --dump output
```

## Rule quality checklist

- [ ] Anchored (`uint16(0)==0x5A4D`, offsets, `pe.*`) — not a free-floating string soup.
- [ ] Uses `N of them` thresholds, not a single mutable string.
- [ ] Targets keys/opcodes/structure over UI strings and paths.
- [ ] `filesize` / section bounds to cap cost and FPs.
- [ ] Validated: TP on the family, **0 FP** on a goodware corpus (`yara_gen.py --validate`).
- [ ] `yara-x fmt` clean; precompiled (`yara-x compile`) for production scanning.
- [ ] Carries meta: author, date, reference, hashes.

## Detection (operationalizing rules)

- Deploy precompiled YARA-X across EDR file scanning, mail/web gateways, and memory scanners
  (Volatility `yarascan`, EDR live-memory scans). Run the *same* rules on disk **and** memory so
  packed-on-disk/unpacked-in-memory families are caught at runtime.
- Pair YARA (byte/string) with **capa** (capability) and **JA4X/Suricata** (network) — multi-layer
  detection is far harder to evade than any single signature.
- Track rule efficacy: log TP/FP over time; retire/raise-threshold on noisy rules.

## OPSEC

- Authoring rules is offline and safe. When publishing family rules, avoid leaking sensitive victim
  IOCs or non-public attribution (team-server watermarks, internal hostnames) beyond ROE.
- Red-team relevance: knowing what stable features detection engineers key on (imphash, config
  tables, default pipe names, JA4X) informs which artifacts an operator must randomize — but that
  same knowledge is exactly what hardens the defensive rules here.

## References

- VirusTotal Blog — *YARA-X 1.0.0: The Stable Release and Its Advantages* (June 2025): https://blog.virustotal.com/2025/06/yara-x-100-stable-release-and-its.html
- VirusTotal/yara-x (Rust rewrite, bindings, fmt, WASM): https://github.com/VirusTotal/yara-x
- Andrea Fortuna — *Threat hunting with YARA-X: a practical guide to the new standard* (2026): https://andreafortuna.org/2026/04/22/threat-hunting-yara-x/
- InQuest — awesome-yara (rules/tools corpus): https://github.com/inquest/awesome-yara
- mandiant/capa (code-level capability rules, complementary): https://github.com/mandiant/capa
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall