samedi 18 avril 2015

Binary-Auditing.com UnpackMe Write-up

While I was checking  binary-auditing.com's package , I found one interesting unpack_me challenge .
So I made up my mind to to give a try as it is recommended by many dudes .

Well , apparently our mission is to unpack the binary and change the message it outputs ("UNREGISTERED") in order to validate the task .



At this point , you can use plenty of tools and olly scripts that dedicated for unpacking purposes such as IMPrec Universal OEPfinder , but I took a different approach and I managed to unpack it manually by taking a deep look at the behaviour of the unpacker .

After loading it in olly , the first CALL is a decryption loop that XORes the first 0x312 bytes starting from 0x0047E340 with 0x62 as a key .Next function  iterates over a range of memory addresses to find the base address of KERNEL32.DLL module .


So , we step out to find another interesting CALL at 0x0047E254 which loops through kernel32.dll memory region and does a manual import of some APIs (LoadLibrary ,IsDebuggerPresent , VirtualAlloc, GetTickCount , CreatThread) that are needed for the unpacker stub.
As we proceed , we will encounter IsDebuggerPresent() and calls to GetTickCount() , it seems that it checks whether the process is  not being debugged otherwise it calls ExitProcess() .  


In function 0x0047E144 , there is something that we need to pay attention to . there are two consecutive calls to VirtualProtect() api that contain instructions like REPE MOVS and SCAS ,STOS .. etc. As expected , this a self-modifying code that changes various opcodes in a .code section . If you look deeper ,you will notice that it destroyes the unpacking stub .


We keep stepping out until we face obfuscated opcodes that reside within the .klizma section , to make readable we click on "remove analysis from module". It turns out that we have long decryption loop that aims to unpack the first part of the binary .  
 The decryption procedure is so long and it does not seem to end as we might have thought . Therefore we have to find a strategy to find out where this loop ends . Since we are dealing with a packer , we are pretty sure that a call to GetProcAdress() api  is going to take place , so let's set a breakpoint on it and press F9 . As expected !! 
  Many procedures that are related to text , image drawing(imagelist_drawEx , GetbitmapBits) have been imported and written to     a memory region where EDI points to .Normally it is building the IAT block of the binary .
 After the binary is unpacked , we search for the string "UNREGISTERED" in the dump , and voilà !!
  

    We set a hardware breakpoint with execution option , and we notice that it is going to be accessed by  REP MOVS [EDI],[ESI] we follow ESI in dump and then change the string to whatever we want it to output . 

  
  

0 commentaires :

Enregistrer un commentaire