Persistence
Kernel Drivers (.sys, Driver Services, BYOVD)
Kernel drivers cheat sheet: driver services (Type 1/2), event 7045, DriverStore, setupapi.dev.log, Amcache and CodeIntegrity logs to hunt BYOVD and rootkits.
- Location
- C:\Windows\System32\drivers\*.sys
- Proves
- A kernel driver was installed or registered as a service, when, from which path, and whether Windows blocked or loaded it
- Timestamps
- Services key LastWrite (FILETIME, UTC), event 7045/4697 and CodeIntegrity times (UTC), setupapi.dev.log section times (local time), .sys file $SI/$FN times
- Retention
- Service keys and .sys files persist until removed; System.evtx and CodeIntegrity logs roll over (defaults of 20 MB and about 1 MB), setupapi.dev.log grows until trimmed
- Access
- Admin for live registry, logs and driver folder; SYSTEM hive, Amcache.hve and active .evtx are locked: raw copy or VSS
- Evidence of
- PersistenceAnti-forensics & deletion
- Type
- File / file system
- Windows
- XPVista / 78 / 8.11011
- KAPE target
- RegistryHivesSystemEventLogsAmcacheUSBDevicesLogs
- Velociraptor
- Windows.Triage.Targets:RegistryHivesSystemEventLogsAmcacheUSBDevicesLogs
Tools
Compare all toolsWhat it is
Kernel drivers are the Windows counterpart of Linux kernel modules: .sys PE files loaded into ring 0 by the Service Control Manager, the Plug and Play manager or a direct NtLoadDriver call. Legitimate hardware and security products need them; attackers use them for rootkits and, far more often today, for Bring Your Own Vulnerable Driver (BYOVD): they drop a signed but exploitable driver (for example RTCore64.sys, gdrv.sys, dbutil_2_3.sys, procexp152.sys) and use it to kill EDR processes or tamper with kernel memory. Every driver needs a service entry, a file on disk and a successful signature check, and each of those steps leaves traces.
Location
| Source | Path |
|---|---|
| Driver binaries | C:\Windows\System32\drivers\*.sys (but a driver can load from any path) |
| Service registration | HKLM\SYSTEM\<ControlSet00x>\Services\<name> with Type = 1 (kernel driver) or 2 (file system driver) |
| Service install events | System.evtx event 7045 (Service Control Manager); Security.evtx event 4697 if "Security System Extension" auditing is enabled |
| PnP driver packages | C:\Windows\System32\DriverStore\FileRepository\<inf>_<arch>_<hash>\, C:\Windows\INF\oem*.inf |
| PnP install log | C:\Windows\INF\setupapi.dev.log (Vista+) |
| Amcache | Amcache.hve, keys Root\InventoryDriverBinary and Root\InventoryDriverPackage (Windows 10+) |
| Signing enforcement | Microsoft-Windows-CodeIntegrity%4Operational.evtx |
| Vulnerable driver blocklist | C:\Windows\System32\CodeIntegrity\driversipolicy.p7b; toggle HKLM\SYSTEM\CurrentControlSet\Control\CI\Config\VulnerableDriverBlocklistEnable |
What it proves
- Registration: a Services key with
Type1 or 2 shows a driver was configured to load, with itsImagePathandStartmode (0 boot, 1 system, 2 automatic, 3 demand, 4 disabled). - Install time and account: event 7045 gives the service name, file path, "kernel mode driver" type and start type; 4697 adds the subject account.
- File identity: Amcache
InventoryDriverBinaryrecords the driver's SHA-1, signing status, company and version, even after the file is deleted. - Blocked loads: CodeIntegrity events show Windows refused a driver because of signing level or policy.
It does not prove the driver was actually loaded or exploited. A service created with sc create and started once may leave no load record in default logging. Confirm with memory (loaded modules), Sysmon event 6 (driver loaded) if Sysmon was deployed, or follow-on effects such as EDR services stopping.
Key fields
| Field | Meaning |
|---|---|
Type | 1 = kernel driver, 2 = file system driver (16/32 are user-mode services) |
Start | 0 boot, 1 system, 2 auto, 3 demand, 4 disabled |
ImagePath | Driver path, often \SystemRoot\System32\drivers\x.sys or System32\drivers\x.sys; any other folder is suspicious |
Group, Tag | Load-order group; rarely set by malicious drivers |
InventoryDriverBinary DriverId | SHA-1 of the file (with leading zero padding) |
DriverSigned, DriverCompany, Product, DriverLastWriteTime | Signing flag and version resources |
setupapi.dev.log >>> Section start | Timestamped PnP driver install sections with the INF name |
Timestamps
- Services key LastWrite (FILETIME, UTC): creation or last change of the service. Changing
StartorImagePathupdates it. - 7045 / 4697: UTC event times, the most reliable install anchor.
- setupapi.dev.log: section start and end times are written in local time; convert before timelining.
- .sys file $SI and $FN times in the $MFT: $FN is harder to timestomp and often exposes a dropped driver dated to look like an OS file.
- Amcache: key LastWrite reflects when the inventory ran, not necessarily when the driver arrived.
Retention and clearing
The registry key and file remain until removed. Attackers often delete the service and .sys after use: look for the deletion in the USN journal, for the orphaned Amcache entry and for the 7045 event, which survives service deletion until the System log rolls over (20 MB default). The CodeIntegrity Operational log is small (commonly about 1 MB), so blocked-load events can be overwritten quickly. Log clearing raises event 104 (System) or 1102 (Security).
Collection
KAPE RegistryHivesSystem, EventLogs, Amcache and USBDevicesLogs (which includes the setupapi logs), plus the driver files themselves:
driverquery /v /fo csv > E:\case\driverquery.csv
driverquery /si /fo csv > E:\case\driver_signing.csv
sc query type= driver state= all > E:\case\sc_drivers.txt
robocopy C:\Windows\System32\drivers E:\case\drivers *.sys /COPY:DAT
Get-WinEvent -FilterHashtable @{LogName='System'; Id=7045} |
Where-Object Message -match 'kernel mode driver|file system driver' |
Select-Object TimeCreated, Message | Export-Csv E:\case\7045_drivers.csv -NoTypeInformation
Get-WinEvent -LogName 'Microsoft-Windows-CodeIntegrity/Operational' |
Select-Object TimeCreated, Id, Message | Export-Csv E:\case\codeintegrity.csv -NoTypeInformation
Parsing tools
- Autoruns (Sysinternals): the Drivers tab with "Verify code signatures" and VirusTotal checks;
autorunsc -a d -h -s -cfor CSV. - sigcheck (
sigcheck -e -h -c C:\Windows\System32\drivers) for signer and hashes of every.sys. - Registry Explorer / RegRipper for offline SYSTEM hives (remember to pick the active control set).
- AmcacheParser for
InventoryDriverBinary. - EvtxECmd for 7045, 4697 and CodeIntegrity events.
- Volatility 3:
windows.modules,windows.modscanandwindows.driverscanto compare listed and carved modules and spot unlinked drivers; see the memory forensics guide.
Investigation tips
- Hash every non-Microsoft driver and match against the LOLDrivers project (loldrivers.io) and Microsoft's vulnerable driver blocklist. A signed driver from a gaming, overclocking or hardware vendor on a server is a classic BYOVD sign.
ImagePathin\Users\,\ProgramData\,\Windows\Temp\or a random short service name paired withType1 andStart3 is typical of tool-dropped drivers.- In CodeIntegrity/Operational, events such as 3033 (image did not meet signing level), 3077 (blocked by an enforced application control policy) and 3076 (audit mode) are the usual starting points; exact IDs and wording vary by build and policy, so read the message.
- The vulnerable driver blocklist is on by default on recent Windows 11 builds and with HVCI or Smart App Control, but coverage lags new drivers; check
VulnerableDriverBlocklistEnableand the policy version before concluding a driver could not load. - Correlate the driver install minute with the installed programs timeline, Windows Defender service stops and tamper protection events.
- Remember that PnP driver installs (USB devices, printers) also land in setupapi.dev.log and DriverStore: separate benign hardware noise from manual
pnputil /add-driverinstalls.
Related artifacts
- Windows ServicesWindows services cheat sheet: Services key values (ImagePath, Start, Type, ServiceDll), 7045 and 4697 install events, PsExec traces and pitfalls.
- Amcache.hveAmcache.hve cheat sheet: file and program inventory keys, SHA-1 hashes, PE metadata, timestamps and why an entry alone does not prove execution.
- PE files (Windows executables)PE file triage cheat sheet: hashes, imphash and Rich header, compile timestamp caveats, sections and entropy, version info, signatures, PDB paths and tools.
- Windows event logs (EVTX)Windows event log cheat sheet: EVTX locations, must-know event IDs for logons, processes, services and log clearing, retention, audit policy and parsing tools.
- Microsoft Defender logs and quarantineMicrosoft Defender forensics: Operational events 1116/1117/5001/5007, MPLog files, DetectionHistory, encrypted quarantine, exclusion keys and tampering traces.
- Sysmon Event LogSysmon cheat sheet: Operational log location, key event IDs, ProcessGuid and hash correlation, config in the registry, tampering signs and parsing tools.
- Installed Programs (Uninstall Keys, MSI, AppX)Installed programs cheat sheet: Uninstall keys, MsiInstaller events 1033/11707, cached MSIs, AppX packages, winget logs and Amcache to date software installs.
- USB device historyUSB forensics cheat sheet: USBSTOR and USB keys, serial numbers, first and last connection times, drive letters, volume serials, setupapi.dev.log and event IDs.
Glossary terms
- PersistenceMechanisms that let malware or an attacker survive reboots and logoffs, such as Run keys, services, scheduled tasks or WMI subscriptions.
- Anti-forensicsTechniques used to destroy, hide or falsify evidence, such as log clearing, timestomping, wiping and deleting shadow copies or the USN journal.
- ControlSet and CurrentControlSetThe numbered configuration sets in the SYSTEM hive; CurrentControlSet is a runtime link that does not exist in an offline hive file.
- Windows event IDThe number identifying an event type within a given provider; it only has meaning when paired with its provider and log channel.
- Registry key LastWrite timeThe single FILETIME stored in every registry key that records when the key or one of its values was last changed, in UTC.
Guides
- Hunting Windows Persistence: Registry, Tasks, WMI and MoreFind attacker persistence on Windows: Run keys, services, scheduled tasks, WMI, Winlogon, IFEO, COM hijacking and BITS, mapped to MITRE ATT&CK, with tools.
- Detecting Windows Anti-Forensics: What Survives the CleanupDetect log clearing, timestomping, secure deletion, VSS deletion and Defender tampering on Windows, mapped to MITRE ATT&CK, with the traces each one leaves.
- Windows Memory Forensics with Volatility 3: Practical GuideAcquire Windows RAM, use hiberfil and pagefile, and run a Volatility 3 workflow to find injected code, hidden processes and network activity.