Skip to content

Lesson 11 of 13 · 24m

Packed and Defended: When the File Lies About Itself

High-entropy .text and a three-import table mean the program only exists in memory — recognize packers, catch the OEP, dump, rebuild imports, and defuse the anti-debug checks.

You open the binary and the ground truth isn't there: .text reads as high-entropy noise, the import table is three entries (LoadLibraryA, GetProcAddress, VirtualProtect), and the longest string is four bytes. The file isn't the program — it's a container. The real code is compressed or encrypted inside, materializes in memory at run time, and doesn't exist in the file at all. The wrong mental model is still "the file is the program." For packed targets, the file is a delivery mechanism; the program only exists while it's running.

Recognizing it

Three tells. Entropy: compressed/encrypted data sits near 7.9 bits per byte — diec (Detect It Easy) reports section entropy, and a .text that looks like randomness is a packed .text. Names: UPX leaves UPX0/UPX1 sections and an UPX! marker; other packers have their own signatures — diec names them. Shape: an import table that only knows how to resolve other imports (GetProcAddress/dlsym plus memory APIs) is a stub that unpacks then hands off.

The easy case and the real case

Stock UPX unpacks itself: upx -d packed restores the original binary, fully analyzable. That works often enough to always try first — real malware still ships in stock UPX because it's free and it defeats dumb scanners.

Modified packers — and everything more serious — make you catch the decompressed image in memory instead. The shape is universal: the unpacking stub decrypts/decompresses into a fresh memory region, then does a tail jmp to the original entry point (OEP). Your job is not to reverse the compressor — it's to stop at the OEP and dump:

  1. In x64dbg: set a breakpoint on the tail jump (the long jump after the decompression loop; often popad; jmp or a jmp rax/jmp <distant VA>), run to it, single-step — you're standing at the OEP of the real program.
  2. Dump the process memory: Scylla (bundled with x64dbg) does "dump + fix imports" — it scans the memory image for the IAT the stub built and rewrites the import directory so the dump analyzes like a normal PE.
  3. On Linux: strace first — an unpacker mprotects or execves a memfd; then gcore <pid> or gdb's dump binary memory while it's stopped at the right moment. rr helps here: record, find the OEP, reverse-continue to it.

The unpacked dump is what you import into Ghidra. Analyze that, not the container.

When the program watches you back

Anti-debugging is a checklist of cheap APIs and one honest mechanism. The catalog:

  • ptrace(PTRACE_TRACEME) on Linux — a process can only be ptraced once; if the program does it to itself, your ptrace-based debugger fails on attach. You'll see it in strace before you ever hit it.
  • IsDebuggerPresent and CheckRemoteDebuggerPresent on Windows — read PEB.BeingDebugged (fs:[0x30]+2 on x86), one byte you can flip.
  • NtQueryInformationProcess with ProcessDebugPort (0x07) — returns nonzero under a debugger.
  • TLS callbacks run before the entry point — the loader calls them before main; anti-debug code lives there so it fires before your breakpoint at WinMain. Check the TLS directory before assuming entry is the start.
  • rdtsc deltas — read the timestamp counter before and after a block; a debugger's single-step inflates it by orders of magnitude. Timing checks don't prove a debugger; they prove the run is slow, which is close enough.

The counters: x64dbg's ScyllaHide plugin hooks the detection APIs at the source so the checks see a clean system. And where a check exists in code, it's a patchable branch like any other — find the IsDebuggerPresent xref, NOP the test.

Know the ceiling

VMProtect-, Themida-, and Denuvo-class protectors don't just compress — they translate selected functions into bytecode for a custom VM embedded in the binary. The "dump at OEP" trick doesn't apply because there is no single OEP for the virtualized code. That's a different discipline with its own tooling; the fundamentals course says: recognize it (diec names VMProtect), report it, and don't start there.

Field notes

  • Always try upx -d first — the five-second test that either solves the problem or tells you it's a modified pack.
  • Run packed samples in a VM or container, never your analysis host — "unpacks in memory" means "executes on your machine."
  • After a memory dump, check imports before analysis: a dump without a rebuilt IAT leaves every external call as an indirect mystery.
  • binwalk is the same idea applied to firmware/carving — "the file is a container" shows up everywhere.

Keep reading

Related articles from the SudoSecurity blog.