Hiding
Windows Kernel Hooks: Inline, SSDT and IRP Hooking
How Windows kernel rootkits hook functions, service tables and driver dispatch routines to hide, why PatchGuard and HVCI changed that, and how to check memory.
- Goal
- Hiding
- Layer
- Kernel
- Platforms
- Windows
- ATT&CK
- T1014
- Also known as
- Kernel hooking, SSDT hooking, IRP hooking, Inline hooking
- Used by
- DemodexSnakeZeroAccess
- Checked by
- None: no module reads its traces
Overview
A kernel hook redirects kernel code to the rootkit. When Windows, or a driver, calls the hooked function or dispatches a request through the hooked pointer, the rootkit's code runs first: it calls the original, then removes its own files, registry keys, handles or connections from the result. Every program on the machine, security tools included, receives the filtered answer.
Hooks are the oldest kernel rootkit technique on Windows. A 2004 Black Hat deck on DKOM already presents system call table hooking as the previous generation, "easy to detect", and direct kernel object manipulation as the next (slides). On 64-bit Windows, Kernel Patch Protection (PatchGuard), introduced with Windows Server 2003 SP1 and Windows XP x64, "monitors if key resources used by the kernel or kernel code itself has been modified" and shuts the system down when it finds an unauthorised patch (Microsoft). That is why current x64 rootkits rarely hook the system service table: they defeat PatchGuard first, as Snake did, edit data instead of code, or move to the documented filtering interfaces that Microsoft offered as the alternative to patching (see filter drivers). IBM X-Force notes the same shift for security vendors, who moved from hooks to kernel callbacks. On Linux, rootkits in the catalogue still replace entries of the system call table.
How it works
| Hook | What is changed | Effect | In Microsoft's bug check 0x109 list |
|---|---|---|---|
| Inline | The first instructions of a kernel function, replaced by a jump or trap into the rootkit | Every call to the function passes through the rootkit | "A function modification" |
| Service table (SSDT) | Entries of the system service dispatch table, which route each system call to its handler | System calls from every process reach the rootkit | "Modification of a system service function" |
| IRP or dispatch | A pointer in a driver object's dispatch table, or a completion routine set on its requests | Requests sent to that driver (file, disk, network queries) pass through the rootkit | "Driver object corruption" |
| Device attachment | A device object attached on top of another driver's device stack | The rootkit sees every request first; this is the legacy filter model, covered under filter drivers | |
| Descriptor tables | Interrupt (IDT) or global (GDT) descriptor table entries | Interrupts or system calls reach the rootkit | IDT, GDT |
The list of corrupted regions that can trigger bug check 0x109 shows what PatchGuard watches: functions, the IDT and GDT, system service functions, driver objects, the loaded module list, import tables and more. A hook that stays in place long enough on a protected system crashes it with that stop code.
Memory integrity (HVCI) adds a harder barrier for inline hooks. It keeps kernel code pages from being writable and "prevents any non-signed memory from being ever executable" (Microsoft). Avast reports that FudModule abandoned a technique that patched function prologues because it conflicted with HVCI. HVCI protects code; a hook that only changes a pointer in data, such as a dispatch table, is a matter for PatchGuard and memory analysis.
How families use it
Snake, 2014 generation. G DATA's Red Paper describes inline patching that "adds a new interrupt instruction (int 0xc3) at the beginning of the hooked function". The hooked functions and their purpose:
| Function | Hides or does |
|---|---|
ZwQueryKey, ZwEnumerateKey, ZwCreateKey, ZwSaveKey | The persistence keys in the registry |
ZwReadFile | The driver and the virtual file system files |
ZwQuerySystemInformation | The rootkit's handles |
ZwTerminateProcess | Clean termination at shutdown |
ObOpenObjectByName | The virtual file systems |
To survive PatchGuard on 64-bit Windows, G DATA's follow-up shows the driver hooking KeBugCheckEx so that bug check 0x109 is not handled, a method G DATA notes was already documented publicly. For the 2023 generation, CISA's advisory says the kernel module removes Snake's components "from any listing returned by the operating system" and intercepts the first packet of incoming TCP sessions, without describing the hooking mechanism.
ZeroAccess, kernel-mode versions. Microsoft reports that Sirefef "implements a disk-level hook to hide its presence": when anything reads the system driver it replaced, the hook returns the original, clean driver. A hash or signature check run on the infected system therefore sees a clean file.
Demodex. Kaspersky reports that the rootkit hides TCP connections on a configured port range from tools such as netstat by hooking "the IOCTL dispatch routine of the NSI proxy driver" (nsiproxy.sys) and setting a completion routine that inspects each connection's port; it notes that an older Derusbi sample used an almost identical flow. Demodex's file and registry hiding uses documented filter interfaces instead.
Traces it leaves
| Trace | Where | Notes |
|---|---|---|
| Patched function prologues | Memory: ntoskrnl.exe and driver code | Code that differs from the file on disk of the same build |
| Service table entries outside the kernel | Memory | Handlers owned by an unexpected module |
| Dispatch routines owned by another module | Memory: driver objects | For example a network or disk driver whose handler lives in an unknown module |
| Unexpected attached devices | Memory: device tree | An unnamed or unknown device on top of a file system, disk or network stack |
| The hooking driver | Driver services and files | Snake's Ultra3 service and its driver in %SYSTEMROOT%\$Ntuninstall…$; ZeroAccess's replaced Windows driver, with its clean copy in a $NtUninstallKB… folder |
| Bug check 0x109 | Crash dumps, System log | PatchGuard caught a modification, or an unrelated fault |
Hooks are in memory and disappear at shutdown; the driver that installs them must load again at each boot, which is where the disk traces come from.
How to check a host
Memory, analysed off the host, is the reference. With Volatility 3:
vol -f host.raw windows.ssdt
vol -f host.raw windows.driverirp
vol -f host.raw windows.devicetree
vol -f host.raw windows.malware.drivermodule
vol -f host.raw windows.modules --dump
windows.ssdt lists each system service entry with its owning module: entries outside the kernel and win32k deserve a look. windows.driverirp lists each driver's dispatch routines and the module that owns them; for a Demodex-style hook, the NSI proxy driver's entries are where to look. windows.devicetree shows device stacks and attached devices. For inline hooks, dump the modules and compare their code sections with the files of the same Windows build.
Disk, read from outside the running system: a disk-level hook only works while the rootkit runs. Compare every driver in System32\drivers by hash with a known-good copy of the same build, as the ZeroAccess page explains, and list the Snake folders and services.
Live, every query passes through the hooked kernel. A result that differs from the offline view is evidence; a clean result is not.
What the checker looks for
The hooks themselves live in memory, so checks is empty. The windrivers module can see the driver that installs them, when the collection was read from outside the running system:
- a driver with no signature raises "An unsigned kernel driver", which fits Snake's 2014 driver;
- a replaced Windows driver whose bytes no longer match its signature raises "The driver was changed after it was signed"; an unsigned replacement raises the unsigned finding, or only the informational "No embedded signature on a Windows driver" if it carries Microsoft's version information (see system driver replacement);
- Snake's old
VBoxDrv.sysraises "A known vulnerable driver (LOLDrivers)".
Two limits matter here. Snake's $Ntuninstall…$ folder is under the Windows folder, so the checker raises no path finding for it: read the ImagePath column. And a collection taken through an infected running system with ZeroAccess may contain the clean copy its disk hook served.
Mitigation and recovery
- 64-bit Windows with Kernel Patch Protection forces hooking rootkits to defeat or race PatchGuard; a 0x109 crash on a production host deserves investigation.
- Memory integrity (HVCI) keeps kernel code from being patched and enforces the vulnerable driver blocklist; Secure Boot and driver signature enforcement keep unsigned hooking drivers out (see DSE tampering).
- Restrict administrator rights, since loading any kernel driver requires them.
Recovery: capture memory, then image the disk and analyse it on another machine. Do not clean in place: a kernel hook means the running system's answers cannot be trusted, including those of the cleaning tool. Scan offline from trusted media, restore replaced drivers from known-good media, and prefer a rebuild; rotate the credentials used on the host.
Sources
Primary public reports, newest first.
- 2024-02-28Lazarus and the FudModule Rootkit: Beyond BYOVD with an Admin-to-Kernel Zero-DayAvast
- 2023-05-09Hunting Russian Intelligence "Snake" Malware (AA23-129A)CISA
- 2021-09-30GhostEmperor: From ProxyLogon to kernel modeKaspersky
- 2020-07-08Introducing Kernel Data ProtectionMicrosoft
- 2020-05-13Bug Check 0x109: CRITICAL_STRUCTURE_CORRUPTIONMicrosoft
- 2014-03-07Uroburos: Deeper travel into kernel protection mitigationG DATA
- 2014-02-28Uroburos: Highly complex espionage software with Russian roots (Red Paper)G DATA
- 2012-04-12Win32/Sirefef threat descriptionMicrosoft
- 2006-08-12An Introduction to Kernel Patch ProtectionMicrosoft
- 2004-01-29DKOM (Direct Kernel Object Manipulation)Black Hat Windows Security 2004
See also
Related techniques
- Direct kernel object manipulation (DKOM)Hiding
- Userland API hookingHiding
- File system and network filter driversHiding
- Driver signature enforcement tamperingGetting into the kernel
- System call table hookingHiding
Families that use it
- DemodexWindows kernel rootkit
- SnakeWindows kernel rootkit
- ZeroAccessWindows kernel rootkit