> Windows Syscalls
ntoskrnl.exeT1562.001T1068T1070

NtUnloadDriver

Unloads a previously loaded kernel-mode driver — the BYOVD cleanup primitive.

Prototype

NTSTATUS NtUnloadDriver(
  PUNICODE_STRING DriverServiceName
);

Arguments

NameTypeDirDescription
DriverServiceNamePUNICODE_STRINGinNT path to the service key under \Registry\Machine\System\CurrentControlSet\Services\<Name>. Caller must hold SeLoadDriverPrivilege.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070x1A9win10-1507
Win10 16070x1B2win10-1607
Win10 17030x1B8win10-1703
Win10 17090x1BCwin10-1709
Win10 18030x1BEwin10-1803
Win10 18090x1BFwin10-1809
Win10 19030x1C0win10-1903
Win10 19090x1C0win10-1909
Win10 20040x1C6win10-2004
Win10 20H20x1C6win10-20h2
Win10 21H10x1C6win10-21h1
Win10 21H20x1C8win10-21h2
Win10 22H20x1C8win10-22h2
Win11 21H20x1D2win11-21h2
Win11 22H20x1D6win11-22h2
Win11 23H20x1D6win11-23h2
Win11 24H20x1D9win11-24h2
Server 20160x1B2winserver-2016
Server 20190x1BFwinserver-2019
Server 20220x1CEwinserver-2022
Server 20250x1D9winserver-2025

Kernel module

ntoskrnl.exeNtUnloadDriver

Related APIs

NtLoadDriverOpenSCManagerWControlServiceDeleteServiceRtlDeleteRegistryValue

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 ENDP

cBYOVD 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