A packer compresses or encrypts a program's real code and wraps it in a small stub that restores the original at runtime. Packed malware shows almost no strings, a tiny import table, and one or two high-entropy sections; every interesting artifact is hidden until the stub runs. This skill covers recognizing packing, identifying the packer, unpacking the common ones automatically, and manually unpacking the rest so the real payload can be analyzed. Scope: unpack only samples you are authorized to handle, inside an isolated lab VM, during authorized DFIR or malware research. Unpacking is a standard defensive analysis step; never use these techniques to strip protections from software you are not authorized to analyze.
Quick Workflow
- Check the basics: section names, entropy, import count. One high-entropy section plus a dozen imports means packed.
- Run Detect It Easy to name the packer; confirm with PE-bear (section headers, entry point location).
- If it is UPX or another supported packer, unpack automatically and skip to validation.
- If automatic unpacking fails, run the sample under x64dbg, break on the tail jump, and locate the original entry point (OEP).
- Dump the process image at OEP with Scylla and rebuild the import table.
- Validate: the dump should show real strings, a full import table, and sane sections. If not, repeat with a better OEP.
- Send the unpacked payload through static triage and config extraction.
1. Packer indicators
Three quick checks separate packed from merely small:
# Section layout: look for odd names and high entropy
diec sample.exe
Example DIE output shape:
PE32
packer: UPX(5.0.2)[NRV,brute]
entropy: 7.94 (packed)
section(0): UPX0, size 0x4000, entropy 0.12
section(1): UPX1, size 0x2a000, entropy 7.96
section(2): .rsrc, size 0x1000, entropy 4.10
In PE-bear, the tells are: entry point inside the last section instead of
.text, an import table with only LoadLibraryA, GetProcAddress, and
VirtualAlloc, and a raw-to-virtual size mismatch (UPX0 has huge virtual
size, zero raw size). High entropy alone is not proof: compressed resources
and encrypted config blobs also score high. Packer verdict needs at least
two indicators.
2. Automatic unpacking
# UPX: the easy case
upx -d sample.exe -o unpacked.exe
# Confirm it worked
diec unpacked.exe # should now report: compiler: Microsoft Visual C++
strings -n 8 unpacked.exe | wc -l # should jump from ~50 to thousands
Other packers with dedicated unpackers: ASPack (aspackdie), MPRESS (mpress -d), FSG, MEW. Some "unpackers" are actually just stubs that run the packer in reverse; always validate the output instead of trusting the tool's exit code. Keep the original packed file: your YARA rule for the family targets the unpacked payload, but incident responders will encounter the packed form and need a companion rule or a packer note.
3. Entropy analysis for unknown packers
When DIE says "unknown", measure first, guess later:
import math, collections
def section_entropy(data: bytes) -> float:
if not data:
return 0.0
counts = collections.Counter(data)
return -sum(c / len(data) * math.log2(c / len(data)) for c in counts.values())
# Typical readings:
# 7.5 - 8.0 : encrypted or compressed (packed code, encrypted config)
# 6.0 - 7.5 : compressed resources, mixed content
# 4.0 - 6.0 : normal compiled code
# 0.0 - 2.0 : padding, zeroed sections (like UPX0)
Plot entropy per section and per 256-byte block across the file. A sharp cliff from 7.9 to 4.5 inside one section often marks the boundary between the encrypted payload and the stub's own code. A uniformly high-entropy file with a normal import table may be a crypter with API hashing rather than a classic packer; that changes the unpacking plan (resolve the API hashes dynamically instead of hunting OEP).
4. Manual unpacking: finding the OEP
The classic method: let the stub do its work, then steal the result.
- Open the packed sample in x64dbg. The entry point lands in the stub.
- Set a breakpoint on
VirtualAllocor watch for a big memory write; the stub allocates space for the unpacked image. - Step through the decompression loop (a tight loop with
rep movsor XOR patterns is typical). - Watch for the tail jump: an indirect jump (
jmp eax,push addr; ret) to a freshly written memory region. That target is near the OEP. - At the landing point, verify: it looks like real startup code (calls to
GetModuleHandle, stack setup), not more stub.
x64dbg trace shape at the tail jump:
0040A310 jmp eax ; eax = 00401000, freshly unpacked region
00401000 push ebp ; real code begins: standard function prologue
00401001 mov ebp, esp
Shortcut: hardware breakpoint on write to the unpacked region, then run; the break at the first execution of written memory is usually the OEP.
5. Dumping and fixing imports
With execution paused at the OEP:
- In Scylla (x64dbg plugin), set the OEP address (RVA, not VA: subtract the image base).
- Click "IAT Autosearch" then "Get Imports"; review for invalid entries (shown red). Fix by tracing which thunk the stub filled.
- Dump the process and let Scylla rebuild the PE (new import table, fixed section headers).
- Open the dump in PE-bear: the entry point should now point at your OEP and the import table should list real APIs.
Validation checklist: strings count jumped 10x or more, imports include network/file/registry APIs consistent with the sandbox report, DIE now reports a compiler instead of a packer, and the file executes the same behavior in the sandbox as the packed original.
6. When the stub fights back
Stolen-bytes packers (ASProtect, some Themida modes) remove the first bytes of each imported function, so a naive dump crashes. Anti-dump tricks include checksumming their own headers and erasing the PE header in memory. Answers: dump the header from disk and graft it on, use hardware breakpoints instead of software ones (software breakpoints modify code bytes the stub may checksum), and for stolen bytes, trace each broken thunk to its real API and rebuild manually. If the packer is a full virtualizer (VMProtect, Themida VM), manual unpacking becomes a project, not a step: devirtualize only the functions you need (usually the config decoder and the C2 routine) rather than the whole binary.
Edge cases
- Fake OEP: some stubs jump to decoy code first. Verify by checking that imports resolve and strings appear; a decoy OEP gives you another stub.
- Multi-layer packing (UPX inside a custom packer): unpack outside-in, validating each layer; DIE on each intermediate dump tells you what is left.
- .NET packers (ConfuserEx, .NET Reactor): do not use the native OEP method. Dump the decrypted assembly from memory with a .NET dumper (ExtremeDumper, dnSpy memory dump) after the CLR loads it.
- Packers that need arguments or environment: the stub may only unpack when run a certain way. Match the sandbox's invocation (working directory, arguments) in the debugger.
- Dumps that will not run standalone: a dump is for analysis, not execution. If it crashes when run, that is fine as long as static analysis works; fix imports only as far as analysis needs.
- Legitimate packed software: some vendors pack with UPX or MPRESS. Packing alone is not malicious; correlate with behavior before verdicting.
- 64-bit vs 32-bit tooling: Scylla and x64dbg handle both, but plugins and scripts must match the target bitness.
Escalation
- If automatic unpackers and the standard OEP hunt both fail after a solid effort, escalate to a specialist: custom packers can take days, and the case may proceed on sandbox behavior plus config extraction from memory instead.
- If the sample is virtualized (VMProtect/Themida VM), scope the work to devirtualizing only the needed functions; full devirtualization is rarely worth it for triage.
- If unpacking reveals a second packed payload (nested droppers), treat each layer as a new sample: hash it, detonate it, and document the chain.
- If the unpacked payload will not analyze cleanly (broken imports you cannot fix), fall back to dynamic analysis: the sandbox report plus a memory dump of the running payload often gives you the IOCs without a perfect static dump.
Detection and defender view
Packer identification is detection fuel. Write a YARA rule for the stub when the stub is family-specific (many crimeware builders reuse one stub), and a separate rule for the unpacked payload's unique strings; label which is which in the meta. Feed packer names into your triage queue metadata so analysts can sort "known packer, auto-unpacked" from "custom packer, needs hands". For the SOC, a packer alert alone is weak signal; pair it with behavior (the sandbox report) before it becomes a page. Track which packers appear in your environment over time: a sudden new packer across multiple hosts is itself an incident indicator.
Key references
- Detect It Easy (packer/compiler identification): https://github.com/horsicq/Detect-It-Easy
- PE-bear (PE structure viewer): https://github.com/hasherezade/pe-bear
- UPX (packer and unpacker): https://upx.github.io/
- x64dbg documentation: https://x64dbg.com/
- Scylla (import reconstruction): https://github.com/NtQuery/Scylla
- MITRE ATT&CK: T1027.002 (Software Packing), T1027 (Obfuscated Files or Information)
- Practical Malware Analysis (Sikorski and Honig), Chapters 18-19 (packing and unpacking methodology)
See also
packer-analysis: Use it instead when the packed sample must be re-triaged and turned into detection rules after unpacking.
