3

tl;dr: What would be alternative approaches for attacking an anti-dump design that allocates encrypted blocks of code on the heap and uses a vm to resolve addresses and decrypt before execution?

I'm working on a binary with about 900 pages (4k) of stolen bytes. The binary in .text jumps with a hardcoded address as a parameter that runs through VMcode, generates a value based on a few identifying features (cpuid, threadid, processid), and eventually decrypts the page on the heap and jumps to it in order to execute the stolen functionality. It doesn't shred the bytes or re-encrypt them most likely for performance reasons - future calls jump directly to the destination code.

I have isolated a few blocks of code that decrypt the code itself and jump (haven't quite figured out the key generation yet), and have considered a few approaches:

1.Dump every 4k page allocated(about 900 or so) and append them to the end of the binary at the right address (they won't be allocated in a dumped binary due to real OEP being after the initial packer OEP that sets all this up), and try to trace the vm to manually fix the jumps in the .text section to the decrypted address.

2.Decrypt the pages, strip out garbage instructions (will probably take a while with not the best confidence level), and paste them in-place where they should be in the executable (the bytes that were stolen have its encrypted counterpart in the original location).

3.Try to inject some shared library at the packer OEP, override ntalloc, allocate the memory in a linear fashion accessible from the dll, and log all the decrypted functions; eventually, write some kind of loader that can use the dumped memory as some kind of switchboard that can jump and update the calls in the original binary to jump into the library that would redirect control flow.

4.Some other method I haven't considered.

It seems like they would all work, but the amount of work in any case seems to range from a lot to a ridiculous amount. Are there any other approaches that might be worth exploring?

Thanks!

3
  • Suppose that the unpacking code does not change depending on the input, IMHO you can use some dynamic binary instrumentation tool (e.g. Pin) to isolate the instructions used for unpacking. I have used this approach to deal with a self-modifying code challenge (so it may be less sophisticated than yours). Mar 29, 2016 at 2:04
  • how does it deal with code that touches encrypted memory pages? Perhaps you can access each page in turn and have it decrypt itself? Mar 31, 2016 at 15:47
  • From what I understand, there is a jump to a function that verifies the image, a few items about the current process, thread, the system it's on, and then does some calculation to figure out the address of the encrypted page. It then runs through a loop to decrypt the page itself - haven't figured out exactly how the key is constructed yet. I have run some traces, but it appears that this functionality is performed from a VM. In addition, I haven't found a solution that can properly dump the pages in full, even with proper permissions... it seems like the pages dump but are empty.
    – MADDJAKKAL
    Apr 1, 2016 at 17:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.