home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / ReverseMes / xorcise.txt < prev    next >
Encoding:
Text File  |  2001-09-21  |  3.6 KB  |  73 lines

  1. Tools used:
  2. SoftIce
  3. Ida
  4. HIEW
  5. (yes, i use always the same tools) :p
  6.  
  7.  
  8.  
  9.  
  10.             Crudd XorCise solution by Extasy.
  11.  
  12.  
  13.  
  14.  
  15. Well, this time, the target seems to be harder ! As it is said on reversemes.cjb.net, we have to reverseme an algorithm there ! So, as i'm not someone that is crazy with algo's, the first thing i made was to look if it was hard to reverse. But, hopefully, it were an easy one (if it weren't, you couldn't be reading this :-)). After analysing this algo, i saw that it manipulates the files this way:
  16.  
  17. take a byte, xor it with 1, store it, take the next byte, xor it with 2, store it .... So, to reverse it, we simply need to know how many bytes we have to decrypt. As an example, if there are 67 bytes, we will xor the last one with 67, the one before with 66, ....
  18. Ok, we are done with the algo. Now let's get back to some "normal" things :). The usual questions are : which api's ? and where ?. As we're dealing here with a window with a big edit box, we need only 2 api's to read & write into
  19.  that edit : GetWindowTextA and SetWindowTextA. That's all. And, as usual, use procdump to add some extra place at the end of the last section and change its characteristics to E0000020.
  20. To play with those 2 little api's, we only need to have the control handle. We can get this one just after it's creation, at the CreateWindowExA call (at 401693).
  21.  
  22. 00401683 FF 75 F4                                push    [ebp+var_C]
  23. 00401686 FF 75 08                                push    [ebp+arg_0]
  24. 00401689 68 4E 16 40 00                          push    offset str->Edit ; "EDIT"
  25. 0040168E 68 00 02 00 00                          push    200h
  26. 00401693 E8 F2 06 00 00                          call    j_CreateWindowExA
  27. 00401698 89 45 FC                                mov     [ebp+var_4], eax
  28. 0040169B 6A 10                                   push    10h
  29. 0040169D E8 DC 06 00 00                          call    j_GetStockObject
  30. 004016A2 89 45 F8                                mov     [ebp+var_8], eax
  31. 004016A5 6A 01      
  32.                              push    1        
  33. 004016A7 FF 75 F8                                push    [ebp+var_8]
  34. 004016AA 6A 30                                   push    30h
  35. 004016AC FF 75 FC                                push    [ebp+var_4]
  36. 004016AF E8 2A 07 00 00                          call    j_SendMessageA
  37.  
  38. Were could we patch a jump to our code ? Where you want :). I choosed at 4016A5, because there are only pushes, so we can easily re-put them in our place. Assemble a push 404600 / ret. At 404600, assemble :
  39.  
  40. mov eax,d,[ebp-4]
  41. mov d,[4045F8],eax
  42. push 1
  43. push d,[ebp-8]
  44. push 30
  45. push 4016ac
  46. ret
  47.  
  48. Now, everything is fine ! But at this time, another thing came to my mind. Where will we stock all the data read ? As, in the program, you can't read files bigger than 7FFF, extend the virtual size of the last section to 9000. Now we have to add the real function. We will put it at 404616. But what will we put ? in general, it should be a call getwindowtext, followed by the reversed algo, and then se
  49. twindowtext. In asm, it gives this result :
  50.  
  51. push 7000
  52. push 405000 (i put it at a "better looking" address)
  53. push d,[4045f8]
  54. call d,[402078]
  55. mov edi,405000
  56. mov ecx,eax
  57. movzx eax,b,[edi+ecx-1]
  58. xor al,cl
  59. mov [edi+ecx-1],al
  60. loop 2433
  61. push 405000
  62. push d,[4045f8]
  63. call d,[402058]
  64. push 40146b
  65. ret
  66.  
  67. Note that the reversed algo is something like 2 or 3 times smaller :). Now just patch the messagebox code to this place, and, run ! IT WORX !
  68. Well, that's all this time
  69.  
  70. THANKS:
  71. Crudd (for this reverseme),MagicRaph,Edy,Tam,C_DKnight,ep-180,promethee,α tous ceux de #R4N, #C4N, #Win32asm and #crack.fr
  72. Et α tous ceux qui reversent en V.F !
  73.