Previously I wrote a post about unpacking ASPack, before I move on to unpacking some of the commonly used protectors(and the uncommon ones), I wanted to mention how to unpack UPX as it is considered one of the easiest packers to unpack.
You can download UPX from its official site at http://upx.sourceforge.net.
Tools we’ll need:
1. PEiD.
2. OllyDbg.
3. OllyDump plugin.
Let’s get started, firstly we should scan our file with PEiD to check it’s actually packed with UPX…
UPX 0.89.6 – 1.02 / 1.05 – 1.24 -> Markus & Laszlo
And it is.
UPX’s entrypoint looks similar to this:
PUSHAD
MOV ESI, Server.00408000
LEA EDI, DWORD PTR DS:[ESI+FFFF9000]
PUSH EDI
OR EBP, FFFFFFFF
JMP SHORT Server.0040BA82
The PUSHAD instruction is of interest to us in this case, it does the following:
PUSHAD – Push All General Purpose Registers.
We can use what is known as the ESP trick to find OEP(Original-Entry-Point)… Step over(F8) the PUSHAD instruction and you’ll notice the ESP register’s contents changes, proceed by following its contents in the dump, set a hardware breakpoint(Size: dword. Type: on access) on followed byte.
Run(F9) until you hit the hardware breakpoint, you should land on a JMP instruction which leads to our OEP, step over it(F8).
You should now be at OEP. The IAT(Import Address Table) is basically intact so there’s no need to launch ImpRec and attempt to rebuild it(Most protectors tend to destroy the IAT to complicate our job).
All that’s left to do is dumping, launch the OllyDump plugin, leave the rebuild imports option on (method 1) and continue dumping the file.
You’ve now unpacked a UPX compressed file, I bet that was easier than you imagined?
Don’t forget to test your dumped file, if you did everything correctly it should execute without problems.
KOrUPt.