home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / Code Inside / ben_tut22.txt < prev    next >
Encoding:
Text File  |  2001-09-21  |  8.9 KB  |  194 lines

  1.  
  2.               Manually UnPacking of EP_v0.1 
  3.                           -----------------------------
  4.  
  5. --------------------------------------------|
  6. Writer:         Bengaly                     |
  7. Author:         CoDe_InSide                 |
  8. Protection:    None                        |
  9. URL:        http://code.freeservers.com |
  10. Tools:        SoftICE v4.05               |
  11.         Hex-Editor                  |
  12.         Procdump v1.6.2             |
  13. --------------------------------------------|
  14.  
  15. Hello!
  16. Welcome to my 22nd tutorial, today we will talk about Manual Unpacking!
  17.  
  18. What is Unpacking?
  19. Unpacking is a way to get rid of packed program with an encryption, either using an
  20. Unpacker, or manual unpacking the program.
  21. Packing meanings taking an exe files and encrypts it (the PE header) so it will be hard to crack it.
  22.  
  23.  
  24. Let's get started:
  25. ------------------
  26.  
  27. In this essay I will use CoDe_InSide's EP_v0.1 (PE) packer/Encrypter.
  28. So I will encrypt NotePade.exe!
  29. * Some windows user will probably notice that an encrypted file runs slow...(it runs Slow here as well), later u will see that we will dump and change some stuff in the file and it will run smoothly Ok so we got the packed NotePade.exe (don't run it yet, it will be slow ;D , for me at least) Open ProcDump..press "PE EDITOR" button, and load the encrypted NotePade.exe we made.
  30.  
  31. U will see a window with this in formation:
  32.  
  33. Entry Point: 0000D000    <= this is the Virtual Offset
  34. Size of Image: 0000E000
  35. Image Base: 00400000
  36.  
  37. Ok, now that we know the virtual offset (0000D000), click the "Sections" button,
  38. U will see all section Information.
  39. .text / .data / .idata / .rsrc / .reloc / PE (wonder what is this ;D )
  40.  
  41. Ok look under Virtual Offset of section PE, u will see 0000D000, but we must
  42. Know the Raw offset, so look under Raw Offset of section EP, it is 0000D000 too 
  43. Wow we got lucky it's the same offset ;D (some may use different offsets), but here it's the same ;D
  44. Ok, now that we know the Raw Offset.
  45. Why wee need to know the raw offset anyway?
  46. We need to know it, because hex editor don't use Virtual Offset (sICE use virtual offset Or as we call it RVA, real virtual address)
  47. So when we are using hex values (hex editor) we need to know the Raw Offset!
  48.  
  49. So, our Raw Offset = 0000D000 
  50. Open up hex editor (any), and look for D000 
  51. U will see this in Hex-Editor:
  52.  
  53. D000: 50 83 C0 17 8B F0 97 33
  54.  
  55. Now, in order to use sICE to break when we load the program (usually BINT 3), we need to change the 50 -> CC  (CC = int 3)
  56.  
  57. So in hex editor just change:
  58.  
  59. 50
  60.  
  61. To:
  62.  
  63. CC
  64.  
  65. Now it will be like this -> D000: CC 83 C0 17 8B F0 97 33
  66.  
  67. Save the file and exit hexeditor.
  68. Now load sICE (Ctrl+D).
  69. Set a breakpoint: BPINT 3 
  70. Press enter, and exit sICE (Ctrl+D)
  71. Load the encrypted file (notePade.exe), SICE will pop up here: 
  72. ────────────────────────────────────────────────────────────────────────────────
  73. PROT32─
  74. 0177:0040CFFE  INVALID                                                        
  75. 0177:0040D000  INT       3        <= sICE Breaks Here                                           
  76. 0177:0040D001  ADD       EAX,17                                                 
  77. 0177:0040D004  MOV       ESI,EAX                                                
  78. 0177:0040D006  XCHG      EAX,EDI                                                
  79. 0177:0040D007  XOR       EAX,EAX                                                
  80. 0177:0040D009  XOR       ECX,ECX                                                
  81. 0177:0040D00B  MOV       CL,24                                                  
  82. 0177:0040D00D  LODSB                                                          
  83. 0177:0040D00E  XCHG      AL,AH                                             
  84. ────────────────────────────────────────────────────────────────────────────────
  85.  
  86. Now we need to change the "CC" back to "50" (the original value), because if we wont then sICE will exit And there will be an error message...so just press:
  87. E EIP
  88. U will see this:
  89. 0177:0040D000 CC 83 C0 17  P......3.3..$...-  <= We will need to change this HEX value
  90. 0177:0040D010 AC AA 86 C4  .........@...<@.
  91.  
  92. Change CC 83 -> 50 83
  93.  
  94. So it will be like this:
  95. 0177:0040D000 50 83 C0 17
  96.  
  97. Press ALT+D to return to the Command Window,
  98. Ha...much better, now we can trace the code ;D
  99. Trace the code using F10, until here:
  100.  
  101. ──────────────────────────────────────────────────byte──────────────PROT───(0)──
  102. 0177:004010DC 55 8B EC 83 EC 44 56 FF-15 D8 63 40 00 8B F0 8A  .....DV...c@....-
  103. 0177:004010EC 00 3C 22 75 13 46 8A 06-84 C0 74 04 3C 22 75 F5  .<"u.F....t.<"u.
  104. 0177:004010FC 80 3E 22 75 0D 46 EB 0A-3C 20 7E 06 46 80 3E 20  .>"u.F..< ~.F.> 
  105. 0177:0040110C 7F FA 80 3E 00 74 0B 80-3E 20 7F 06 46 80 3E 00  ..>.t..> .F.>.
  106. ─────────────────────────────────────────────────────────────────────────PROT32─
  107. 0177:004010DA  ARPL      [EAX],AX                                              
  108.  ==> 004010DC  JMP       004010DC     <= here is the OEP  (Original Entry Point)               
  109. 0177:004010DE  IN        AL,DX                                                  
  110. 0177:004010DF  SUB       ESP,44                                                 
  111. 0177:004010E2  PUSH      ESI                                                    
  112. 0177:004010E3  CALL      [KERNEL32!GetCommandLineA]                             
  113. 0177:004010E9  MOV       ESI,EAX                                                
  114. 0177:004010EB  MOV       AL,[EAX]                                               
  115. 0177:004010ED  CMP       AL,22                                                 
  116. 0177:004010EF  JNZ       00401104                                           
  117. ────────────────────────────────────────────────────────────────────────────────
  118. How did i know how trace until here?
  119. Well I looked for a value (similar to entry point), but here I found something more Better...I found a jump to 004010DC (note: u need to move some rets ;D 
  120. ) Anyway, so Just write down the OEP "10DC" on paper or something!
  121. Now look up (above the ASM code) u will see this:
  122.  
  123. 004010DC 55 8B (OEP start here), so we will make an infinite loop in this part.
  124. We are going to use the "EBFE" trick! , Do this in sICE:
  125.  
  126. E EIP    [enter]        
  127. EBFE            : Change 558B to EBFE (Don't forget to remember 558B!) 
  128. ALT+D            : To return to the Command Window 
  129.  
  130. So we set a trap on the OEP ;D, now let's clear all breakpoints : BC * 
  131. And get out of sICE.
  132. Now let's open procdump again...now in the TASK window, scroll down and look for
  133. The Directory u have the encrypted file, mine is:
  134.  
  135. C:\mirc\download\notepade.exe
  136.  
  137. Now select the file, right click with mouse and choose: DUMP (FULL)
  138. Save the new dump anywhere u like, chose a name of course ;D (i prefer the name DUMP.EXE ;D) Now again right click on it again and choose: KILL TASK  (press ok after u get a message) Now, the dump we made does not run yet, we need to modify it to make it run...duh! ;D
  139. So click "PE Editor" and choose the new dump file we made.
  140. Now the entry point is still 000D000, so change it to the real OEP: 10DC(remember I told u To write it down ;D )
  141.  
  142. It will be like this now:
  143.  
  144. Entry Point: 00010DC
  145. (OEP "004010DC" <= Image Base "00400000" + "000010DC")
  146.  
  147. Now on the "Apply Changes Method:" choose "To PE Header" <= so we can kick the encryption Code as well (to reduce some exe size ;D )
  148. After choosing "To PE Header" tab, click "SECTIONS" button.
  149. Now click on the section called: "PE" right click and choose "Kill Section"
  150. This will ensure that the encryption code wont be on the dump.exe anymore ;D
  151. Now we will change the Size of Image:
  152. Size of Image = Last Virtual Offset + Last Virtual Size
  153. So because we killed "PE" section, the last section is now ".reloc" (last section) To fix this take NOW the last Section ".reloc" and add the Virtual Offset and Size together.
  154. Right click on .Reloc and choose "edit section" and edit the
  155.  
  156. Offset            = 0000C000  
  157. Virtual Size    = 00001000
  158.  
  159. Size of Image = 0000C000 + 00001000 = 0000D000
  160. Click "CANCEL" button and we back to the Header Info screen,
  161. We see that the "Size Of Image" = 0000E000 <= which is not correct! 
  162. Change "Size Of Image" = 0000E000 -> 0000D000 
  163.  
  164. Press OK to rebuild the structure of dump.exe ;D
  165. Exit procdump.
  166. Try running the file (dump.exe)...what's going on, it's not working...why! >:/
  167. Well it won't work because it runs in a loop that provides form the program from crashing!
  168. Remember: 558B -> EBFE?
  169. So open hex editor again and go to the OEP we found (10DC).
  170. * Sometimes in winHEX u wont find exactly 10DC (don't know why), so go to the nearest offset I.e.: 10E0/10D0 (u will see EBFE there dont worry ;D ).
  171.  
  172. Change back EBFE -> 558B
  173.  
  174. Save the file...
  175. Run Dump.exe...IT WORKS!!!!!!!!...
  176.  
  177. File has been decrypted (Manually unpacked).
  178.  
  179.  
  180. Have fun ;D
  181.  
  182.                   My thanks and gratitude goes to:
  183.                   --------------------------------
  184.  
  185.                      ----CODE_INSIDE----- ;for helping in cracking
  186.                      -----BLAcKgH0sT------;for being good friend :)
  187.                      -------FusS------    ;asm / keygenning helper
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.