home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Stone / windows / stnapihd.asm < prev    next >
Encoding:
Assembly Source File  |  2000-05-25  |  2.2 KB  |  83 lines

  1. Comment % Stone's APIHook - Detector :)
  2.  
  3.  
  4.       Detecting an API-Spy real simple in a TASM/TLINK compiled program.
  5.       This program will detect any API spy that hooks MessageBoxA api
  6.           by modifying the IAT. (Ofcause provided the HOOK doesn't come up
  7.       with counter meassures)....
  8.  
  9.       NOTICE: THIS PROGRAM STRONGLY HINGES ON THE WAY BORLAND MAKES
  10.           API-CALL'S... THE JUMP-TABLE APPROACH. NOTICE ALSO THAT IT HINGES
  11.           ON THE "DETECT" CALL TO BE COMPILED AS A SHORT (RELATIVE CALL)...
  12.  
  13.        For a MS Convertion replace the first 4 lines of code with:
  14.       mov eax, dword ptr [Detection+2]
  15.       mov eax, [eax]
  16.           ...
  17.       
  18.           To change detection from the MessageBoxA api to another just change
  19.           the call in detection accordingly.
  20.  
  21.                 2nd&mi
  22.                 Stone / UCF & F4CG 1998
  23.                 email: stone@one.se
  24.     %
  25.  
  26.  
  27.  
  28.  
  29. .386P
  30. Locals
  31. jumps
  32. .Model Flat ,StdCall
  33. extrn VirtualQuery : PROC
  34.  
  35. UNICODE=0
  36. include w32.inc
  37. ;──────────────────────────────────────────────────────────────────────────────
  38. .Data  
  39. Mem_Structure:
  40. pvBaseAddress     dd 0
  41. pvAllocBase       dd 0
  42. dwAllocProt       dd 0
  43. dwRegionSize      dd 0
  44. dwState              dd 0
  45. dwProtect    dd 0
  46. dwType        dd 0 
  47.  
  48. lpUser32     db "USER32.DLL",0
  49. Tittle        db "Stone's ApiHook Detect",0
  50. Detected    db 13,"                 FOUND!!",13,0
  51. NotHere        db 13,"No ApiHook Installed on MessageBoxA",13,0
  52. .Code                                  
  53. ;──────────────────────────────────────────────────────────────────────────────
  54. Main:
  55.     mov eax, dword ptr [Detection+1]    ; Find IAT: 
  56.                         ; eax = JMPtable-entry's displacement
  57.                         ; from Detection
  58.     add eax, offset Detection+5+2        ; eax->IAT-Entry in jump instruction
  59.                         ; E8(ADDRESS)=5, 2= FF25 of jump
  60.     mov eax, [eax]                ; eax->IAT-Entry
  61.  
  62.     mov eax, [eax]                ; eax = IAT-entry
  63.  
  64.     call VirtualQuery, eax, offset Mem_Structure, 4*7 ; Which module owns this?
  65.  
  66.     call GetModuleHandleA, Offset lpUser32    ; Get USER32's baseaddress
  67.     cmp eax, [pvAllocBase]            ; do they compare?
  68.         jnz  SpyDetected
  69.  
  70.     call MessageBoxA, 0, offset NotHere, offset Tittle, 0
  71. exit:
  72.     Call ExitProcess, LARGE-1        
  73.  
  74. SpyDetected:
  75.     call MessageBoxA, 0, offset Detected, offset Tittle, 0
  76.     jmp  exit    
  77.  
  78. Detection:
  79.     call MessageBoxA
  80.  
  81. ;──────────────────────────────────────────────────────────────────────────────
  82. End Main
  83.