NtUnloadDriver
Unloads a previously loaded kernel-mode driver — the BYOVD cleanup primitive.
Prototype
NTSTATUS NtUnloadDriver( PUNICODE_STRING DriverServiceName );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| DriverServiceName | PUNICODE_STRING | in | NT path to the service key under \Registry\Machine\System\CurrentControlSet\Services\<Name>. Caller must hold SeLoadDriverPrivilege. |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0x1A9 | win10-1507 |
| Win10 1607 | 0x1B2 | win10-1607 |
| Win10 1703 | 0x1B8 | win10-1703 |
| Win10 1709 | 0x1BC | win10-1709 |
| Win10 1803 | 0x1BE | win10-1803 |
| Win10 1809 | 0x1BF | win10-1809 |
| Win10 1903 | 0x1C0 | win10-1903 |
| Win10 1909 | 0x1C0 | win10-1909 |
| Win10 2004 | 0x1C6 | win10-2004 |
| Win10 20H2 | 0x1C6 | win10-20h2 |
| Win10 21H1 | 0x1C6 | win10-21h1 |
| Win10 21H2 | 0x1C8 | win10-21h2 |
| Win10 22H2 | 0x1C8 | win10-22h2 |
| Win11 21H2 | 0x1D2 | win11-21h2 |
| Win11 22H2 | 0x1D6 | win11-22h2 |
| Win11 23H2 | 0x1D6 | win11-23h2 |
| Win11 24H2 | 0x1D9 | win11-24h2 |
| Server 2016 | 0x1B2 | winserver-2016 |
| Server 2019 | 0x1BF | winserver-2019 |
| Server 2022 | 0x1CE | winserver-2022 |
| Server 2025 | 0x1D9 | winserver-2025 |
Kernel module
Related APIs
Syscall stub
4C 8B D1 mov r10, rcx B8 D9 01 00 00 mov eax, 0x1D9 F6 04 25 08 03 FE 7F 01 test byte ptr [0x7FFE0308], 1 75 03 jne short +3 0F 05 syscall C3 ret CD 2E int 2Eh C3 ret
Undocumented notes
NtUnloadDriver is the counterpart of NtLoadDriver. Given an NT path to a service key, it asks the I/O manager to call the driver's `DriverUnload` routine and remove its `DRIVER_OBJECT` from `\Driver`. The driver image is unmapped from kernel address space and the corresponding `MmUnloadedDrivers` slot is filled (the kernel keeps a small ring buffer of the last ~50 unloaded driver names — `!drvobj /unloaded` in WinDbg). NtUnloadDriver requires the caller token to hold `SeLoadDriverPrivilege`, which Administrators have by default but is rarely held by service accounts.
Common malware usage
The defining call in **BYOVD (Bring Your Own Vulnerable Driver) cleanup**. The classic kill chain is: 1) drop a signed-but-vulnerable driver from a hardcoded list (RTCore64, gdrv, mhyprot2, kArmor, etc.); 2) NtLoadDriver to create the service and load it; 3) IOCTL into the driver to disable EDR callbacks, terminate-protected processes, write to MSRs or arbitrary kernel memory; 4) NtUnloadDriver to remove the driver from the live system and reduce forensic footprint. Families: EDRKillShifter (RansomHub affiliate tooling), Spyboy's Terminator, AvosLocker's BYOVD module, KillAV variants, BlackByte's RTCore64 abuse, Lazarus's FudModule rootkit loader. The unload itself is *required* — leaving the vulnerable driver loaded is a loud detection signal for kernel-image enumeration.
Detection opportunities
Critical: most public BYOVD telemetry focuses on the *load* side (`Microsoft-Windows-Kernel-PnP` event 400, Sysmon Event ID 6) — the *unload* side has historically been under-instrumented. Detection relies on correlation: Sysmon Event 6 logs the prior load, then absence of the driver image in subsequent `Get-WindowsDriver` / `driverquery` / kernel-callback enumeration is the only delta. `Microsoft-Windows-Kernel-PnP` event 410 fires on service stop. Microsoft Defender vulnerable-driver blocklist (`DriverSiPolicy.p7b`) prevents the load entirely on enabled systems — when present, the BYOVD path fails at NtLoadDriver and NtUnloadDriver is never reached. ELAM and HVCI also bite the load, not the unload.
Direct syscall examples
asmx64 direct stub
; Direct syscall stub for NtUnloadDriver (SSN 0x1D9 on Win11 24H2)
NtUnloadDriver PROC
mov r10, rcx ; DriverServiceName
mov eax, 1D9h ; SSN — verify per-build
syscall
ret
NtUnloadDriver ENDPcBYOVD cleanup after exploitation
// Final stage of a BYOVD chain: tear down the vulnerable driver and its service key.
#include <windows.h>
#include <winternl.h>
typedef NTSTATUS (NTAPI *pNtUnloadDriver)(PUNICODE_STRING);
BOOL BYOVDCleanup(PCWSTR ntServicePath /* L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Vuln" */) {
UNICODE_STRING us;
RtlInitUnicodeString(&us, ntServicePath);
pNtUnloadDriver fn = (pNtUnloadDriver)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtUnloadDriver");
NTSTATUS s = fn(&us);
// Best practice: also delete the service-key and the .sys on disk to slim forensics.
// (omitted) RegDeleteTreeW + DeleteFileW
return s >= 0;
}rustEDR-kill teardown
// Cargo: ntapi = "0.4", widestring = "1"
use ntapi::ntioapi::NtUnloadDriver;
use ntapi::ntrtl::RtlInitUnicodeString;
use winapi::shared::ntdef::UNICODE_STRING;
use widestring::U16CString;
unsafe fn unload(svc_nt_path: &str) -> i32 {
let w = U16CString::from_str(svc_nt_path).unwrap();
let mut us: UNICODE_STRING = std::mem::zeroed();
RtlInitUnicodeString(&mut us, w.as_ptr());
NtUnloadDriver(&mut us)
}MITRE ATT&CK mappings
Last verified: 2026-05-20