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

  1.  
  2.                   Dead listening/Patching Tutorial 
  3.                               ================================
  4.  
  5. |----------------------------------------------------------|
  6. |Basic Info:                                               |
  7. |----------------------------------------------------------|
  8. |Writer:        Bengaly                                    |
  9. |date:          12/7/01                                    |
  10. |Author:        HilgraEve's HyperTerminal 6.1              |
  11. |Protection:    Register Code                              |
  12. |URL: ftp://ftp.download.com/pub/win95/utilities/htpe6.exe |
  13. |Tools:                                                   |
  14. |        Hex-Editor (Hview)                         |
  15. |        W32DASM                                    |
  16. |               SoftIce  3.x+                              |
  17. |Level:                                                    |
  18. |                                                          |
  19. | Beginner [ X+ ] Medium [   ] Advanced [   ]              |
  20. |----------------------------------------------------------|
  21.  
  22. Hello !
  23. Welcome to my 25th tutorial, today we will talk about Patching and dead listening.
  24. alittle hard to understand, and easy to patch ;P...
  25.  
  26.  
  27. the author says:
  28. -----------------------------------------------------------------------------------------------
  29. HyperTerminal Private Edition (HyperTerminal PE) is a more powerful version of HyperTerminal, which Microsoft includes with Windows 95, Windows 98, and Windows NT 4.0. Hilgraeve developed HyperTerminal for Microsoft, and began providing HyperTerminal PE free for personal use shortly after the release of Windows 95. Each successive release of HyperTerminal PE has won new awards and caused the program's following to swell. It is today one of the most popular free downloads on the Internet.
  30. ------------------------------------------------------------------------------------------------
  31.  
  32. About the protection:
  33. -----------------------------------------------------------------------------------------------
  34. This protection is Via Nag screen that appear at ever run on the program
  35. Or u can choose HELP->ENTER AUOTHORIZED CODE... (inside the program)
  36. reg key will be saved at:
  37. RegDB Key: Software\Hilgraeve Inc\HyperTerminal PE\3.0
  38. ------------------------------------------------------------------------------------------------
  39.  
  40.                                        The Essay
  41.                                        ==========
  42.  
  43. Today we will learn how to crack this program in 2 posibles ways, 
  44. I wanna thank +ORC for the second approach! .
  45. I will not sniff out serial, cuz it's very hard-task,
  46. this program do not use any algo to calculate any
  47. registered serial number, and are pronoused us with a REG CODE.
  48. so usually there won't be alot of serials to deal with 
  49. we can max minimize it to 3-1 posible serials, best case 1 serial.
  50. ok so what we going to do today, first we explore the program ans it's elements.
  51.  
  52. ======================================[1's Approach]============================================
  53.  
  54. load the program you will see a NAG SCREEN with 3 buttons "OK" / "REGISTER" / "ENTER CODE"
  55. we press the "ENTER AUTHORIZE CODE" button and we continue to our nice TextA field.
  56. Ener any code u wish..
  57. --------------------------
  58. Enter Code: [ 1234567890 ]
  59. --------------------------
  60.  
  61. Load Up SoftIce, and we will use the BreakPoint "GetDlgItemTextA", to break with.
  62. So set it up : BPX GetDlgItemTextA <Enter>...we are done!
  63. Leav SoftIce with F5 or X or Ctrl-D (never mind wich)
  64. Press "OK" button, SoftIce will immidiatly Breaks In..Press F12 only one time.
  65. we will be here:
  66.  
  67. ====================================================================================|
  68. EAX=0000000A   EBX=0063F698   ECX=800077E8   EDX=80008A58   ESI=000003F4            |
  69. EDI=00000810   EBP=0063F644   ESP=0063F624   EIP=1001B7AE   o d I S z a P c         |
  70. CS=0177   DS=017F   SS=017F   ES=017F   FS=11BF   GS=0000   SS:0063F62C=34333231    |
  71. ....................................................................................|
  72. 0177:1001B7A8  CALL      [USER32!GetDlgItemTextA]                                   |       
  73. 0177:1001B7AE  LEA       EAX,[EBP-18]      <= We Break Here, Get Serial From TextA  |     
  74. 0177:1001B7B1  PUSH      EAX               <= Save Entered Serial To Stack          |   
  75. 0177:1001B7B2  CALL      1001B835          <= Call Program's Main Check Of Code No  |  
  76. 0177:1001B7B7  CMP       EAX,01            <= "Flag City" is EAX = Correct Code?    |   
  77. 0177:1001B7BA  JNZ       1001B7DA          <= No...Begger_Off                       |   
  78. 0177:1001B7BC  LEA       EAX,[EBP-18]      <= Not Important                         | 
  79. 0177:1001B7BF  PUSH      EAX               <= Not Important                         | 
  80. 0177:1001B7C0  CALL      1001B3E1          <= Not Important                         | 
  81. 0177:1001B7C5  MOV       EAX,[10038718]    <= Not Important                         | 
  82. ====================================================================================|
  83.  
  84. Ok let's us examin the asm code we see above.
  85. We see a CALL->CMP unsual..mostly programers will hide such thing,
  86. But seems they haven't ;P let's take it as our advantage..
  87. Entering the CALL at offset 1001B7B2 will take us to the main
  88. Program's code checking and analayzing, note this is not an algo
  89. Since the program don't use or have it anywhere inside of it!
  90.  
  91. OK we see a CMP...seems the program checks if EAX (fake serial) = 01
  92. hm..so seems to me 01 = real serial flag.
  93. What do i mean by flag??
  94.  
  95. i mean that if we enter a fake serial then EAX=0
  96. and if we enter a correct serial then EAX=1      
  97. so the program checks to see if we enter a correct serial
  98. by using this flag (i'll call it Flag-City).
  99.  
  100. and in our case we enter "1234568790" <= bad serial, EAX=0
  101. then we get a messagebox saying "Invalid Registration Code"
  102.  
  103. Now Exit SoftIce for now, and open up W32Dasm...
  104. Load hyperTeminal.exe (20k weird)...ok we get a dissasembly but..
  105. Weird no String-Freferences and the code is to much small...
  106. No API calling...so i guess something wonrg...ok goto to the
  107. Program's dir "C:\Program Files\Accesories\Hyper\"
  108. We will see that there is a hiden DLL (4000k), that sound much
  109. Better to us...so the program import the data from the hiden DLL..
  110. Heh though no one will search there?? dunno mabye, anyway
  111. Load the dll in W32Dasm...fewwwwww we get a Pure Disasembly with
  112. String-references and we also see the API imoport calling (GetDlgItemTextA,
  113. MessageBoxA and etc.), ok, we click on the Str-Refn button to get a list
  114. Of Exports and Text used by the prgoram's DLL.
  115. Search alittle bit in the end to see the requied text: "Invalid Regitration Code"
  116. Click on it so we will be on the offset that calls it.
  117. It will be here:
  118.  
  119. ======================================================================================|
  120. *Referenced by a posible (U)ncoditional or (C)onditional Jump ar adress:              |
  121. |:1001B7BA(C)                                                                         |
  122. |                                                                                     |
  123. :1001B7DA 6A30      PUSH 00000030                                                     |
  124.                                                                                       |
  125. *Possible StringData Ref From Data OBJ  -> "HyperTeminal"                             |
  126.                                |                                                      |
  127. :1001B7DC 68FC020410           PUSH 100402FC                                          |
  128.                                                                                       |
  129. *Possible StringData Ref From Data OBJ  -> "Invalid Registration Code."               |
  130.                                |                                                      |
  131. :1001B7E1 689C030410           PUSH 1004039C    <= Breaks here                        |
  132. :1001B7E6 57                   PUSH EDI                                               |  
  133.                                                                                       |
  134. *Reference To: User32.MessageBoxA, Ord:01C1h                                          |
  135. ======================================================================================|
  136.  
  137. OK so we got the dissasembly of the required place of the MessageBoxA called from.
  138. but! we can see that there is an (U)ncoditional or (C)onditional Jump that called
  139. to this MessagBoxA...at adress offset "1001B7BA", seems that we must check it
  140. Out..ok press SEARCH->FIND TEXT and fill in : 1001B7BA  (note the direction need to be
  141. Up..tells W32dasm to look this adress at direction UP).
  142. ok we found the jump, w32dasm will break here:
  143.  
  144. =========================================================================================|
  145.                                                                                          |      *Reference To: User32.GetDlgItemTextA, Ord:0106h                                         |
  146.                                      |                                                   |
  147. :1001B7A8 FF1598830310               CALL dword ptr [10038398]                           |
  148. :1001B7AE 8D45E8                     lea eax, dword ptr [ebp-18]   ; Get user input      |
  149. :1001B7B1 50                         push eax                      ; Save it for later   |
  150. :1001B7B2 E87E000000                 CALL 1001B835                 ; Program's checks    |
  151. :1001B7B7 83F801                     CMP eax, 00000001             ; Compare fake serial |
  152. :1001B7BA 751E                       JNE 1001B7DA                  ; Begger_Off          |
  153.                                                                                          |
  154. =========================================================================================|
  155.  
  156. OK, remmrber this code above??, yeah the same as we got from SoftIce when we breaked
  157. With GetDlgItemTexta, this prove use that the MessageBoxA is really called from here
  158. and so we are ready for Our first approch in the crack.
  159. Note: i will not enter the CALL now, i will enter it in the second approach, so we
  160. can get a better idea on the second apprach.
  161.  
  162. ok so the main idea is clear, EAX = 1 if we enter correct serial else EAX=0
  163. so what we need to do is to change the call (which is what decide the value of EAX)
  164. to a simple Instruction: MOV EAX,00000001
  165. got the idea??
  166. Sure u did, it's not to hard u know ;P
  167.  
  168. so now it will be like this:
  169.  
  170. =========================================================================================|
  171.                                                                                          |      *Reference To: User32.GetDlgItemTextA, Ord:0106h                                         |
  172.                                      |                                                   |
  173. :1001B7A8 FF1598830310               CALL dword ptr [10038398]                           |
  174. :1001B7AE 8D45E8                     lea eax, dword ptr [ebp-18]   ; Get user input      |
  175. :1001B7B1 50                         push eax                      ; Save it for later   |
  176. :1001B7B2 B801000000                 MOV eax, 00000001             ; EAX = 01            |
  177. :1001B7B7 83F801                     CMP eax, 00000001             ; Compare fake serial |
  178. :1001B7BA 751E                       JNE 1001B7DA                  ; Begger_Off          |
  179.                                                                                          |
  180. =========================================================================================|
  181.  
  182. notice the diffrent?? :=)
  183. a few byte changes and we get a full registered program to use with.
  184. Note: the patch it self is in the DLL, so load up hex editor , and load the DLL
  185. in it, and look for this adress: E87E000000
  186. you will be drop here:
  187.  
  188. |----------------------------------------|
  189. | :1001B7B2 E87E000000   CALL 1001B835   |
  190. |----------------------------------------|
  191.  
  192. Now press F3 for edit, and Press F2 for ASM edit Window (Hview 6.40)
  193.  
  194. you will see this window of asm edit:
  195.  
  196. |===Aseembler======|
  197. |  CALL 1001B835   |
  198. |==================|
  199.  
  200. just change it with regular ascii to:
  201.  
  202. |===Aseembler========|
  203. |  MOV EAX,00000001  |
  204. |====================|
  205.  
  206. Press <enter> and then ESC..to get our if Edit mode!
  207. F9 for save correct file, F10 to out of the program (hex editor).
  208.  
  209. So now that we changed eax register to hold the Value flag of 01, the 
  210. program think it's registered when Excuting the instruction CMP eax,01
  211. no bad message and we cleared our way and cut some looses in fidning actual S.code
  212. run the exe again, and u enter any number, press ok...hehe program registered!
  213. no more nag screen and the HELP->ENTER AUTHORIZED CODE is now Greyed out!
  214.  
  215. Job Done!.
  216.  
  217. =================================[Second Approach]=============================================
  218.  
  219. The Second Approach is a bit more harder, since u need to
  220. enter the program's main check (CALL) at offset: 1001B7B2
  221. From there We need to understand how the program behaves
  222. while checking our code (fake) we entered...well we know the
  223. Final conclusion (1/0), yes but how it's created is another
  224. story.
  225. so first let's enter the call and see what us awating us ;P
  226. Note: alittle big asm check routine, i will do my best to explaine :=)
  227.  
  228.                                  [Program Check Routine:]
  229.                                  ------------------------
  230.  
  231. * Referenced by a CALL at Address:
  232. |:1001B7B2   
  233. |
  234. :1001B835 55                      push ebp
  235. :1001B836 8BEC                    mov ebp, esp
  236. :1001B838 83EC1C                  sub esp, 0000001C
  237. :1001B83B 6A15                    push 00000015
  238. :1001B83D 8D45E4                  lea eax, dword ptr [ebp-1C]      ; get code
  239. :1001B840 6A00                    push 00000000
  240. :1001B842 50                      push eax                         ; save
  241. :1001B843 E860BC0100              Call 100374A8                    
  242. :1001B848 83C40C                  add esp, 0000000C                ; max chars = 12
  243. :1001B84B 8D45E4                  lea eax, dword ptr [ebp-1C]      ; get user serial
  244. :1001B84E FF7508                  push [ebp+08]                    ; save chars
  245. :1001B851 50                      push eax                         ; save stack
  246. :1001B852 E835BDFEFF              call 1000758C                    ; xor ecx/edx
  247. :1001B857 807DE448                cmp byte ptr [ebp-1C], 48        ; first char = "H" ?
  248. :1001B85B 7404                    je 1001B861                      ; yes then contine ------|
  249. :1001B85D 33C0                    xor eax, eax                     ; clear eax              |   
  250. :1001B85F EB51                    jmp 1001B8B2                     ; jump to LEAVE          |
  251. :1001B861 8D45E4                  lea eax, dword ptr [ebp-1C]      ; we jump here if "H" <--|  
  252. :1001B864 50                      push eax                         ; save
  253. :1001B865 E80DBDFEFF              call 10007577                    ; get fake serial lenght
  254. :1001B86A 83F806                  cmp eax, 00000006                ; compare with '6'
  255. :1001B86D 7CEE                    jl 1001B85D                      ; lower then '6'? then LEAVE
  256. :1001B86F 8A4C05E2                mov cl, byte ptr [ebp+eax-1E]    ; 9'th char move to cl
  257. :1001B873 8D4405E4                lea eax, dword ptr [ebp+eax-1C]  ; fake serial
  258. :1001B877 8065FE00                and byte ptr [ebp-02], 00        ; AND ebp-2 with 00 " "
  259. :1001B87B 884DFC                  mov byte ptr [ebp-04], cl        ; last char move to ebp
  260. :1001B87E 8A48FF                  mov cl, byte ptr [eax-01]        ; last char move to cl
  261. :1001B881 8060FE00                and byte ptr [eax-02], 00        ; AND ebp-2 with 00 " "
  262. :1001B885 8D45E4                  lea eax, dword ptr [ebp-1C]      ; move fake -1 char
  263. :1001B888 56                      push esi                         ; save source 
  264. :1001B889 50                      push eax                         ; save to stack
  265. :1001B88A 884DFD                  mov byte ptr [ebp-03], cl        ; last char move to ebp+3
  266. :1001B88D E822BC0100              Call 100374B4                    ; lengh of serial -1
  267. :1001B892 59                      pop ecx                          ; load ecx
  268. :1001B893 50                      push eax                         ; save ecx
  269. :1001B894 8D45E4                  lea eax, dword ptr [ebp-1C]      ; fake serial
  270. :1001B897 50                      push eax                         ; save stack
  271. :1001B898 6A00                    push 00000000                    ; flag?
  272. :1001B89A E817000000              call 1001B8B6                    ; 
  273. :1001B89F 8BF0                    mov esi, eax                     ; esi = eax (fake serial)? 
  274. :1001B8A1 8D45FC                  lea eax, dword ptr [ebp-04]      ; fake serial
  275. :1001B8A4 50                      push eax                         ; save stack  
  276. :1001B8A5 E867000000              call 1001B911                    ;
  277. :1001B8AA 2BC6                    sub eax, esi                     ; eax-esi = -1
  278. :1001B8AC 5E                      pop esi                          ; reload esi
  279. :1001B8AD F7D8                    neg eax                          ; eax = -1 (negative of 1)
  280. :1001B8AF 1BC0                    sbb eax, eax                     ; eax = -1 (ffffffff)
  281. :1001B8B1 40                      inc eax                          ; eax = 0 <= bad_boy
  282. :1001B8B2 C9                      leave                            ; exit
  283. :1001B8B3 C20400                  ret 0004                         ; return
  284.  
  285. ok, got the idea?..basicly it's check for max/min chars that the serial need to be, also
  286. it check for "H" char with the first char u enter, other wise it jump to bad boy.
  287. then it's moving chars from the reg coode and play it alittle.
  288. as i said, it's very hard to get the serial, so only very high skilled asm
  289. could sniff out the serial, other wise the only way we can do is to use another patch.
  290. that patch will let us use an serial number start with "H" and need to be 6-12 long 
  291. registration code.
  292.  
  293. second patching approach :
  294.  
  295. since after that call we have a CMP eax,01
  296. eax need to be 01 at the end of the routine above.
  297. but most casses it will be 0 since we don't know the
  298. real serial, and used a faked one :=)
  299. here the small efficient patch:
  300.  
  301. =================================|
  302. 1001B8AF 1BC0  sbb eax, eax      |
  303.                                  |
  304. To:                              |
  305.                                  |
  306. 1001B8AF 33C0  xor eax, eax      |
  307. =================================|
  308.  
  309. Now that we set eax=0 the next instruction:
  310.  
  311. |=========|
  312. | inc eax |
  313. |=========|
  314.  
  315. will make eax = 1 for every "Hxxxxxx" or until 12 chars
  316. os serial number.
  317.  
  318. this a small and efficient patch, that won't
  319. screw up the code.
  320.  
  321. Job Done!.
  322. ===============================================================================================
  323.  
  324. final notes:
  325.  
  326. all the patching took place inside: hyprtrm.dll
  327. not so hard, just practice...untill next time.
  328.  
  329.  
  330. Have fun :=)
  331.                |==================================================================|
  332.                |             My thanks and gratitude goes to:                     |
  333.                |==================================================================|
  334.                |   -------+ORC----------;for talking to me and for the support    |
  335.                |   ------+SandMan-------;for being a Great Cracker                |
  336.                |   ----CoDe_InSiDe----- ;for helping in cracking                  |
  337.                |   -----BLAcKgH0sT------;for being a good friend :=)              |
  338.                |   -------FusS----------;for the asm / keygenning help            |
  339.                |==================================================================|
  340.