NtLoadKey
Monta un archivo de hive de registro bajo una clave objetivo — el syscall detrás de la carga offline de SAM/SYSTEM.
Prototipo
NTSTATUS NtLoadKey( POBJECT_ATTRIBUTES KeyObjectAttributes, POBJECT_ATTRIBUTES FileObjectAttributes );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| KeyObjectAttributes | POBJECT_ATTRIBUTES | in | Ruta de registro destino bajo la cual se monta el hive (p. ej. \Registry\Machine\OFFLINE_SAM). |
| FileObjectAttributes | POBJECT_ATTRIBUTES | in | Ruta NT al archivo hive en disco (p. ej. \??\C:\Windows\System32\config\SAM). |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0xF6 | win10-1507 |
| Win10 1607 | 0xFB | win10-1607 |
| Win10 1703 | 0xFF | win10-1703 |
| Win10 1709 | 0x100 | win10-1709 |
| Win10 1803 | 0x101 | win10-1803 |
| Win10 1809 | 0x101 | win10-1809 |
| Win10 1903 | 0x102 | win10-1903 |
| Win10 1909 | 0x102 | win10-1909 |
| Win10 2004 | 0x107 | win10-2004 |
| Win10 20H2 | 0x107 | win10-20h2 |
| Win10 21H1 | 0x107 | win10-21h1 |
| Win10 21H2 | 0x108 | win10-21h2 |
| Win10 22H2 | 0x108 | win10-22h2 |
| Win11 21H2 | 0x10D | win11-21h2 |
| Win11 22H2 | 0x10E | win11-22h2 |
| Win11 23H2 | 0x10E | win11-23h2 |
| Win11 24H2 | 0x110 | win11-24h2 |
| Server 2016 | 0xFB | winserver-2016 |
| Server 2019 | 0x101 | winserver-2019 |
| Server 2022 | 0x10C | winserver-2022 |
| Server 2025 | 0x110 | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 10 01 00 00 mov eax, 0x110 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
Notas no documentadas
NtLoadKey monta un archivo hive de registro (formato binario en disco usado por `SAM`, `SECURITY`, `SYSTEM`, `SOFTWARE`, `NTUSER.DAT`) bajo una subclave arbitraria de `\Registry\Machine\` o `\Registry\User\`. El llamante debe poseer **SeRestorePrivilege** (y normalmente SeBackupPrivilege). NtLoadKey es la versión original de dos argumentos; NtLoadKey2 / NtLoadKeyEx añaden flags como `REG_HIVE_NO_RM` (sin registro transaccional / KTM) y parámetros explícitos de clase de confianza. El SSN deriva en cada feature update.
Uso común por malware
El abuso canónico es el **robo de credenciales offline**. Un atacante que ya obtuvo copia de los archivos hive `SAM`, `SYSTEM` y `SECURITY` (vía VSS, lectura NTFS en crudo o robo de backup) los remonta en otra máquina con NtLoadKey bajo una subclave elegida (a menudo `HKLM\OFFLINE_SAM`), luego lee los hashes cifrados y el material SYSKEY con APIs estándar de registro — exactamente el camino del modo offline de `secretsdump.py` de Impacket y de `lsadump::sam /system:SYSTEM /sam:SAM` de Mimikatz. Uso secundario: *persistencia sigilosa* — el malware deja un hive pequeño en una ubicación no estándar y lo monta en ejecución para ocultar configuración o equivalentes de Run keys a baseliners que solo auditan los hives conocidos.
Oportunidades de detección
Sysmon Event ID 12/13 se dispara en creación de objeto / set de valor de registro bajo puntos de montaje inusuales (`HKLM\OFFLINE*`, `HKLM\TEMP_*`). El proveedor ETW `Microsoft-Windows-Kernel-Registry` expone eventos de carga de hive con la clave de montaje y la ruta de origen. El ajuste de SeRestorePrivilege justo antes de un load es un indicador anticipado fuerte (Sysmon Event 4673 con lista de privilegios). La carga de archivos hive fuera de `%SystemRoot%\System32\config\` y `%UserProfile%\NTUSER.DAT` casi siempre merece alerta.
Ejemplos de syscalls directos
asmx64 direct stub (Win11 24H2)
; Direct syscall stub for NtLoadKey (SSN 0x110 on Win11 24H2 — drifts per build)
NtLoadKey PROC
mov r10, rcx ; KeyObjectAttributes
mov eax, 110h ; SSN
syscall
ret
NtLoadKey ENDPcOffline SAM credential extraction sketch
// Mount a stolen SAM hive offline and let LSAlib decrypt the NTLM hashes.
// Requires SeRestorePrivilege + SeBackupPrivilege.
#include <windows.h>
#include <winternl.h>
static void EnablePriv(LPCWSTR p) {
HANDLE tok; TOKEN_PRIVILEGES tp = {0};
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &tok);
LookupPrivilegeValueW(NULL, p, &tp.Privileges[0].Luid);
tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(tok, FALSE, &tp, 0, NULL, NULL);
CloseHandle(tok);
}
int main(void) {
EnablePriv(SE_RESTORE_NAME);
EnablePriv(SE_BACKUP_NAME);
// RegLoadKeyW is the documented wrapper that ends at NtLoadKey under the hood.
LONG s = RegLoadKeyW(HKEY_LOCAL_MACHINE, L"OFFLINE_SAM",
L"C:\\stolen\\SAM");
if (s == ERROR_SUCCESS) {
// Now HKLM\OFFLINE_SAM\SAM\Domains\Account\Users\... is readable.
RegUnLoadKeyW(HKEY_LOCAL_MACHINE, L"OFFLINE_SAM");
}
return s;
}rustDirect NtLoadKey via ntapi
// Cargo: ntapi = "0.4", winapi = { version = "0.3", features = ["ntdef"] }
use ntapi::ntregapi::NtLoadKey;
use ntapi::ntrtl::{RtlInitUnicodeString};
use winapi::shared::ntdef::{OBJECT_ATTRIBUTES, UNICODE_STRING, OBJ_CASE_INSENSITIVE};
unsafe fn load_offline_hive(mount: &str, file: &str) -> i32 {
let mut k_us: UNICODE_STRING = std::mem::zeroed();
let mut f_us: UNICODE_STRING = std::mem::zeroed();
let mw: Vec<u16> = mount.encode_utf16().chain([0]).collect();
let fw: Vec<u16> = file.encode_utf16().chain([0]).collect();
RtlInitUnicodeString(&mut k_us, mw.as_ptr());
RtlInitUnicodeString(&mut f_us, fw.as_ptr());
let mut k_oa: OBJECT_ATTRIBUTES = std::mem::zeroed();
let mut f_oa: OBJECT_ATTRIBUTES = std::mem::zeroed();
k_oa.Length = std::mem::size_of::<OBJECT_ATTRIBUTES>() as u32;
k_oa.ObjectName = &mut k_us; k_oa.Attributes = OBJ_CASE_INSENSITIVE;
f_oa.Length = std::mem::size_of::<OBJECT_ATTRIBUTES>() as u32;
f_oa.ObjectName = &mut f_us; f_oa.Attributes = OBJ_CASE_INSENSITIVE;
NtLoadKey(&mut k_oa, &mut f_oa)
}Mapeos MITRE ATT&CK
Last verified: 2026-05-20