At boot
Kernel Drivers: Windows Persistence in Kernel Mode
How kernel drivers load at boot through the Services key, how attackers use rootkits and vulnerable signed drivers, and how to find and remove a bad driver.
- Tactics
- Persistence, Privilege escalation, Defense evasion
- Runs
- At boot
- Set up by
- Administrators
- Locations
- HKLM\SYSTEM\CurrentControlSet\Services
- C:\Windows\System32\drivers
- C:\Windows\System32\DriverStore\FileRepository
- HKLM\SYSTEM\CurrentControlSet\Control\CI\Config
- HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity
How it works
A driver is registered like a service, as a subkey of HKLM\SYSTEM\CurrentControlSet\Services, with a Type of 1 (kernel driver) or 2 (file system driver, which includes minifilters). ImagePath names the .sys file, usually as \SystemRoot\System32\drivers\x.sys, System32\drivers\x.sys or \??\C:\…\x.sys. Without ImagePath, Windows loads System32\drivers\<name>.sys. Start decides who loads it:
Start | Loaded by |
|---|---|
| 0 Boot | The boot loader (winload), with the kernel, in the order of Group and ServiceGroupOrder |
| 1 System | The kernel's I/O manager during initialisation |
| 2 Automatic | The Service Control Manager at boot |
| 3 Manual | Plug and Play when its device appears, or an explicit load (sc start, fltmc load, NtLoadDriver) |
| 4 Disabled | Nobody |
Driver code runs in ring 0. It can read and change any memory, hide files, processes and registry keys, and stop security products. That is why loading one needs SeLoadDriverPrivilege, held by administrators.
Signing is the main barrier. 64-bit Windows has required signed kernel code since Vista. From Windows 10 1607, on new installations with Secure Boot on, new drivers must be signed by Microsoft through the Windows Hardware Dev Center; drivers cross-signed with a certificate issued before 29 July 2015 still load. Test signing mode (bcdedit /set testsigning on) accepts test-signed drivers. Microsoft's vulnerable driver blocklist, on by default since the Windows 11 2022 update and enforced whenever memory integrity (HVCI) is on, refuses known vulnerable drivers. Since Windows 8, an Early Launch Antimalware (ELAM) driver from the installed antivirus can classify boot-start drivers before they start.
Where it lives
| Location | What | Who can write it |
|---|---|---|
HKLM\SYSTEM\CurrentControlSet\Services\<name> | Type, Start, ImagePath, Group, Tag, ErrorControl; minifilters add an Instances subkey with an altitude | Administrators, SYSTEM |
C:\Windows\System32\drivers\*.sys | Driver files | Administrators and installers; Windows' own files belong to TrustedInstaller |
C:\Windows\System32\DriverStore\FileRepository\<package>\ | Packages installed from an INF; many current drivers load from here | Windows, through Plug and Play installation |
HKLM\SYSTEM\CurrentControlSet\Control\CI\Config | VulnerableDriverBlocklistEnable | Administrators |
HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity | Enabled (memory integrity) | Administrators |
There is no per-user variant. A stock Windows 10 or 11 system has hundreds of driver keys: Windows' own and those of the hardware vendors. Most of them sit in System32\drivers or the DriverStore and are signed, by Microsoft or through Microsoft's hardware program.
How attackers use it
Kernel rootkits register a boot or system start driver so they load before most defences, then hide their own key and files. Turla's Snake (Uroburos) rootkit is a documented case: it loaded an old, vulnerable VirtualBox driver to turn off driver signature enforcement before loading its own.
That pattern, "bring your own vulnerable driver" (BYOVD), is now common. The attacker installs a legitimately signed driver with a known flaw and uses it to run code in the kernel or to kill security products. ESET reported Lazarus using Dell's dbutil_2_3.sys this way, and Sophos reported BlackByte ransomware abusing MSI Afterburner's RTCore64.sys. Other malicious drivers carried valid signatures outright: in 2021 Microsoft confirmed that the Netfilter rootkit had been signed through its own hardware program.
Creating the key is one line:
sc.exe create kbdfltr type= kernel start= auto binPath= C:\Windows\System32\drivers\kbdfltr.sys
Tooling can also write the key and call NtLoadDriver directly. A driver loaded that way and then deleted, key and file, stays in memory until reboot: evasion rather than persistence. For persistence the driver keeps a key with Start 0 to 2, usually under a name and description that look like a hardware or Windows component.
How to check a host
On a live machine:
driverquery /v /fo csv > drivers.csv
Get-CimInstance Win32_SystemDriver | Select-Object Name, State, StartMode, PathName
fltmc filters
sc.exe qc kbdfltr
Get-AuthenticodeSignature C:\Windows\System32\drivers\kbdfltr.sys | Format-List
sigcheck.exe -accepteula -u -e C:\Windows\System32\drivers
autorunsc.exe -accepteula -a s -h -s -c > services-drivers.csv
bcdedit /enum "{current}"
Look at the signer (a person or small company, a revoked or expired certificate, or none), at drivers outside System32\drivers and the DriverStore, and at known vulnerable drivers: compare the hashes with Microsoft's recommended driver block rules or the community LOLDrivers list. bcdedit shows whether testsigning or nointegritychecks is set.
A rootkit controls what the running system reports. When one is suspected, also examine the disk from a clean environment (WinPE or an image).
Offline: the SYSTEM hive (Select\Current, then Services), the key's last-write time, the .sys file times, C:\Windows\INF\setupapi.dev.log for Plug and Play installations, and Amcache, which records driver binaries on Windows 10 and 11.
Events: System log 7045 records a new kernel driver service like any other, and Security log 4697 does too when "Audit Security System Extension" is on. Sysmon event 6 logs each driver load with its hashes and signature. A key written straight into the registry leaves only registry auditing (4657, Sysmon 12 and 13).
What Windows Persistence flags
Drivers come from the same reader as Windows services: every subkey of Services in the current control set with a Type of 1, 2 or 8 (a file system recognizer). A driver without ImagePath is listed with the file Windows then loads, \SystemRoot\System32\drivers\<name>.sys. The entry shows the start type, type and group. \SystemRoot\, System32\ and \??\ forms are turned into plain paths. Start 0 to 2 counts as a boot trigger, 3 as on demand (an event with a TriggerInfo subkey), and Start 4 marks the entry disabled.
Flags on a driver:
- The path rules, in system context: System-wide autostart from a writable folder, Runs from a temporary or public folder, Runs from a network share, Windows program name in the wrong place, Name one letter away from a Windows program and Machine-made name.
- Runs a program when the service fails when
FailureCommandis set and a recovery action runs it; information only otherwise. - Across mechanisms: Written date (the key changed in the 7 days before the newest time seen for that host), Inside a Defender exclusion (exclusion) and program also runs from mechanisms.
The unquoted-path check is not applied to drivers. The origin comes from the path alone: a driver in System32\drivers or the DriverStore counts as Windows. "Hide Windows entries" hides such a driver unless something flags it, and recency is not checked for it, so a malicious driver dropped into System32\drivers only shows with the filter off.
Limits: the tool reads registrations, not loaded drivers, so a driver loaded and then unregistered is invisible. It does not check signatures or hashes, and has no list of vulnerable drivers. It does not read bcdedit settings, memory integrity or the blocklist switch. Other control sets are not read.
Cleaning up
- Confirm what it is before touching it: vendor, signer, the device it serves. Disabling a boot-start storage or file system driver can leave Windows unable to start.
- Preserve:
reg export HKLM\SYSTEM\CurrentControlSet\Services\kbdfltr drv.reg, copy and hash the.sysfile. - Disable it with
sc.exe config kbdfltr start= disabled, or remove it withsc.exe delete kbdfltr; many drivers cannot be stopped, so reboot. Then delete the file. Keep the export to restore from the recovery environment if the machine no longer starts. - Restore what the driver may have changed:
bcdedit /set testsigning off, memory integrity, the blocklist, Defender and EDR settings (see Defender exclusions), and look for the program that installed it among services and scheduled tasks. - Kernel code had full control of the machine and its memory, including credentials in
lsass.exe. Treat the host as compromised: rotate the credentials used on it and prefer a rebuild.
See also
Related techniques
On Windows Forensics
The artifacts behind this technique, in the Windows Forensics reference: