Skip to content

Lesson 6 of 12 · 25m

Unpacking: Let the Malware Do the Work

The effort ladder from upx -d to debugger breakpoints on memory APIs, catching payloads with pe-sieve, and how to know the dump is actually the payload.

The packer's whole job is to put the real payload in memory and run it. Your job is to be standing there when it does. New analysts burn days reversing a decompression routine; the senior move is to never read the algorithm at all. Set traps on the handful of APIs every unpacker must call, let the stub do its work, and collect the result.

The effort ladder — climb only as far as needed

  1. Known tool: upx -d sample.exe -o sample.unpacked.exe. "Not packed by UPX" while DIE says UPX → tampered section names or stripped UPX! magic; restore them and retry before moving up the ladder.
  2. Sandbox dumps: CAPE captures injected and unpacked payloads automatically — check the payloads tab before opening a debugger. This is the step people skip.
  3. Memory scanners: run the sample in the lab VM and point pe-sieve at the process.
  4. Debugger breakpoints on memory APIs.
  5. Reversing the stub — rare, and usually a sign a step above was skipped.

The pattern every unpacker follows

stub -> VirtualAlloc(NULL, 0x3A000, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE)
     -> decrypt / decompress payload into the buffer     ; you don't care how
     -> VirtualProtect(buf, 0x3A000, PAGE_EXECUTE_READ, &old)
     -> jmp payload OEP                                 ; self-injection
     or CreateProcessW(CREATE_SUSPENDED) -> WriteProcessMemory
        -> SetThreadContext -> ResumeThread              ; hollowing

Two shapes worth naming. Self-injection allocates in its own process, flips the memory executable, and jumps — the payload never touches disk. Hollowing spawns a legitimate process suspended, writes the payload into it, and resumes — so the malicious code runs under explorer.exe's or svchost.exe's good name. Both paths funnel through the same four APIs, which is why the breakpoint set works for both.

The x64dbg recipe

bp VirtualAlloc
bp VirtualProtect
bp WriteProcessMemory
bp ResumeThread
run

At VirtualAlloc, rtr (run to return) and note RAX — the new buffer; follow it in the dump pane and set a hardware write breakpoint (bphws rax, w, 1) to watch it fill until it starts with 4D 5A. At WriteProcessMemory the x64 calling convention puts args in RCX, RDX, R8, R9: RCX is the target handle, RDX the remote address, R8 the buffer, R9 the size. Save it with savedata C:\dump\payload.bin, r8, r9 and stop before ResumeThread — you just caught a hollowing payload without letting it run.

pe-sieve: the lazy (correct) first try

C:\Tools> pe-sieve64.exe /pid 4312 /shellc /imp 1
[*] Scanning: C:\Windows\SysWOW64\explorer.exe
Implanted PE: 1   Implanted shc: 0   Replaced: 0
Dumped modules to: process_4312

pe-sieve finds PEs and shellcode that don't match anything on disk — implants, hollowed images, patched modules — and dumps them realigned, with a scan_report.json explaining each flag. An Implanted PE inside explorer.exe is the hollowing case made concrete.

Is the dump the payload?

Re-run your static triage on the dump: meaningful strings, a rich import table, .text entropy around 6, capa describing malware behaviors instead of packer behaviors. Tiny imports and another high-entropy blob means you've peeled one layer of a multi-stage chain — keep going, and hash every stage separately.

Field notes

  • Multi-stage is normal: loader → shellcode → loader → payload. Hash and label every stage in the case file.
  • Memory dumps sit at virtual offsets — fine for strings, capa, and YARA. For a runnable PE, let pe-sieve unmap it or rebuild imports with Scylla.
  • IsDebuggerPresent, PEB.BeingDebugged, and timing checks will fight you; ScyllaHide defeats most commodity checks.
  • .NET loaders usually end in Assembly.Load(byte[]) — that's a different lesson; native breakpoints won't help you there.
  • Report both hashes: the packed file is what IR blocks on disk, the payload hash is what clusters the family.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.