Otro ejemplo de api Hook que muestra en un MessageBox los archivos mediante los vea el explorer.exe
; FinFuncion-FuncionInyectada = tamaño de la funcion
include 'win32ax.inc' ;Incluimos la libreria
.data ; Declaramos la sección de codigo
proc start ; Entry Point
locals
PID dd ?
lProc dd ?
DirFun dd ? ;Espacio donde escribiremos nuestro codigo
endl
invoke FindWindowEx,0,0,"Progman",NULL
invoke GetWindowThreadProcessId,eax,addr PID
invoke OpenProcess,PROCESS_CREATE_THREAD+PROCESS_VM_OPERATION+PROCESS_VM_WRITE,FALSE,[PID]
mov [lProc],eax
stdcall ReservarEspacio,FinFuncion-FuncionInyectada,[lProc]
mov [DirFun],eax
invoke WriteProcessMemory,[lProc],[DirFun],FuncionInyectada,FinFuncion-FuncionInyectada,0
invoke GetModuleHandle,'kernel32.dll'
invoke CreateRemoteThread,[lProc],0,0,[DirFun],eax,0,0
ret
endp
proc ReservarEspacio,pTamaño,pPid
invoke VirtualAllocEx,[pPid],0,[pTamaño],MEM_COMMIT+MEM_RESERVE,PAGE_EXECUTE_READWRITE
ret
endp
proc FuncionInyectada,pMZ
locals
pGetProcAddress dd ?
lDelta dd ?
lGetMDA DD ?
lWSOCK32 dd ?
lRMM dd ?
lDD dd ?
LVRPX dd ?
lBytes dd ?
lSend dd ?
endl
call delta
delta:
pop edx
sub edx,delta
mov [lDelta],edx
mov eax,[lDelta]
add eax,GetAddressFunction
mov [pGetProcAddress],eax
stdcall [pGetProcAddress],[pMZ],"GetModuleHandleA",[lDelta]
mov [lGetMDA],eax
stdcall [lGetMDA],"kernel32.dll"
mov [lWSOCK32],eax
stdcall [pGetProcAddress],[pMZ],"GetProcAddress",[lDelta]
stdcall eax,[lWSOCK32],"FindNextFileW"
mov [lSend],eax
mov ebx,cRtlMoveMemory
add ebx,[lDelta]
mov [lRMM],ebx
mov edi,BytesOriginales
add edi,[lDelta]
stdcall [pGetProcAddress],[pMZ],"VirtualProtectEx",[lDelta]
mov [LVRPX],eax
mov edi,BytesOriginales
add edi,[lDelta]
lea edx,[lDD]
mov [lBytes],edi
stdcall [LVRPX],-1,[lBytes],40,PAGE_EXECUTE_READWRITE,edx
stdcall [lRMM],[lBytes],[lSend],40
lea edx,[lDD]
stdcall [LVRPX],-1,[lSend],20,PAGE_EXECUTE_READWRITE,edx
mov eax,[lSend]
mov byte[eax],0x68
inc eax
mov dword[eax],MiSend
mov edx,[lDelta]
add dword[eax] ,edx
add eax,4
mov byte[eax],0xC3
mov eax,DireecionAPI
add eax,[lDelta]
mov edi,[lSend]
mov [eax],edi
stdcall [pGetProcAddress],[pMZ],"GetModuleHandleA",[lDelta]
mov [lGetMDA],eax
stdcall [lGetMDA],"user32.dll"
stdcall [pGetProcAddress],eax,"MessageBoxW",[lDelta]
mov edi, eax
mov eax,DireccionMes
add eax,[lDelta]
mov [eax],edi
stdcall [pGetProcAddress],[pMZ],"Sleep",[lDelta]
stdcall eax,-1
endp
proc GetAddressFunction,pMZ,pApi,lDelta
locals
lDelta2 dd ?
endl
;EDI = MZ
;Expot data = EBX
;Esi = Cantidad de funciones
;edx = AddressOfNames
;ECX = Propositos generales
mov edi, [pMZ]
mov ebx,[edi+0x3c]
mov ebx,[ebx+edi+0x78]
add ebx,edi
mov esi,[0x18+ebx]
mov edx, [0x20+ebx]
add edx,edi
.bucle:
dec esi
cmp esi,0
je .error
mov eax,esi
rol eax,2 ;Multiplicamos esi por 4
mov eax,[edx + eax]
add eax,edi
push eax
mov eax,[lDelta]
mov [lDelta2],eax
add [lDelta2],comparar
pop eax
stdcall [lDelta2],[pApi],eax
xor eax,0
jnz .bucle
mov eax,[0x24+ebx]
add eax,edi
movzx ecx, word[eax + 2*esi]
mov eax, [ebx + 0x1c]
add eax,edi
mov eax, [eax + 4 * ecx]
add eax, edi
.salir:
ret
.error:
xor eax,eax
jmp .salir
endp
proc comparar ,SRC,DST
push edi ecx esi
mov ecx,-1
mov edi,[SRC]
mov al,0
repnz scasb
mov eax,ecx
not eax
mov ecx,eax
mov esi,[SRC]
mov edi,[DST]
repz cmpsb
mov eax,1
jnz Next
dec eax
Next:
pop esi ecx edi
ret
endp
;Descripcion: Esta función funciona igual que la winapi RtlMoveMemory
; by YST
proc cRtlMoveMemory,cBuffer,Cpuntero,cCantidad
push esi edi
xchg edi,[cBuffer]
xchg esi,[Cpuntero]
.bucleb:
dec [cCantidad]
movsb
cmp [cCantidad],0
jge .bucleb
pop edi esi
ret
endp
proc MiSend,p1,p2
locals
lDelta dd ?
lRMM dd ?
lResultado dd ?
lDireccion dd ?
lMensaje dd ?
lBytes dd ?
endl
call .delta
.delta:
pop edx
sub edx,.delta
mov [lDelta],edx
mov eax,[lDelta]
add eax,DireccionMes
mov eax,dword[eax]
mov [lMensaje],eax
mov eax, DireecionAPI
add eax,[lDelta]
mov eax,dword[eax]
mov [lDireccion],eax
mov eax,cRtlMoveMemory
add eax,[lDelta]
mov [lRMM],eax
mov eax,BytesOriginales
add eax,[lDelta]
mov [lBytes],eax
stdcall [lRMM],[lDireccion],[lBytes],40
stdcall [lDireccion],[p1],[p2]
mov [lResultado],eax
mov eax,[lDelta]
add eax,MiSend
mov ebx,[lDireccion]
mov byte[ebx],0x68
inc ebx
mov dword[ebx],eax
add ebx,4
mov byte[ebx],0xC3
mov eax,[p2]
add eax,44
stdcall [lMensaje],0,eax,0,0
mov eax,[lResultado]
ret
endp
DireccionMes dd ?
DireecionAPI dd ?
BytesOriginales:
db 50 dup (0)
FinFuncion:
.end start ; Declaramos el Import data y el Entry Point