NtQueryKey
Returns metadata about an open registry key — name, class, subkey/value counts, last-write time.
Prototype
NTSTATUS NtQueryKey( HANDLE KeyHandle, KEY_INFORMATION_CLASS KeyInformationClass, PVOID KeyInformation, ULONG Length, PULONG ResultLength );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| KeyHandle | HANDLE | in | Handle to an open key. Required access depends on KeyInformationClass; KEY_QUERY_VALUE suffices for most classes. |
| KeyInformationClass | KEY_INFORMATION_CLASS | in | Variant requested: KeyBasicInformation, KeyNodeInformation, KeyFullInformation, KeyNameInformation, KeyCachedInformation, KeyVirtualizationInformation, etc. |
| KeyInformation | PVOID | out | Caller-allocated buffer that receives the requested structure. |
| Length | ULONG | in | Size of KeyInformation in bytes. |
| ResultLength | PULONG | out | Receives the size actually returned (or required, on STATUS_BUFFER_TOO_SMALL). |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0x16 | win10-1507 |
| Win10 1607 | 0x16 | win10-1607 |
| Win10 1703 | 0x16 | win10-1703 |
| Win10 1709 | 0x16 | win10-1709 |
| Win10 1803 | 0x16 | win10-1803 |
| Win10 1809 | 0x16 | win10-1809 |
| Win10 1903 | 0x16 | win10-1903 |
| Win10 1909 | 0x16 | win10-1909 |
| Win10 2004 | 0x16 | win10-2004 |
| Win10 20H2 | 0x16 | win10-20h2 |
| Win10 21H1 | 0x16 | win10-21h1 |
| Win10 21H2 | 0x16 | win10-21h2 |
| Win10 22H2 | 0x16 | win10-22h2 |
| Win11 21H2 | 0x16 | win11-21h2 |
| Win11 22H2 | 0x16 | win11-22h2 |
| Win11 23H2 | 0x16 | win11-23h2 |
| Win11 24H2 | 0x16 | win11-24h2 |
| Server 2016 | 0x16 | winserver-2016 |
| Server 2019 | 0x16 | winserver-2019 |
| Server 2022 | 0x16 | winserver-2022 |
| Server 2025 | 0x16 | winserver-2025 |
Kernel module
Related APIs
Syscall stub
4C 8B D1 mov r10, rcx B8 16 00 00 00 mov eax, 0x16 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
Notably, NtQueryKey's SSN has been pinned at `0x16` from Windows 10 1507 through Windows 11 24H2 — one of the most stable numbers in the SSDT, which makes a hardcoded SSN safe across builds. The KEY_FULL_INFORMATION variant returns LastWriteTime as a FILETIME, the count of subkeys / values, and the maximum lengths of each — the same numbers `reg query` and Sysinternals `regjump` rely on.
Common malware usage
Three flavors of abuse. (1) *Forensic timestomp detection avoidance*: an operator can read LastWriteTime before tampering with a value, then use NtSetInformationKey (KeyWriteTimeInformation) to restore it. (2) *Enumeration tooling*: registry-walking implants pair NtEnumerateKey + NtQueryKey to recurse a subtree and identify high-value targets (autoruns, services, AppCompat shims). (3) *Sandbox fingerprinting*: query keys like `HKLM\HARDWARE\DESCRIPTION\System\BIOS` and inspect LastWriteTime to spot freshly-built analysis VMs.
Detection opportunities
Standalone NtQueryKey is high-volume background noise — Explorer alone calls it tens of thousands of times an hour. The valuable signal is the *write* that follows: KeyWriteTimeInformation set via NtSetInformationKey is rare in legitimate workloads and almost diagnostic of timestomp. EDRs hooking CmRegisterCallbackEx see RegNtPostQueryKey but most ignore it for cost reasons. ETW Microsoft-Windows-Kernel-Registry RegistryQueryKey is available but disabled by default. Hunting tip: process-handle inventory showing a non-Explorer, non-svchost process holding hundreds of open registry handles is a better lead than any single NtQueryKey call.
Direct syscall examples
cRead LastWriteTime for timestomp staging
// Capture the original LastWriteTime before tampering with a value,
// so it can be restored via NtSetInformationKey afterward.
KEY_BASIC_INFORMATION* kbi = (KEY_BASIC_INFORMATION*)buf;
ULONG ret = 0;
NTSTATUS st = NtQueryKey(hKey, KeyBasicInformation, kbi, sizeof(buf), &ret);
if (NT_SUCCESS(st)) {
g_savedWriteTime = kbi->LastWriteTime;
}asmx64 direct stub (stable SSN 0x16)
NtQueryKey PROC
mov r10, rcx
mov eax, 16h
syscall
ret
NtQueryKey ENDPrustFull information enumeration
// Cargo: ntapi = "0.4"
let mut needed: u32 = 0;
let status = unsafe {
NtQueryKey(h_key,
KeyFullInformation,
null_mut(),
0,
&mut needed)
};
assert_eq!(status, STATUS_BUFFER_TOO_SMALL as i32);
let mut buf = vec![0u8; needed as usize];
let status = unsafe {
NtQueryKey(h_key,
KeyFullInformation,
buf.as_mut_ptr() as _,
buf.len() as u32,
&mut needed)
};
assert!(status == 0);MITRE ATT&CK mappings
Last verified: 2026-05-20