home *** CD-ROM | disk | FTP | other *** search
/ Guide To Cracking 2002 / Guide_to_Cracking_2002.iso / Tutorials / ReverseMes / verulam.txt < prev    next >
Encoding:
Text File  |  2001-09-21  |  5.9 KB  |  163 lines

  1. Solution to Kee LUR-the process killer (tank_) by Verulam
  2.  
  3. Introduction
  4. ------------
  5.  
  6. Well this is my solutoin to tank_'s ReverseMe Kee LUR.exe that can
  7. be found at reversemes.cjb.net
  8.  
  9. The program requires an 'are you sure?' prompt and the code to kill
  10. the currenty selected process when the kill button is pressed.
  11.  
  12. Tools
  13. -----
  14.  
  15. Softice
  16. WDASM
  17. DeDe 
  18. HIEW
  19. Procdump
  20.  
  21. Essay
  22. -----
  23.  
  24. First thing to do is to find out how to kill a process, you could 
  25. search your API reference for functions that do such a thing or you 
  26. could just do what I did, know of a program that does such a thing 
  27. and dissasemble it (Procdump).
  28.  
  29. Procdump gave me the two functions OpenProcess and TerminateProcess,
  30. there are a couple more used but I'll explain them later.
  31.  
  32. The next thing to do was to fire up DeDe, a great little program
  33. which disassembles Delphi programs.
  34.  
  35. This gave me:
  36.  
  37. TForm1.Image1Click       45A2AC
  38. TForm1.Button3Click      45A29C
  39. TForm1.ComboBox1Click    45A0B0
  40. TForm1.Button2Click      45A0A8
  41. TForm1.Button1Click      45A074
  42. TForm1.FormCreate        45A06C
  43.  
  44. And also a disassembly of the code at each function.
  45.  
  46. From the dissassembly Button1 is clearly the Kill Button.
  47.  
  48. The first thing to do is to find some space for our 'are you sure?'
  49. dialog box.  The about text you get when you click on the image
  50. mentions reversing and the readme.txt file both of which become
  51. irrelevant once we have finishded so I cut it short with a 
  52. convieniently placed 0 and added my own 'Kill Task' and
  53. 'Are you sure?'.
  54.  
  55. So this gives:
  56.  
  57. 45A074:  pushad
  58. 45A075:  mov eax, 24       ; MB_ICONQUESTION | MB_YESNO
  59. 45A07A:  push eax
  60. 45A07B:  push 45A30B       ; 'Kill Task'
  61. 45A080:  jmp 45A570        ; need to find some more room 
  62.  
  63. 45A570:  push 45A2FD       ; 'Are you sure?'
  64. 45A575:  xor eax, eax
  65. 45A577:  push eax          ; 0 = non-window specific, bad really
  66. 45A578:  call MessageBoxA
  67. 45A57E:  cmp eax, 7        ; IDNO
  68. 45A583:  jz 45A5C6              
  69. 45A585:  push 12345678     ; a marker for pid, more about this later        
  70. 45A58A:  xor eax, eax
  71. 45A58C:  mov al, 01  
  72. 45A58E:  push eax          ; 2 parameters given from dis-asm of procdump
  73. 45A58F:  push eax          ; they are bound to work <g>
  74. 45A590:  push 45F6BC       ; 'kernel32.dll'
  75. 45A595:  call LoadLibraryA
  76. 45A59B:  push 45A088       ; 'OpenProcess'
  77. 45A5A0:  push eax           
  78. 45A5A1:  call GetProcAddress
  79. 45A5A7:  call eax          ; parameters are already on stack pid,01,01
  80. 45A5A9:  xor ebx,ebx       
  81. 45A5AB:  push ebx          ; exit code for process
  82. 45A5AC:  push eax          ; handle returned from openprocess
  83. 45A5AD:  push 45F6BC       ; 'kernel32.dll' a little redundant now
  84. 45A5B2:  call LoadLibraryA
  85. 45A5B8:  push 45A088       ; 'TerminateProcess'
  86. 45A5BD:  push eax           
  87. 45A5BE:  call GetProcAddress
  88. 45A5C4:  call eax          ; again parameters already on stack
  89. 45A5C6:  popad
  90. 45A578:  ret
  91.  
  92. I'll have to explain the push 12345678
  93. The ProcessID value needed is based on which process is being displayed
  94. currently, the hwnd value is displayed as a string and is probably
  95. stored as one (it is if you look) so the value in hex is going to 
  96. have to be pulled out and kept somewhere when the OnChange Event for
  97. the listbox fires.  We need somewhere to store it and where better 
  98. than the actual code we will use to kill it. So at startup and when
  99. the listbox changes we write the pid value to 45A586. This serves
  100. as quite a neat solution and if I didn't recall LoadLibrary and
  101. kept the return from the first it would be even better.
  102.  
  103. So let's find the current ProcessID
  104.  
  105. It's a safe bet that all the processing is done at startup and all the
  106. combobox does is write values to textboxes on selection.  This is 
  107. deduced from a) it's common practice when using a visual programming 
  108. language. b) there is a refresh button which means the data isn't 
  109. real-time/sampled. c) looking at the code at 45A0B0
  110.  
  111. so we need to know which process is currently selected, looking at the
  112. code starting at 45A0B0 we see:
  113.  
  114. 45A0D7:  call 0041FA24
  115. 45A0DC:  inc eax
  116. 45A0DD:  and eax, 000000FF
  117. 45A0E2:  lea eax, dword ptr [eax+4*eax]
  118. 45A0E5:  lea esi, dword ptr [8*eax+0045D874]
  119. 45A0EC:  mov eax, dword ptr [esi]
  120.        
  121. The call at 41FA24 returns 0 for the first item in the listbox,
  122. 1 for the second, 2 for the third and so on. A zero based array.
  123. All the + and * should be a big clue there's an array of structures
  124. involved and no self respecting reverse project would be started without
  125. a little research.  To get a list of processes you can:
  126. CreateToolhelp32Snapshot, Process32First, Process32Next.
  127. The Process32 functions use a structure called PROCESSENTRY which
  128. with other important information contains the processid as the
  129. second structure entry so:
  130.  
  131. 45A0E5:  JMP 45A5C8
  132. 45A0EA:  nop           ; for neatness
  133. 45A0EB:  nop           ; or inc eax, dec eax if you wish     
  134.  
  135. and
  136.  
  137. 45A5C8:  lea esi, [eax*8+45D874]    ; our overwritten code
  138. 45A5CF:  push eax                   ; save eax
  139. 45A5D0:  mov eax, [esi+08]          ; the second structure entry
  140. 45A5D3:  mov [45A586], eax          ; self modifying code
  141. 45A5D8:  pop eax                    ; restore eax
  142. 45A5D9:  jmp 45A0EC                 ; jump to next instruction
  143.  
  144. All that is left is to fire up procdump and edit the permissions
  145. for the code section replacing the 6 at the start with a C.
  146. This is done because by default you don't want to go messing
  147. with your code.
  148.  
  149. Further Enhancements
  150.  
  151. The code as it stands doesn't work as a program should, when you kill
  152. a process you need to hit the refresh button otherwise it is still listed
  153. and people my think they wern't able to kill it so:
  154.  
  155. Add a call to 459EC0 before you return and it will refresh them.
  156.  
  157. Another thing is to add a call to WaitForSingleObject specifying
  158. a process event in the call so the programm gives the process
  159. a bit of time to die before refreshing the list.
  160.  
  161. -------
  162. Verulam
  163.