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.
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.packedsuffix UPX0The 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/VirtualProtectseveral 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:
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.
- Lower breakpoint: Load the sample, in
UPX1at the end of paragraphpopadThe one after thatjmp/retBreak up, or right.textHardware Access breakpoint under the starting address. - Wait for decompression:F9 release, observe
UPX0From non-executable to content. - ESP law positioning OEP: The tail of the shell must be
popad→push eax→ret/jmp eax. After stoppingdd espWhen reading the stack, the adjacent 4 bytes are usually OEP; for the Hardware Execute breakpoint at this address, F9 hits the OEP. - Confirm OEP: In the executable section of the current module, the instruction is a normal function prologue (
push ebp; mov ebp,esporsub esp,xxx), not a shell stub. - Dump: Scylla → Dump to save, and manually change the OEP to the just-caught RVA.
- 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
- static: The section name is normal, the import table can be parsed, and there is no
UPX0/UPX1Residue - dynamic: Can start normally, no report
0xc000007b(Bitwidth/import error) or0xc0000135(DLL missing) - 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
| Phenomenon | reason | deal with |
|---|---|---|
-d Report modified/hacked | UPX header changed | --force, checksum cannot be repaired |
| Finished taking off 0xc000007b | Bit width does not match / IAT is not corrected | Confirm x86/x64, rerun Scylla |
| The volume increases after taking off the clothes | UPX0 The VirtualSize is written unchanged into the file | PE-bear rearranges section alignment |
| OEP caught in the shell | It's too early to set the breakpoint | exist popad later jmp/ret Break again |
| The import table is all serial numbers | The 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.