UPX shelling practice: from feature recognition to IAT reconstruction (including ESP law manual shelling process)

The identification characteristics of UPX shell, upx -d one-click unpacking and magic shelling manual unpacking process, including OEP positioning, IAT reconstruction and result verification.

UPX shell processing notes for PE samples: one-click removal from the command line, manual removal from the magic shell, and IAT repair and verification after removal.

1. First confirm whether it is UPX

Just don't come up upx -d, do three things first: look at the section name, look at the entry point, and look at the import table.

bash
python -c "import pefile,sys; pe=pefile.PE(sys.argv[1]); [print(s.Name.rstrip(b'\x00').decode(errors='replace'), hex(s.VirtualAddress), hex(s.Misc_VirtualSize), round(s.get_entropy(),2)) for s in pe.sections]" sample.exe

Typical features:

  • Section name UPX0 / UPX1, sometimes with .packed suffix
  • UPX0 The VirtualSize is much larger than the SizeOfRawData (the space decompressed at runtime)
  • EP falls in the last non-empty section instead of .text
  • The import table remains LoadLibraryA / GetProcAddress / VirtualProtect several items
  • The overall entropy value is above 7.5

upx -l sample.exe Being able to report the unpacked version (such as upx 3.96) is the key to 1:1 unpacking later.

2. One-click removal: upx -d

The version above is just one line:

bash
upx -d sample.exe -o sample_unpacked.exe

Version mismatch will lead to two types of pitfalls:

1. CantUnpackException: file is modified/hacked/protected

The verification field in the UPX header has been modified (people who modify the shell often modify it conveniently) UPX! magic number or patch checksum). Processing order: first upx -d --force;If still fails, position UPX! Magic number, recalculate the checksum according to the p_info structure, or set this field to 0 before running --force。

2. Prompt that compressed data is damaged

Most of them are processed twice (the small loader then applies UPX).-d Always failed, just go to the third quarter and lose your hand.

upx -d It is only responsible for restoration, not repairing the PE header. Please review it after removing it: the section name returns to .text/.rdata/.data/.rsrc, EP falls back to the code segment, and the import table is restored to dozens or hundreds of items.

3. Hands off: x64dbg + ESP law

Suitable for magic modification,-d A variant of denial. The core is to let the shell decompress itself and capture the scene the moment it returns control.

  1. Lower breakpoint: Load the sample, in UPX1 at the end of paragraph popad The one after that jmp/ret Break up, or right .text Hardware Access breakpoint under the starting address.
  2. Wait for decompression:F9 release, observe UPX0 From non-executable to content.
  3. ESP law positioning OEP: The tail of the shell must be popad → push eax → ret/jmp eax. After stopping dd esp When reading the stack, the adjacent 4 bytes are usually OEP; for the Hardware Execute breakpoint at this address, F9 hits the OEP.
  4. Confirm OEP: In the executable section of the current module, the instruction is a normal function prologue (push ebp; mov ebp,esp or sub esp,xxx), not a shell stub.
  5. Dump: Scylla → Dump to save, and manually change the OEP to the just-caught RVA.
  6. Take IAT:Scylla → IAT Autosearch, if the recognition is not complete, cut it with Get Imports, repair Invalid / Cut thunk one by one, and finally Fix Dump.

4. Three levels of verification

  1. static: The section name is normal, the import table can be parsed, and there is no UPX0/UPX1 Residue
  2. dynamic: Can start normally, no report 0xc000007b(Bitwidth/import error) or 0xc0000135(DLL missing)
  3. Behavior: Compare the key paths (registry, network, file writing) with the original sample to confirm that the logic is not damaged.

5. Quick check on common pitfalls

Phenomenonreasondeal with
-d Report modified/hackedUPX header changed--force, checksum cannot be repaired
Finished taking off 0xc000007bBit width does not match / IAT is not correctedConfirm x86/x64, rerun Scylla
The volume increases after taking off the clothesUPX0 The VirtualSize is written unchanged into the filePE-bear rearranges section alignment
OEP caught in the shellIt's too early to set the breakpointexist popad later jmp/ret Break again
The import table is all serial numbersThe original samples are imported according to serial numbers.Keep ordinal in Scylla, don’t force the name change

Tool list

upx(same version as shell), x64dbg + Scylla, PE-bear, Python + pefile.


The above only focuses on the structure and restoration of the Packer itself, and does not involve any business logic of the protected program.

There are no messages yet. please Log in or Register an account Start this discussion.