From cybersec-toolkit
Explains low-level keylogger architecture: kernel hooks, ETW capture, user vs kernel mode, stealth, and exfiltration. For security research and EDR evasion analysis.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cybersec-toolkit:offensive-keylogger-archThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- **Skill Name**: keylogger-architecture
Low-level keylogger architecture design: kernel driver hooks (WH_KEYBOARD_LL, SetWindowsHookEx), ETW-based input capture, user-mode vs kernel-mode approaches, stealth techniques, and data exfiltration. Use for understanding input capture mechanisms, EDR evasion research, or malware architecture analysis.
Use this skill when the conversation involves any of:
keylogger, keyboard hook, WH_KEYBOARD_LL, SetWindowsHookEx, ETW, kernel driver, input capture, low-level keylogger, malware architecture, stealth, exfiltration
When this skill is active:
Case study of different keylogger implementations, how to implement them and their individual IOCs.
Majority of malware uses user32.dll!SetWindowHookEx to create a global hook event. this modifies an internal structure in win32k.sys.
Internally, SetWindowsHookEx is just a user-mode wrapper around NtUserSetWindowsHookEx (which itself wraps around zzzzNtUserSetWindowsHookEx) in win32k.sys. What happens after you call it depends on the hook type you request but the sequence is always the same four steps:
Validate and allocate a hook record
win32k.sys creates an internal HOOK structure, fills in the filter type, module handle, thread/desktop IDs, and inserts the structure at the head of the global hook chain for that type
Decide whether the hook procedure must live in the target process
WH_KEYBOARD_LL, WH_MOUSE_LL)WM_* message posted to its hidden “ghost” window .WH_KEYBOARD, WH_CBT, WH_GETMESSAGE, …)win32k queues an asynchronous load request to csrss.exe, which in turn calls LoadLibraryEx inside the target process, mapping the hook DLL and fixing up its entry point.win32k; the first user-mode exit from kernel to that process takes the APC and calls LdrLoadDll directly.
– The first time the target thread is about to return to user mode, the kernel APCs the loader, so the DLL’s DllMain runs in the context of the victim process.Event routing at runtime
When the monitored event occurs (key press, window activation, etc.), win32k walks the hook chain inside the thread that owns the input queue.
KBDLLHOOKSTRUCT / MSLLHOOKSTRUCT) into an internal message and posts it to the installing thread’s message queue.Mandatory CallNextHookEx
Each hook handler must call CallNextHookEx to pass control down the chain.
Internally, CallNextHookEx is just a call back into win32k, which continues the chain walk; if any handler fails to call it, the chain is broken and subsequent handlers never run. This might break input for the whole session.
WriteProcessMemory or CreateRemoteThread, but they leave a mapped DLL behind in every hooked process. Easy VAD artefact for EDRs.
Same as above but you're directly calling the lower-level function. Same IOCs, really. You're only bypassing potential hooks in user32.dll. The full logic of these functions could be reimplemented fully without a jump to external modules but it has too much IOCs and is too complex to implement to really be interesting.
Session boundary: raw-input registration is per-session, not per-desktop.
A service in session-0 cannot register for keyboard raw-input and expect to see session-1 keystrokes – the HID packets are routed to the session that owns the target HWND.
(You can open the physical keyboard device object directly and parse HID, but that is a completely different attack surface – needs admin, bypasses win32k.)
tells the window manager to deliver raw HID packets to one specific HWND (or to the thread whose queue the window is attached to)
Practical abuse scenario
PeekMessage / GetMessage loop.HWND_MESSAGE).RIDEV_INPUTSINK – > this routes all keyboard traffic to our window even when it is not in the foreground .WM_INPUT handler call GetRawInputData and log the RAWKEYBOARD payload.Because no hook is installed, this technique:
WinDbg’s !hook listthis still requires your process to stay alive and message-aware, and it cannot key-log from sessions it is not running in.
Kernel-mode implementation:
Win32AllocPoolWithQuotaZInitRegisterRawInputDevices(v9, a2, 0)
Calls the INTERNAL worker (see below).EtwTraceAuditApiRegisterRawInputDevicesThe internal worker modifies our process's EPROCESS structure. This makes it so that we can't re-implement this from user-mode.
ERROR_INVALID_WINDOW_HANDLE) if the thread is not connected to a desktop. Services running in session-0 with no desktop therefore cannot use this path; they must either:To filter for interesting keystrokes you may only monitor keystrokes from Chrome.exe \ firefox.exe, etc.
Different methods of doing that:
NtUserInternalGetWindowText.Win32kFull.sys.
win32u.dllReverse-engineering this was very tedious because the only references of this online seem to be:
BOOL InternalGetWindowText(HWND hwnd, LPWSTR pString, int cchMaxCount) {
DWORD retval = (DWORD)NtUserInternalGetWindowText(hwnd, pString, cchMaxCount);
if (!retval) {
*pString = (WCHAR)0;
}
return retval
}
its a syscall so you can use your favorite *gate technique on it
Now... that's all stuff that can be figured out by anyone determined for the unique research... contact me @ lovestrangekz on tg, everything has a price :]
Ideas that were abandonned:
Use NtUserBuildHwndList/EnumWindows and re-implement the z-order heuristic to generate the list of all handles to all windows and call IsWindowVisible on them and do some other stuff to figure out if they're foreground or not?
Walk _K_USER_SHARED_DATA to query its ConsoleSessionForegroundProcessId member then query the system to know that PID's windows and hope it only has one
lovestrange @ TeamKavkaz join our channel for more hackerz 4 lyfe
npx claudepluginhub 26zl/cybersec-toolkit --plugin cybersec-toolkitDetects rootkit presence on compromised systems using memory forensics, cross-view detection, and integrity checking. Activates for hidden processes, hooked system calls, modified kernel structures, or covert network connections.
Detects and analyzes process injection techniques in malware via memory forensics, API monitoring, and behavioral analysis. Activates for injection detection, hollowed process investigation, or in-memory threat detection.
Detects and analyzes malware process injection techniques like DLL injection, process hollowing, APC injection, thread hijacking via memory forensics (Volatility), Sysmon, and API monitoring. For EDR alerts and in-memory threats.