home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / E_bliss / eb_tut21.txt < prev    next >
Text File  |  2000-05-25  |  13KB  |  311 lines

  1.             Tutorial Number 21
  2.  
  3. Written by Etenal Bliss
  4. Email: Eternal_Bliss@hotmail.com
  5. Website: http://crackmes.cjb.net
  6.          http://surf.to/crackmes
  7. Date written: 30th May 1999
  8.  
  9. Program Details:
  10. Name: Crackme 2a
  11. Author: n0p3x
  12.  
  13. Tools Used:
  14. W32Dasm
  15. HexEditor
  16.  
  17. Cracking Method:
  18. Code Analysis
  19.  
  20. Viewing Method:
  21. Use Notepad with Word Wrap switched on
  22. Screen Area set to 800 X 600 pixels (Optional)
  23.  
  24. __________________________________________________________________________
  25.  
  26.  
  27.                         About this protection system
  28.  
  29. This CrackMe produces a Nag whenever we run it. There is no other
  30. registration method other than cracking it to remove the Nag.
  31.  
  32. What the author said:
  33. "The previous programs have used message boxes called by the function
  34. 'MessageBoxA'. This program uses an alternative method to display it's nag"
  35.  
  36.  
  37. _________________________________________________________________________
  38.  
  39.  
  40.                 W32Dasm
  41.  
  42. First, disassemble the CrackMe using W32Dasm. You do this by running W32Dasm,
  43. then choose "Disassembler" -> "Open File To Disassemble".
  44.  
  45. Go to the little icon that says "Imp Fa". When your mouse is there, you
  46. will see the word "Imports" popping up. Ok. We will take a look at the imports
  47. to see what functions are used in the CrackMe. Hopefully find the one that
  48. produces the Nag.
  49.  
  50. You will see a few "cw3220.__XXX" functions. These are utilised by the CrackMe
  51. using the cw3220.dll file. They don't concern us.
  52.  
  53. Other functions include:
  54. USER32.DialogboxParamA
  55. USER32.EndDialog
  56. USER32.MessageBoxA
  57.  
  58. Well, MessageBoxA is not used for the Nag. (The author told us that)
  59.  
  60. So, the most probable function will be DialogBoxParamA to produce the nag
  61. and EndDialog to end the Nag...
  62.  
  63. Double click on the USER32.DialogBoxParamA to see where in the codes is
  64. this function used...Do it a few times to make sure that we have covered 
  65. every single location using this function.
  66.  
  67. You will get these locations...
  68. 004010AF, 0040114C, 004014EE
  69.  
  70. I've pasted the codes below...
  71.  
  72. USER32.DialogBoxParamA at 004010AF
  73. =================================================================
  74. * Possible Reference to Dialog: DialogID_0002 
  75.                                   |
  76. :00401098 6A02                    push 00000002
  77. :0040109A FF7508                  push [ebp+08]
  78.  
  79. * Reference To: USER32.EndDialog, Ord:0000h
  80.                                   |
  81. :0040109D E858040000              Call 004014FA
  82. :004010A2 6A00                    push 00000000
  83. :004010A4 68DF104000              push 004010DF
  84. :004010A9 6A00                    push 00000000
  85.  
  86. * Possible Reference to Dialog: DialogID_0001 
  87.                                   |
  88. :004010AB 6A01                    push 00000001
  89. :004010AD 6A00                    push 00000000
  90.  
  91. * Reference To: USER32.DialogBoxParamA, Ord:0000h
  92.                                   |
  93. :004010AF E83A040000              Call 004014EE
  94.  
  95. * Possible Reference to Dialog: DialogID_0001 
  96.                                   |
  97. :004010B4 B801000000              mov eax, 00000001
  98. :004010B9 EB20                    jmp 004010DB
  99. =================================================================
  100.  
  101. USER32.DialogBoxParamA at 0040114C
  102. =================================================================
  103. :0040113B 55                      push ebp
  104. :0040113C 8BEC                    mov ebp, esp
  105. :0040113E 6A00                    push 00000000
  106. :00401140 687C104000              push 0040107C
  107. :00401145 6A00                    push 00000000
  108.  
  109. * Possible Reference to Dialog: DialogID_0002 
  110.                                   |
  111. :00401147 6A02                    push 00000002
  112. :00401149 FF7508                  push [ebp+08]
  113.  
  114. * Reference To: USER32.DialogBoxParamA, Ord:0000h
  115.                                   |
  116. :0040114C E89D030000              Call 004014EE
  117. :00401151 33C0                    xor eax, eax
  118. :00401153 5D                      pop ebp
  119. :00401154 C21000                  ret 0010
  120. =================================================================
  121.  
  122. The last USER32.DialogBoxParamA at 004014EE doesn't concern us. 
  123.  
  124. Looking at these two pieces of codes, you will see "DialogID_0001" 
  125. or "DialodID_0002" just before the DialogBoxParamA function. So, what
  126. are the parameters for this function? We will have to refer to W32 API.
  127. You can get this off the web easily...
  128.  
  129. int DialogBoxParam(
  130.  
  131.     HINSTANCE hInstance,    // handle to application instance
  132.     LPCTSTR lpTemplateName,    // identifies dialog box template
  133.     HWND hWndParent,        // handle to owner window
  134.     DLGPROC lpDialogFunc,    // pointer to dialog box procedure  
  135.     LPARAM dwInitParam         // initialization value
  136. );
  137.  
  138. Ok. You need 5 parameters before the function. I read somewhere that the 
  139. parameters are always "fed" into the memory from back to front.
  140. ie LPARAM dwInitParam will be pushed first and HINSTANCE hInstance will be
  141. pushed last. So, in the disassembled codes, we see DialogID_000x in the 4th
  142. push which means that it is the dialog box template...
  143.  
  144. Now, what is "DialogID_0001" and "DialodID_0002"?? Go all the way up to
  145. the top of the disassembled codes... You will see
  146.  
  147. +++++++++++++++++ DIALOG INFORMATION ++++++++++++++++++
  148.  
  149. Number of Dialogs =    2 (decimal)
  150.  
  151. Name: DialogID_0001, # of Controls=009, Caption:"Crackme 2a - n0p3x", ClassName:""
  152.      001 - ControlID:0002, Control Class:"BUTTON" Control Text:"E&xit" 
  153.      002 - ControlID:0009, Control Class:"BUTTON" Control Text:"A&bout" 
  154.      003 - ControlID:0065, Control Class:"EDIT" Control Text:"Nag Removal                                         The previous programs have" 
  155.      004 - ControlID:0066, Control Class:"BUTTON" Control Text:"-=n0p3x=-" 
  156.      005 - ControlID:FFFF, Control Class:"STATIC" Control Text:"Coded By n0p3x. 10th May 1999." 
  157.      006 - ControlID:FFFF, Control Class:"STATIC" Control Text:"EMAIL: adminno1@yahoo.com" 
  158.      007 - ControlID:FFFF, Control Class:"STATIC" Control Text:"WEB: http://cod3r.cjb.net" 
  159.      008 - ControlID:FFFF, Control Class:"STATIC" Control Text:"If you suceed in killing this nag screen and write a tutorial on it then email" 
  160.      009 - ControlID:FFFF, Control Class:"STATIC" Control Text:"Frame2" 
  161. Name: DialogID_0002, # of Controls=004, Caption:"The deadly NAG!", ClassName:""
  162.      001 - ControlID:FFFF, Control Class:"STATIC" Control Text:"This is a demonstration version of this program." 
  163.      002 - ControlID:0065, Control Class:"BUTTON" Control Text:"Uhh, youv'e made me feel guilty now. Heres all my money." 
  164.      003 - ControlID:0066, Control Class:"BUTTON" Control Text:"Take the program for a test drive before paying." 
  165.      004 - ControlID:FFFF, Control Class:"STATIC" Control Text:"SOFTWARE PIRACY IS ILLEGAL" 
  166. =================================================================
  167.  
  168. Now, if you had run the CrackMe, you will see the Nag with the caption 
  169. "The deadly NAG!". So, the nag is DialogID_0002 and the main program is 0001.
  170.  
  171.  
  172. Remember the "USER32.EndDialog" function we saw in the Imports as well? It
  173. will close the corresponding Dialog depending on which DialogID is pushed as
  174. the parameter... Ok. The basic introduction is over. 
  175. Lets get down to cracking it...
  176.  
  177.  
  178. Looking at the two pieces of codes earlier... I've commented on
  179. what I know... (remember that I am a newbie too)
  180.  
  181. USER32.DialogBoxParamA at 004010AF
  182. =================================================================
  183. * Possible Reference to Dialog: DialogID_0002         <<Nag ID
  184.                                   |
  185. :00401098 6A02                    push 00000002
  186. :0040109A FF7508                  push [ebp+08]
  187.  
  188. * Reference To: USER32.EndDialog, Ord:0000h
  189.                                   |
  190. :0040109D E858040000              Call 004014FA        <<End the Nag!!
  191. :004010A2 6A00                    push 00000000        <<1st parameter of
  192. :004010A4 68DF104000              push 004010DF          USER32.DialogBoxParamA
  193. :004010A9 6A00                    push 00000000          for main prog
  194.  
  195. * Possible Reference to Dialog: DialogID_0001         <<Main Prog ID
  196.                                   |
  197. :004010AB 6A01                    push 00000001
  198. :004010AD 6A00                    push 00000000
  199.  
  200. * Reference To: USER32.DialogBoxParamA, Ord:0000h    <<Show the prog
  201.                                   |
  202. :004010AF E83A040000              Call 004014EE
  203.  
  204. * Possible Reference to Dialog: DialogID_0001 
  205.                                   |
  206. :004010B4 B801000000              mov eax, 00000001
  207. :004010B9 EB20                    jmp 004010DB
  208. =================================================================
  209.  
  210. USER32.DialogBoxParamA at 0040114C
  211. =================================================================
  212. :0040113B 55                      push ebp
  213. :0040113C 8BEC                    mov ebp, esp
  214. :0040113E 6A00                    push 00000000        <<1st parameter of
  215. :00401140 687C104000              push 0040107C          USER32.DialogBoxParamA
  216. :00401145 6A00                    push 00000000          for Nag
  217.  
  218. * Possible Reference to Dialog: DialogID_0002         <<Nag ID
  219.                                   |
  220. :00401147 6A02                    push 00000002
  221. :00401149 FF7508                  push [ebp+08]
  222.  
  223. * Reference To: USER32.DialogBoxParamA, Ord:0000h    <<Show the Nag!!
  224.                                   |
  225. :0040114C E89D030000              Call 004014EE
  226. :00401151 33C0                    xor eax, eax
  227. :00401153 5D                      pop ebp
  228. :00401154 C21000                  ret 0010
  229. =================================================================
  230.  
  231. Well, looking at what I commented, do you understand what we must do?
  232.  
  233. If you are thinking of NOPing the 6 lines from 0040113E to 0040114C, you are
  234. wrong. I tried it. The CrackMe crashes... 8P
  235.  
  236. So, if patching it that way doesn't work, there is one more way. Did you
  237. think about jumping straight to the "Show Main Prog" codes, therefore 
  238. bypassing the NagScreen? 8)
  239.  
  240. Ok. We must start patching at 0040113E so the the CrackMe will jump to
  241. 004010A2. Why 004010A2?? Well, from 00401098 to 0040109D is the codes to
  242. end the Nag... If we were to stop the CrackMe producing a Nag, then we would
  243. not need the End-Nag codes anymore right??? 8)
  244.  
  245. Simple? Now, we will need to find what codes to use to patch it so that the
  246. CrackMe will jump to the Show Main Prog without showing and ending the Nag
  247. Screen...
  248.  
  249. You can use Softice to do it. But because I have not loaded softice and
  250. you still need to break into the CrackMe first before patching in Softice,
  251. I have decided to use W32Dasm instead...
  252. There is a debugger function in W32Dasm too.
  253.  
  254. What you need to do is this:
  255. 1) Go to "Debug", choose "Load Process"
  256. 2) You may get another prompt asking you something. Just click on "Load"
  257. 3) You will then see 3 seperate windows. Don't be afraid. 8P
  258. 4) Go to the right window (the one showing the words "Code Address ..."
  259. 5) Click on "Goto Address"
  260. 6) Fill in the offset which is 0040113E (remember we are jumping FROM here)
  261. 7) You will see the pushes exactly like what is in the disassembled file
  262. 8) Click on "Patch Code"
  263. 9) In the "Enter New Instruction Below" line, type in "jmp 004010A2" without
  264.    quotes. (rememeber we are jumping TO here)
  265. 10) Hit "Enter" key. You will see in the 'Code Patch Listing" the required
  266.     bytes to make the CrackMe jump to 004010A2...
  267. 11) It is E95FFFFFFF
  268. 12) Now, click on "Clear Patch" and answer "Yes" and then click "Close"
  269. 13) Back to the right window, click on "Terminate" because we have finished 
  270.     our job here
  271.  
  272. Back to the main disassembled file, go to the location 0040113E
  273. Look at the bottom of W32Dasm and you will see this:
  274. Line:298 Pg 4 of 12 Code Data @:0040113E @Offset 0000073Eh in File:crackme2a.exe
  275.  
  276. What you need is the Offset which is 0000073E
  277.  
  278. Now, make a copy of the CrackMe and open it with a HexEditor. 
  279. ** You need to open the copy because you will not be able to patch 
  280.    if W32Dasm is using the same file.
  281.  
  282. Using whatever Hexeditor you have, go to the offset 73E. You will see the bytes
  283. as 6A 00 68 7C 10
  284. ** compare it to W32Dasm (they are the same)
  285.  
  286. Change them to E9 5F FF FF FF and save the patched file...
  287.  
  288. Now, run the patched file and see...
  289.  
  290. If you do everything correctly, you will be brought to the main program
  291. without seeing the NagScreen.
  292.  
  293. CrackMe cracked!!
  294.  
  295.  
  296. __________________________________________________________________________
  297.  
  298.  
  299.                              Final Notes
  300.  
  301. This tutorial is dedicated to all the newbies like me.
  302.  
  303. And because I'm a newbie myself, I may have explained certain things wrongly
  304. So, if that is the case, please forgive me. Email me if there is anything 
  305. you are not clear about.
  306.  
  307.  
  308. My thanks and gratitude goes to:-
  309.  
  310. All the writers of Cracks tutorials and CrackMes
  311. and also to all the crackers that have been supporting my site and project forum.