Foro de elhacker.net

Seguridad Informática => Análisis y Diseño de Malware => Mensaje iniciado por: fary en 4 Agosto 2011, 13:03 pm



Título: Error intentando hookear FindNextFileA
Publicado por: fary en 4 Agosto 2011, 13:03 pm
pues eso, estoi intentando hookear la api FindNextFileA con una dll que estoi creando en FASM pero no hay manera, el programa me explota cuando arga la dll y intento usar la api, el problema creo que esta en que no vuelve a llamar correctamente al api que modifique y por eso explota :S

Este es el código:

Código
  1. format PE GUI 4.0 DLL
  2. entry DllEntryPoint
  3.  
  4. include 'd:\Fasm\INCLUDE\win32ax.inc'
  5.  
  6. section '.code' code readable executable
  7.  
  8. proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
  9.        cmp [fdwReason],1
  10.        je mensage
  11.        jne salir
  12.  
  13.        mensage:
  14.  
  15.        invoke LoadLibrary,"Kernel32.dll"
  16.        invoke GetProcAddress,eax,"FindNextFileA"
  17.        mov ebx,eax ; Dirección de la api en ebx
  18.  
  19.        mov [PunteroOri],ebx
  20.  
  21.        lea edx,dword[ebp-4]
  22.        invoke VirtualProtectEx,-1,ebx,7,PAGE_EXECUTE_READWRITE,edx
  23.  
  24.  
  25.        mov ecx,ApiOriginal
  26.  
  27.        lea edx,dword[ebp-4]
  28.        invoke VirtualProtectEx,-1,ecx,7,PAGE_EXECUTE_READWRITE,edx
  29.  
  30.        mov al,byte[ebx] ; movemos el primer byte
  31.        mov byte[ecx],al
  32.  
  33.        mov byte[ebx],0x68  ; push
  34.        inc ebx
  35.        inc ecx
  36.  
  37.        mov eax,dword[ebx]   ; movemos 4 bytes
  38.        mov dword[ecx],eax
  39.  
  40.        mov dword[ebx],Funcion ; dreccion funcion
  41.        add ebx,4
  42.        add ecx,4
  43.  
  44.        mov al,byte[ebx] ; ultimo byte
  45.        mov byte[ecx],al
  46.  
  47.        mov byte[ebx],0xC3   ;ret
  48.        inc ebx
  49.  
  50.        salir:
  51.        ret
  52. endp
  53.  
  54. Funcion:
  55.  
  56.             ApiOriginal:
  57.             nop
  58.             nop
  59.             nop
  60.             nop
  61.             nop
  62.             nop
  63.  
  64.             mov eax,[PunteroOri]
  65.             add eax,6
  66.             jmp eax
  67.  
  68.             ret
  69.  
  70.  
  71. ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError);
  72.  
  73. proc ShowErrorMessage hWnd,dwError
  74.  local lpBuffer:DWORD
  75.        lea     eax,[lpBuffer]
  76.        invoke  FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0
  77.        invoke  MessageBoxA,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK
  78.        invoke  LocalFree,[lpBuffer]
  79.        ret
  80. endp
  81.  
  82. ; VOID ShowLastError(HWND hWnd);
  83.  
  84. proc ShowLastError hWnd
  85.        invoke  GetLastError
  86.        stdcall ShowErrorMessage,[hWnd],eax
  87.        ret
  88. endp
  89.  
  90.  
  91.  
  92. section '.data' data readable writeable
  93.        PunteroOri dd ?
  94.  
  95. section '.idata' import data readable writeable
  96.  
  97.  library kernel,'KERNEL32.DLL',\
  98.          user,'USER32.DLL'
  99.  
  100.  import kernel,\
  101.         GetLastError,'GetLastError',\
  102.         SetLastError,'SetLastError',\
  103.         FormatMessage,'FormatMessageA',\
  104.         LocalFree,'LocalFree',\
  105.         LoadLibrary,'LoadLibraryA',\
  106.         GetProcAddress,'GetProcAddress',\
  107.         VirtualProtectEx,'VirtualProtectEx',\
  108.         ExitProcess,'ExitProcess'
  109.  
  110.  import user,\
  111.         MessageBoxA,'MessageBoxA'
  112.  
  113. section '.edata' export data readable
  114.  
  115.  export 'ERRORMSG.DLL',\
  116.         ShowErrorMessage,'ShowErrorMessage',\
  117.         ShowLastError,'ShowLastError'
  118.  
  119. section '.reloc' fixups data discardable
  120.  


Tambien me gustaría que me explicasen como puedo debugear estas cosas ya que no lo tengo muy claro  :-\

saludos.


Título: Re: Error intentando hookear FindNextFileA
Publicado por: .:UND3R:. en 4 Agosto 2011, 18:33 pm
Para debuggear necesitas usar ollydbg, así este te podría mostrar en que linea se genera el error, es decir si hay algún desbordamiento de la pila o se genera una excepción que no se pueda reparar, saludos


Título: Re: Error intentando hookear FindNextFileA
Publicado por: fary en 5 Agosto 2011, 13:13 pm
Para debuggear necesitas usar ollydbg, así este te podría mostrar en que linea se genera el error, es decir si hay algún desbordamiento de la pila o se genera una excepción que no se pueda reparar, saludos

Asta ahí había llegado... yo preguntaba como cargar la dll y etc. Aora cargo mi DLL co LoadLibrary y listo :P

saludos.