Using AI for malware triage safely: VMs, unpacking and YARA rules
A defensive workflow for triaging a sample with an AI agent — isolation first, strings/capa/FLOSS, unpacking, writing and testing YARA rules, and verifying every claim the model makes against the sample.
· 8 min read

An AI agent is genuinely useful for malware triage. It reads capa output and strings faster than you can scroll, recognizes library code and crypto constants, drafts a YARA rule from a handful of samples, and explains what an obfuscated routine is doing. This is analysis work — understanding a sample so you can detect and defend against it — and it's where models help most without crossing into anything they shouldn't.
Two rules frame everything below. First: isolation before analysis. A malware sample is live, hostile code; the agent's job is to describe it, never to run it outside containment. Second: the model guesses, the sample decides. Every claim — "this is ransomware," "it beacons to this domain," "this is packed with UPX" — is a hypothesis until you've confirmed it against the bytes. A model that names a malware family from a filename is pattern-matching, not analysing.
Step 0: isolation first
Decide where the sample lives before you touch it.
- Static analysis (strings,
capa, disassembly, hashing) doesn't execute the sample, but still do it on a non-production machine, ideally a dedicated VM, with the sample inside an archive until you need it. An AI agent's analysis box — caveira's Docker box, for instance — is fine for static work, but it is not a detonation sandbox: it has tools, not the isolation and monitoring that running malware demands. - Dynamic analysis (actually running the sample) belongs only in a purpose-built, network-contained sandbox VM with snapshots — REMnux and FLARE VM are the standard analysis distros, and CAPE is a common automated sandbox. Never detonate on a host that matters, never on a box with a route to your network, and never because a model suggested it would be "quick to just run it."
Have the agent record the hash and basic facts first, on a copy, and never rename or move the original:
sha256sum ./sample
file ./sample
Keep the model in static-analysis mode unless you've deliberately set up a detonation environment. "Run it and tell me what happens" is the one instruction you don't delegate.
Step 1: cheap static facts
The fast triage pass, all non-executing:
file ./sample
sha256sum ./sample
strings -n 8 ./sample | head -200 # ASCII strings
strings -el -n 8 ./sample | head -200 # UTF-16LE, common on Windows malware
For PE files, structure and indicators:
pefile ./sample # or: python3 -c "import pefile; ..."
die ./sample # Detect It Easy: packer/compiler identification
A useful prompt at this stage:
This is a malware sample I'm triaging statically in an isolated VM. From the strings, imports and DIE output, tell me the likely language/compiler, whether it looks packed and why, and which capabilities the strings hint at. Mark each as confirmed or guessed.
The "confirmed or guessed" tag matters: clear strings are weak evidence (they're often decoys), and a packed sample has almost no useful strings until you unpack it.
Step 2: capabilities with capa and FLOSS
Two Mandiant tools do a lot of the heavy lifting, and models read their output well.
capa matches a sample against a rule set of behaviours and reports capabilities — "encrypt data using RC4," "create a process," "persist via registry run key" — mapped to MITRE ATT&CK:
capa ./sample # add -vv for the evidence behind each match
FLOSS recovers strings that plain strings misses — stack strings, tightly-encoded strings, and strings decoded at runtime — which is often where the C2 domains and keys hide:
floss ./sample
Feed both to the agent and ask it to summarize the capabilities and cross-reference them with the strings. This is where it shines: turning pages of capa -vv evidence into "this looks like a downloader that pulls a second stage over HTTP and persists via a run key." Then verify the specifics — an ATT&CK technique capa reports is backed by the -vv evidence; make the model point at it.
Step 3: unpacking
If DIE or the entropy and import profile say the sample is packed, you analyse the packer's output, not the packer. For UPX — the common, honest case — unpacking is a documented operation:
upx -d ./sample -o ./sample.unpacked # only works on genuine UPX, not tampered variants
Many samples use custom or modified packers where upx -d fails. Those are unpacked dynamically: run under a monitored debugger in the sandbox until the real code is in memory, then dump it — work for your contained VM, not the agent's static box. A model can explain the general approach for a given packer and help you script a dumper, but the actual unpacking happens in isolation, and the dumped payload goes back through steps 1–2 as if it were a fresh sample (because it is).
Don't let the model declare a sample "unpacked" because an entropy number dropped. Confirm by re-running capa/strings on the output: real code has real imports and readable strings; a bad dump doesn't.
Step 4: writing a YARA rule
Once you understand the sample, a YARA rule turns that understanding into detection. (VirusTotal's newer YARA-X is a drop-in for most rules and the direction the project is heading.) Models are good at drafting rules — and good at drafting overfit ones, which is the whole risk.
Ask for a rule built on durable traits, not incidental bytes:
Draft a YARA rule for this family. Use the decoded C2 strings from FLOSS and the distinctive code constants, not the compile timestamp or the sample's hash. Add a condition requiring several strings so one coincidence doesn't match. Comment why each string was chosen.
A reasonable shape:
rule Downloader_ExampleFamily {
meta:
author = "you"
description = "Second-stage downloader, static-only traits"
reference = "<sha256 of the samples it was built from>"
strings:
$ua = "Mozilla/4.0 (compatible; MSIE ...)" ascii // distinctive hardcoded UA
$c2 = "/gate.php" ascii // from FLOSS-decoded strings
$k = { 8B 45 FC 33 45 F8 } // small decrypt-loop constant
condition:
uint16(0) == 0x5A4D and 2 of them
}
Then test it like a detection engineer, because the model can't:
yara -r rule.yar ./samples/ # must hit the family samples
yara -r rule.yar /usr/bin/ # must NOT hit clean files — false positives here are the whole game
A rule that matches your one sample is worthless; a rule that matches your one sample and Notepad is worse. The model will confidently hand you either. Only the test against a corpus of goodware and other samples tells you which you've got. Require the uint16(0) == 0x5A4D (MZ) anchor and N of them so a single lucky string can't fire the rule.
Verifying the model's claims
The through-line of all four steps: a non-refusing model is not a correct model, and malware analysis punishes confident wrongness. Build these into your instructions:
- Family and behaviour claims cite evidence — a
capa -vvmatch, a FLOSS-decoded string, a disassembled routine — not vibes from a filename or a string that could be a decoy. - "Packed," "unpacked," "encrypted" are claims to confirm by re-running the tools on the output, not states the model announces.
- YARA rules are tested against goodware and siblings before you trust them, every time.
- Nothing executes outside the sandbox. If the model proposes running the sample, that's a decision for you and your contained VM, never a step the agent takes on its own.
Used this way — isolation first, tools over guesses, every claim checked — an agent makes triage dramatically faster without ever becoming the thing that detonates the sample or ships an overfit rule. For the deeper static side when a sample needs real reversing, see the Ghidra/IDA/radare2 workflow.