> Windows Syscalls
ntoskrnl.exeT1003.002T1106

NtLoadKey2

Loads a registry hive into the configuration tree with a 2-flag wrapper around NtLoadKey.

Prototype

NTSTATUS NtLoadKey2(
  POBJECT_ATTRIBUTES TargetKey,
  POBJECT_ATTRIBUTES SourceFile,
  ULONG              Flags
);

Arguments

NameTypeDirDescription
TargetKeyPOBJECT_ATTRIBUTESinObject attributes describing the mount point key (e.g. \Registry\User\TempHive).
SourceFilePOBJECT_ATTRIBUTESinObject attributes pointing at the on-disk hive file (NT path, e.g. \??\C:\Windows\System32\config\SAM).
FlagsULONGinREG_NO_LAZY_FLUSH (0x4) is the canonical value; other bits are largely ignored on the 2-arg wrapper.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070xF7win10-1507
Win10 16070xFCwin10-1607
Win10 17030x100win10-1703
Win10 17090x101win10-1709
Win10 18030x102win10-1803
Win10 18090x102win10-1809
Win10 19030x103win10-1903
Win10 19090x103win10-1909
Win10 20040x108win10-2004
Win10 20H20x108win10-20h2
Win10 21H10x108win10-21h1
Win10 21H20x109win10-21h2
Win10 22H20x109win10-22h2
Win11 21H20x10Ewin11-21h2
Win11 22H20x10Fwin11-22h2
Win11 23H20x10Fwin11-23h2
Win11 24H20x111win11-24h2
Server 20160xFCwinserver-2016
Server 20190x102winserver-2019
Server 20220x10Dwinserver-2022
Server 20250x111winserver-2025

Kernel module

ntoskrnl.exeNtLoadKey2

Related APIs

RegLoadKeyWNtLoadKeyNtLoadKeyExNtUnloadKeyNtUnloadKey2NtSaveKey

Syscall stub

4C 8B D1            mov r10, rcx
B8 11 01 00 00      mov eax, 0x111
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

`NtLoadKey2` is a thin, deprecated wrapper introduced alongside Windows 2000 / XP that forwards to the same kernel path as `NtLoadKey`/`NtLoadKeyEx` (`CmLoadKey` inside `ntoskrnl.exe`). It only accepts the legacy `Flags` argument and lacks the modern `TrustClassKey`, `Event`, `TokenHandle` and `IoPriority` parameters of `NtLoadKeyEx`. Microsoft considers it superseded but the export is still present in every shipping ntdll up to and including 24H2, and the SSN still maps to a real handler — exactly the kind of deprecated-but-callable corner attackers prefer because hooks and EDR rules often forget it.

Common malware usage

Offline credential-dump tradecraft: `secretsdump`-style attackers copy a victim hive (SAM, SYSTEM, SECURITY) via VSS / raw NTFS, then mount it under an arbitrary key with `NtLoadKey`/`NtLoadKey2` to enumerate it through normal `RegOpenKeyEx` / `NtOpenKey` APIs without parsing the binary hive format themselves. `NtLoadKey2` is reached when an operator deliberately swaps the obvious `RegLoadKeyW` (which routes to `NtLoadKeyEx`) for the older variant to dodge naive hook lists. Requires `SeRestorePrivilege` and `SeBackupPrivilege` — i.e. local administrator.

Detection opportunities

Any call to `NtLoadKey*` from a non-Microsoft binary is high-signal because the legitimate consumers are essentially `regedit.exe`, `reg.exe`, `appidcertstorecheck.exe`, the user-profile loader and a handful of imaging tools. Sysmon Event ID 12/13/14 (Registry) does **not** fire for hive loads themselves — the kernel only emits ETW via the `Microsoft-Windows-Kernel-Registry` provider (event ID 9 = HiveLoaded). EDRs that track privileged-token enable-events for `SeRestorePrivilege` followed by hive opens of `\??\...\config\SAM` paths catch the canonical SAM-dump pattern; the file open is usually the better tripwire than the syscall itself.

Direct syscall examples

asmx64 direct stub (Win11 24H2)

; Direct syscall stub for NtLoadKey2 (SSN 0x111 on Win11 24H2)
NtLoadKey2 PROC
    mov  r10, rcx          ; TargetKey
    mov  eax, 111h         ; SSN — drifts per build
    syscall
    ret
NtLoadKey2 ENDP

cMount an offline SAM hive grabbed via VSS

// Requires SeRestorePrivilege + SeBackupPrivilege enabled on the caller.
#include <windows.h>
#include <winternl.h>

typedef NTSTATUS (NTAPI *pNtLoadKey2)(POBJECT_ATTRIBUTES, POBJECT_ATTRIBUTES, ULONG);

NTSTATUS MountHive(LPCWSTR ntMountPath, LPCWSTR ntHiveFile) {
    UNICODE_STRING uMount, uFile;
    OBJECT_ATTRIBUTES oaMount, oaFile;
    RtlInitUnicodeString(&uMount, ntMountPath);   // e.g. L"\\REGISTRY\\USER\\OfflineSAM"
    RtlInitUnicodeString(&uFile,  ntHiveFile);    // e.g. L"\\??\\C:\\temp\\SAM_copy"
    InitializeObjectAttributes(&oaMount, &uMount, OBJ_CASE_INSENSITIVE, NULL, NULL);
    InitializeObjectAttributes(&oaFile,  &uFile,  OBJ_CASE_INSENSITIVE, NULL, NULL);
    pNtLoadKey2 fn = (pNtLoadKey2)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtLoadKey2");
    return fn(&oaMount, &oaFile, 0x4 /* REG_NO_LAZY_FLUSH */);
}

MITRE ATT&CK mappings

Last verified: 2026-05-20