Windows kernel rootkit detection from memory: SSDT, IRP, callbacks and hidden drivers
7 min read
A kernel rootkit has the same problem as injected user-mode code, one level down. Its code has to run, so something must point at it: a system call table entry, an interrupt vector, a driver's dispatch table, a notification callback, a timer, a thread. And it has to hide, which means removing itself from lists the kernel keeps but that nothing else checks.
Memory forensics catches both halves: resolve every code pointer against the loaded modules, and compare every list a rootkit edits with a scan that ignores it. This post covers how ramparser does both on a Windows image with kernel symbols, using the Volatility plugin names from The Art of Memory Forensics.
The core test: who owns this address?
Almost every check below comes down to one operation. Take a code
pointer from a kernel structure, find the module in
PsLoadedModuleList whose image range contains it, and ask whether
that module should own it. Two outcomes are interesting:
- the pointer lands in the wrong module (a system call handler in a third-party driver);
- the pointer lands in no module at all, meaning code in pool memory that the loader never registered. This is the stronger sign.
SSDT: the system call table
nt!KiServiceTable maps each system call number to its handler. On
x64 each entry is a 32-bit signed offset, and the handler is
KiServiceTable + (entry >> 4). ssdt decodes every entry (bounded
by KiServiceLimit) and attributes each routine to its module. A
rootkit that redirects NtQueryDirectoryFile to hide files shows up
as an entry outside ntoskrnl.exe.
PatchGuard makes this rare on modern x64 Windows, which is exactly why a hit is significant.
Inline hooks on system call handlers
A rootkit can leave the table intact and patch the code it points to
instead. inline_hooks reads the first instructions of every SSDT
handler and decodes a control transfer at entry: jmp rel32,
jmp [rip+x], mov rax, imm; jmp rax, or push; ret. Jumps that
stay inside ntoskrnl or hal are ordinary thunks and are dropped. Only
jumps out of the kernel are reported, with the target and its owning
module. The scope is the system call handlers, not every exported
kernel function.
IDT: interrupt handlers
idt walks every CPU: KiProcessorBlock gives each _KPRCB, from
which the _KPCR and its IdtBase are found, then all 256
_KIDTENTRY64 entries are decoded. Each handler should live in
ntoskrnl or hal. One outside them is intercepting exceptions or
interrupts on that CPU. Rows carry the CPU number, so a hook installed
on only some processors is visible.
Driver IRP tables
Each _DRIVER_OBJECT has a 28-entry MajorFunction[] table: the
handlers for IRP_MJ_CREATE, READ, WRITE, DEVICE_CONTROL and so
on. Hooking another driver's table (the disk, the file system, the
network stack) lets a rootkit filter what the rest of the system sees.
driverirp takes every driver object found by driverscan (a pool
scan, so unlinked drivers are included), reads the table, and marks an
entry as hooked when the handler is outside that driver's own image.
That raw rule is noisy: many drivers legitimately hand IRPs to the
kernel (IopInvalidDeviceRequest) or to Microsoft frameworks such as
wdf01000.sys, ndis.sys or classpnp.sys. The integrity checklist
filters those out and reports the rest as suspicious, not
critical. One limit: the table offset in _DRIVER_OBJECT is the fixed
Windows 10/11 x64 value.
Kernel callbacks
Drivers subscribe to process, thread and image-load events with
PsSetCreateProcessNotifyRoutine[Ex], PsSetCreateThreadNotifyRoutine
and PsSetLoadImageNotifyRoutine. The kernel stores them in 64-slot
arrays of EX_CALLBACK_FAST_REF, where the routine address is the
pointer with the low 4 bits cleared. Rootkits register here because
they need to know when a process starts in order to inject into it or
hide it. EDRs register here too.
callbacks walks the four Psp*NotifyRoutine arrays and the two
bugcheck callback lists (KeBugCheckCallbackListHead,
KeBugCheckReasonCallbackListHead), and attributes each routine to a
module. A callback in no loaded module is critical in the
checklist. Registry callbacks (CmRegisterCallback) and object
callbacks (ObRegisterCallbacks) are not walked yet.
Timers and DPCs
A kernel timer can run a DPC routine periodically without any thread,
which makes it a quiet way to keep a foothold. timer_table walks
each CPU's _KPRCB.TimerTable, collects every queued _KTIMER, and
decodes its DPC pointer. Since Windows 7 x64 that pointer is obfuscated
with KiWaitNever and KiWaitAlways, and ramparser checks that the
decoded value lands on a real _KDPC before trusting it. Each timer
comes with its routine, owning module and period. A routine in no
module is critical. When no timer decodes on a given build, the
check says so instead of reporting clean.
Orphan system threads
Every thread of the System process starts at a routine passed to
PsCreateSystemThread, in ntoskrnl, hal or a driver. A rootkit that
copies its code into pool and then unlinks or unloads its driver
leaves threads whose start address is in no module. orphan_threads
checks both StartAddress and Win32StartAddress, and records the
first 16 bytes at the start address: a function prologue means live
code, zeros mean freed memory. Terminated threads are listed but not
judged, since their memory may have been reused. A driver that
unloaded without stopping its thread produces the same shape, so read
these hits next to the unloaded-driver list.
File-system minifilters
Minifilters see every file operation, which is why antivirus and
backup products register them, and why rootkits that hide files do
too. Using symbols from fltmgr.sys's own PDB, minifilters walks
FltGlobals.FrameList to each registered _FLT_FILTER and reports
its name, altitude, the operations it intercepts, and any callback
that lives outside the filter's own driver. Without the Filter Manager
symbols, the check reports that they are unavailable.
Hidden, unlinked and unloaded drivers
Hiding a driver usually means unlinking its entry from
PsLoadedModuleList, as DKOM does for processes. The allocations stay
in the pool, so the cross-view works the same way:
moduleswalksPsLoadedModuleList;modscanpool-scans forMmLd(_LDR_DATA_TABLE_ENTRY);driverscanpool-scans for_DRIVER_OBJECT;drivermoduleflags a driver object whoseDriverStartis in no listed module.
A module found by modscan but not by modules is reported as
hidden, except for the crash-dump stack copies (dump_*.sys) and
debugger transports, which are legitimately unlisted, and drivers in
the unloaded list, whose entries linger in freed pool.
unloadedmodules reads the MmUnloadedDrivers ring (name, range,
unload time). It is shown as information, not a finding: most entries
are normal, but it is where a load-use-unload of a vulnerable driver
leaves a trace. devicetree walks each driver's devices and their
attachment stacks, where a filter driver appears as an extra level on
top of a base device. The checklist also flags drivers loaded from
outside the Windows folders, and escalates when such a driver has no
embedded signature.
The integrity checklist
ramparser gathers these checks into one list with a status and the evidence behind each:
| Check | Source | Status on a hit |
|---|---|---|
| System call table untouched | ssdt | critical |
| Handlers not patched | inline_hooks | critical |
| Interrupt tables untouched | idt | critical |
| Callbacks in loaded drivers | callbacks | critical |
| Timers run known code | timer_table | critical |
| System threads in loaded drivers | orphan_threads | critical |
| Minifilters run their own code | minifilters | critical |
| IRP handlers not hijacked | driverirp | suspicious |
| No hidden drivers | modules vs modscan | suspicious |
| No hidden processes | psxview | critical |
| Every thread belongs to a listed process | thrdscan | suspicious |
| Recently unloaded drivers | unloadedmodules | info |
psxview belongs here because DKOM process hiding is a kernel
technique: it compares the active process list, the PspCidTable and
the pool scan, and flags a process missing from the active list but
seen by another view. thrdscan applies the same idea to threads:
_ETHREAD objects found in the pool whose process is not on the active
list. Threads of exited processes linger and are shown as context. One
still ready or running is flagged for review rather than as critical,
because a process ending during a live acquisition leaves the same
trace; the acquisition tool itself is labelled as such.
Reading the results
A clean checklist means these pointers and lists are consistent, not that the kernel is clean. A critical row is a starting point: check whether the same code shows up elsewhere (a callback and an orphan thread in the same pool range is a strong combination), then look for how it got there in the services, the unloaded-driver ring and the timeline.