Getting into the kernel
System Driver Replacement: Rootkits Inside Windows Drivers
How rootkits overwrite a Windows driver that already loads at boot, keep its service key, serve the clean copy to scanners, and how to check a host offline.
- Goal
- Getting into the kernel
- Layer
- Kernel
- Platforms
- Windows
- Also known as
- Driver infection, Driver file replacement
- Used by
- ZeroAccess
- Checked by
- Windows drivers
Overview
A rootkit does not need a service of its own to load at every boot: it can take the place of a driver Windows already loads. It overwrites the file of an existing driver service with its own driver and leaves the service key untouched. The service list, the start type and the image path stay exactly as Windows set them, so a review of driver services finds nothing new.
ZeroAccess is the documented case. Microsoft's Win32/Sirefef description states that "older variants of Sirefef try to replace a randomly-selected system driver with its own malicious copy", and that "the replaced driver will load each time you start your PC". To keep the machine working, the rootkit loads the original driver from a hidden copy; to stay invisible, it hands that clean copy to anyone who reads the file.
The technique belongs to the 32-bit era. The Prevx analysis of ZeroAccess notes that the sample it studied did not infect 64-bit Windows, where kernel code must be signed: an unsigned replacement for a Windows driver is refused there unless signature enforcement is weakened (see DSE tampering) or the replacement carries a valid signature of its own (see malicious drivers with valid signatures).
How it works
| Stage | What changes | Source |
|---|---|---|
| The victim | A random driver in System32\drivers. Microsoft's examples are afd.sys, i8042prt.sys, ipsec.sys, mrxsmb.sys, netbt.sys, raspppoe.sys and serial.sys, and its list is not complete. Prevx saw only drivers that do not start with the boot loader (Start above 0) | Microsoft; Prevx |
| Keep the original | The clean driver is saved in the rootkit's encrypted storage | Microsoft, Prevx |
| Overwrite | The file's body is replaced with the rootkit driver; Symantec adds that its length is set to that of the original | Symantec, Prevx |
| First load | Prevx saw a temporary service key named after the victim with a leading dot, such as .NdProxy, used to load the driver without a reboot | Prevx |
| Every boot | Windows loads the rootkit through the victim's own service key; the rootkit loads the original from its store and, in Symantec's words, "relinks the I/O database" so the device keeps working | Symantec |
| Hide the swap | A hook low in the disk stack returns the clean copy when the replaced file is read; Prevx saw writes to the file replaced with the infected copy, and Symantec a shutdown handler that repairs removed components | Microsoft, Prevx, Symantec |
The result defeats three common checks at once. The service is legitimate and old. The file has a Windows name in the Windows driver folder. And a hash or signature check run on the infected system reads the clean bytes, so it passes.
Replacing versus patching. Prevx contrasts ZeroAccess, which "totally overwrites the driver's body", with TDL3, which hijacked a random driver's entry point by overwriting less than 1 KB in its resource section. Both are infections of an existing driver; TDL3's successor is covered on bootkits.dev as TDL4.
How families use it
ZeroAccess used it in its kernel-mode versions. Microsoft, Prevx (April 2011) and Symantec (October 2013) agree on the swap, the hidden original and the disk-level hiding; they differ on details. Prevx saw only drivers with a Start value above 0 chosen, while Symantec writes "system start drivers"; Prevx and Symantec place the first hidden store in a file in System32\config, while Symantec and ESET describe later kernel-mode variants using a $NtUninstallKB folder, the store Microsoft describes (see encrypted hidden storage). In 2012 ZeroAccess dropped its kernel component, and Symantec and ESET describe it infecting services.exe instead: the same idea applied to a user-mode system binary, covered on the family page.
Traces it leaves
| Trace | Where | What to read |
|---|---|---|
| The replaced driver | C:\Windows\System32\drivers\<name>.sys, read from outside the running system | A hash that differs from the same file on a clean install of the same build; compile time, imports, version information or signature that do not fit the Windows build; Symantec notes the size matches the original |
| The victim's service key | SYSTEM hive, Services\<name> | Unchanged: the swap does not show here |
| A dot-prefixed service key | SYSTEM hive, Services\.<name> | Prevx's first-load key; it may not persist |
| The clean copy and payloads | The rootkit's encrypted store | See encrypted hidden storage |
| The disk hook | Memory | Prevx: the disk driver's DR0 device redirected to the rootkit's device; a shutdown notification routine pointing to unknown memory |
| Stopped security tools | Process and service state | Microsoft: Sirefef "tries to stop and delete any process that tries to access it" |
No 7045 event should be expected: no new service is installed through the Service Control Manager.
How to check a host
Offline, from a disk image or a collection made outside the running system:
- Hash every file in
System32\driversand compare it with the same files from a clean installation of the same Windows build and update level. A Windows driver whose hash matches nothing known is the finding. - For drivers that differ, read the PE header and version information: compile time, imports and company name are often inconsistent with neighbouring Windows drivers.
- Many Windows drivers are signed through catalog files rather than an embedded signature, so "no embedded signature" alone proves nothing; check the catalog signature on the image or compare hashes.
- Look for dot-prefixed driver service keys and for the storage described on the encrypted hidden storage page.
- From the recovery environment or another system,
sfccan check an offline Windows installation with/offbootdirand/offwindir(Microsoft)./scannowand/scanfilerepair as they go, so image the disk first.
Live, the running system is the wrong place to look: the hook serves the clean file to sfc, to Get-FileHash and to antivirus scans alike, and ZeroAccess stopped processes that touched it. Capture memory, then examine it elsewhere with Volatility 3:
vol -f host.raw windows.modules --dump
vol -f host.raw windows.devicetree
vol -f host.raw windows.callbacks
Compare the code of the module loaded from the victim's path with the clean file of the same build; look in the device tree for an unexpected device below the disk driver; and look in windows.callbacks for a shutdown notification that does not belong to a known driver.
What the checker looks for
The windrivers module reads every .sys file in the collection with its PE header, Authenticode signature and hashes, and lists the driver services of the SYSTEM hive. For a replaced Windows driver, read from outside the running system, the result depends on what the replacement looks like:
- a replacement with no embedded signature raises "An unsigned kernel driver", high severity because a service points to it, unless it also carries Microsoft's version resource and its name is on the checker's list of Windows driver names (Microsoft's example
ipsec.sysis not); - if it does, the module treats it like Windows' own catalog-signed drivers and raises only the informational "No embedded signature on a Windows driver", whose text says a tampered copy would look the same and asks for a hash comparison with a clean install;
- a signed driver whose bytes changed raises "The driver was changed after it was signed", and a broken signature "The driver's signature does not verify";
- the detail sheet shows hashes, compile time, imports and version information for the comparison the module does not make.
No path or name finding fires, since the name and folder are Windows', and the untouched service key raises no recency finding. A leftover dot-prefixed key would appear in the service list without a specific finding. The module holds no reference hashes of Windows builds and does not read catalogs. A collection taken through an infected running system may contain the clean copy the hook served.
Mitigation and recovery
- 64-bit Windows with signature enforcement and Secure Boot. The Prevx sample did not infect 64-bit Windows. Since Windows 10 version 1607, Windows does not load new kernel drivers that Microsoft's portal has not signed, apart from documented exceptions (Microsoft).
- Memory integrity (HVCI) and the vulnerable driver blocklist close the routes around signing.
- Fewer administrators. Prevx's dropper acquired privileges such as
SeDebugPrivilegeandSeTakeOwnershipPrivilegebefore overwriting the driver and suspending file protection; that needs an administrator.
Recovery: scan and repair from outside the running system, from trusted rescue media, and restore the replaced driver from known-good media of the same build. The rootkit downloaded further components into its hidden store, so its payload at a given time is unknown: prefer a rebuild to cleaning in place, and rotate the credentials used on the host.
Sources
Primary public reports, newest first.
- 2024-08-19Driver Signing PolicyMicrosoft
- 2022-10-19sfcMicrosoft
- 2013-10-04ZeroAccess IndepthSymantec
- 2012-09-26Defeating Anti-Forensics in Contemporary Complex ThreatsESET (Virus Bulletin 2012)
- 2012-04-12Win32/Sirefef threat descriptionMicrosoft
See also
Related techniques
- Encrypted hidden storageHiding
- Kernel hooks on Windows (inline, SSDT, IRP)Hiding
- Driver signature enforcement tamperingGetting into the kernel
- Malicious drivers with valid signaturesGetting into the kernel
Families that use it
- ZeroAccessWindows kernel rootkit