

# Instantiate our emulator object emu = PEPyEmu() # Commandline arguments exename = sys.argv # You must set your path to pyemu ("C:\\PyEmu") ("C:\\PyEmu\\lib") from PyEmu import PEPyEmu We are going to be using the standalone PEPyEmu module this time around, so open a new Python file, name it upx_unpacker.py, and punch in the following code. Now that we have an executable that's been packed with UPX, let's utilize PyEmu to unpack and dump the original binary to disk.

All we need to do is let the emulator run through this unpacking routine and detect a JMP instruction that takes EIP out of the UPX1 section, and we should be at the original entry point of the executable. The packer runs its unpacking routine in this section, and when it is finished, it JMPs out of the UPX1 section and into the "real" binary's executable code.

We can see that the UPX1 section contains code, and this is where the UPX packer creates the main unpacking routine. Listing 12-3: Memory layout of a UPX compressed executable. If you load the compressed executable into Immunity Debugger and examine the memory layout (alt-M), you'll see that the executable has a memory map similar to what's shown in Listing 12-3: Do your worst, malware! Bring it on.The UPX packer uses a fairly straightforward method for compressing executables: it re-creates the executable's entry point so that it points to the unpacking routine and adds two custom sections to the binary. One more malware writer's trick dispatched. As a result, not only did Windows' own PE loader fail to parse the resources in the file (Explorer crashed spectacularly), but various security products went into an infinite loop trying to parse the resource tree.īut you can't fool us, malware: Malwarebytes Anti-Malware now handles this correctly, along with a slew of other intentional PE corruptions we've seen before.

#UPX FILE IS MODIFIEDHACKEDPROTECTED WINDOWS#
In computer science terms, it created a directed cyclic graph of resources.Īccording to the Windows PE specification, this is illegal. This cunning piece of malware created a tree with circular references: a tree whose leaves pointed back to its branches. rsrc section is organized hierarchically into a tree data structure, where branches of the tree represent different resource “types” or classifications (like icons, or string resources), and individual leaves represent individual resource elements. This often includes graphics, like icons or bitmaps, but it can be anything, even other binaries. One section, commonly called “.rsrc”, contains arbitrary “resource” data that the executable can reference. One section usually contains the actual executable code, another section contains read-only data, a third contains writeable global variables, another contains API import and export tables. The Windows PE executable binary format is divided into so-called “sections”, which contain different kinds of information about the binary. I saw a cute new trick just the other day when I was analyzing a buggy malware binary that caused our scanner to crash.
#UPX FILE IS MODIFIEDHACKEDPROTECTED CODE#
They are free to write as buggy, as corrupt, as unstable code as they want, and half the time, we take the blame for it! (You can imagine how challenging and frustrating this can be for us.) We have to play (somewhat) by the rules the bad guys don't. Not only does this make us unable to detect and remove the malware, but it also makes us look bad. One of the malware writers' favorite tricks is to try to get our scanner to crash when scanning their malware files. Malwarebytes Anti-Malware has been downloaded 100 million times, is one of the most popular and effective anti-malware cleanup tools out there, and is a threat to the malware industry's bottom line (what, you didn't know there was a malware industry?) As such, it's no surprise that malware is constantly trying to thwart our software. If you read my recent blog post about the development of Malwarebytes Chameleon, you know that we at Malwarebytes have big red 'X's on our chests the bad guys are always out to get us. 24 hours per day, 7 days per week, 365 days per year. Malwarebytes Anti-Malware is under constant attack.
