Foro de elhacker.net

Programación => ASM => Mensaje iniciado por: rmdma() en 1 Marzo 2012, 11:19 am



Título: Problema inyeccion
Publicado por: rmdma() en 1 Marzo 2012, 11:19 am
codigo al que inyectar:
Código
  1.    include 'win32ax.inc'
  2.  
  3.    .data
  4.        t1 db 'sindlll',0
  5.        t2 db 'damedll',0
  6.  
  7.  
  8.    .code
  9.    start:
  10.        stdcall prueba,t1,t2
  11.        ret
  12.  
  13.        proc prueba,t1,t2
  14.            mov esi,[t1]
  15.            mov ecx,[t2]
  16.  
  17.           push 0
  18.           push esi
  19.           push ecx
  20.           push 0
  21.           call [MessageBoxA]
  22.           ret
  23.  
  24.         endp
  25.    .end start
  26.  

la dll:
Código
  1. format PE GUI 4.0 DLL
  2. entry DllEntryPoint
  3.  
  4. include 'win32a.inc'
  5.  
  6. section '.data'
  7.  
  8. dato1 db 'hellooo',0
  9. dato2 db 'agurrrr',0
  10.  
  11.  
  12. section '.text' code readable executable
  13.  
  14. proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
  15.  
  16. pushad
  17. push dato1
  18. push dato2
  19. mov eax, 0x00402010 ; la direccion de la funcion prueba
  20. call eax
  21. add esp,8
  22. popad
  23. endp    
  24.  

quiero usar la funcion prueba desde la dll, pero me esta petando , hesegido el tutorial este
https://foro.elhacker.net/programacion_cc/tutorialiniciandome_en_el_hacking_mediante_inyeccion_de_dll_con_ejercicio-t258750.15.html
 (https://foro.elhacker.net/programacion_cc/tutorialiniciandome_en_el_hacking_mediante_inyeccion_de_dll_con_ejercicio-t258750.15.html) pero  me lo e montao en asm.


Título: Re: Problema inyeccion
Publicado por: Eternal Idol en 1 Marzo 2012, 12:51 pm
Tenes que depurar tu codigo para ver donde falla, podes poner un int 3 en el codigo y configurar el WinDbg como depurador post-mortem, ejecutandolo con -I, asi se abre automaticamente.


Título: Re: Problema inyeccion
Publicado por: _Enko en 1 Marzo 2012, 13:43 pm
la dll esta mal hecha. Te falta la sección de reloc/fixups.

Tenes que poner esto al final de la dll.
Código:
section '.reloc' fixups data discardable
En los ejemplos de fasm, en la carpeta EXAMPLES hay una DLL.


Código
  1.  
  2. ; DLL creation example
  3.  
  4. format PE GUI 4.0 DLL
  5. entry DllEntryPoint
  6.  
  7. include 'win32a.inc'
  8.  
  9. section '.text' code readable executable
  10.  
  11. proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
  12. mov eax,TRUE
  13. ret
  14. endp
  15.  
  16. ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError);
  17.  
  18. proc ShowErrorMessage hWnd,dwError
  19.  local lpBuffer:DWORD
  20. lea eax,[lpBuffer]
  21. invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0
  22. invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK
  23. invoke LocalFree,[lpBuffer]
  24. ret
  25. endp
  26.  
  27. ; VOID ShowLastError(HWND hWnd);
  28.  
  29. proc ShowLastError hWnd
  30. invoke GetLastError
  31. stdcall ShowErrorMessage,[hWnd],eax
  32. ret
  33. endp
  34.  
  35. section '.idata' import data readable writeable
  36. ;..............imports
  37.  
  38. section '.reloc' fixups data discardable
  39.  
  40.  

Si estas en WinNT y familia, no le gusta la secciónes vacias.
En ese caso, se hace
Código:
section '.reloc' data discardable fixups 
if ~ $-$$  
        dd      0,8 ;empty fixups section iff no other fixups  
end if
Saludos.