> Windows Syscalls
ntoskrnl.exeT1547.001T1546.012T1112

NtCreateKey

Erstellt oder öffnet einen Registrierungsschlüssel — die Kernel-Primitive hinter jeder Registry-basierten Persistenz.

Prototyp

NTSTATUS NtCreateKey(
  PHANDLE            KeyHandle,
  ACCESS_MASK        DesiredAccess,
  POBJECT_ATTRIBUTES ObjectAttributes,
  ULONG              TitleIndex,
  PUNICODE_STRING    Class,
  ULONG              CreateOptions,
  PULONG             Disposition
);

Argumente

NameTypeDirDescription
KeyHandlePHANDLEoutErhält das Handle auf den erstellten oder geöffneten Schlüssel.
DesiredAccessACCESS_MASKinZugriffsmaske, z. B. KEY_WRITE, KEY_ALL_ACCESS, KEY_SET_VALUE.
ObjectAttributesPOBJECT_ATTRIBUTESinOBJECT_ATTRIBUTES mit dem Registrierungspfad (z. B. \Registry\Machine\Software\...).
TitleIndexULONGinReserviert. Muss null sein.
ClassPUNICODE_STRINGinOptionaler Klassenname für den Schlüssel. Üblicherweise NULL.
CreateOptionsULONGinFlags, z. B. REG_OPTION_NON_VOLATILE, REG_OPTION_VOLATILE, REG_OPTION_CREATE_LINK.
DispositionPULONGoutErhält REG_CREATED_NEW_KEY oder REG_OPENED_EXISTING_KEY. Darf NULL sein.

Syscall-IDs pro Windows-Version

Windows-VersionSyscall-IDBuild
Win10 15070x1Dwin10-1507
Win10 16070x1Dwin10-1607
Win10 17030x1Dwin10-1703
Win10 17090x1Dwin10-1709
Win10 18030x1Dwin10-1803
Win10 18090x1Dwin10-1809
Win10 19030x1Dwin10-1903
Win10 19090x1Dwin10-1909
Win10 20040x1Dwin10-2004
Win10 20H20x1Dwin10-20h2
Win10 21H10x1Dwin10-21h1
Win10 21H20x1Dwin10-21h2
Win10 22H20x1Dwin10-22h2
Win11 21H20x1Dwin11-21h2
Win11 22H20x1Dwin11-22h2
Win11 23H20x1Dwin11-23h2
Win11 24H20x1Dwin11-24h2
Server 20160x1Dwinserver-2016
Server 20190x1Dwinserver-2019
Server 20220x1Dwinserver-2022
Server 20250x1Dwinserver-2025

Kernel-Modul

ntoskrnl.exeNtCreateKey

Verwandte APIs

RegCreateKeyExWRegOpenKeyExWNtOpenKeyNtOpenKeyExNtSetValueKeyNtDeleteKey

Syscall-Stub

4C 8B D1            mov r10, rcx
B8 1D 00 00 00      mov eax, 0x1D
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

Undokumentierte Hinweise

`0x1D` ist die SSN seit Windows 7 und bis Win11 24H2 unverändert — eine der zuverlässigsten hartkodierten Nummern. Der Aufruf läuft über CmpCallCallBacksEx und CmCreateKey im Configuration Manager (CM_KEY_BODY-Allokation). Da der ObjectAttributes-Pfad im NT-Objektnamensraum (`\Registry\Machine\...`, `\Registry\User\<SID>\...`) geparst wird, nutzen Implants ihn direkt, um die Pfadübersetzungs-Hooks der EDRs auf advapi32!RegCreateKeyEx zu umgehen.

Häufige Malware-Nutzung

Persistenz ist der dominante Anwendungsfall. Angreifer legen Unterschlüssel unter `HKLM\Software\Microsoft\Windows\CurrentVersion\Run`, `HKCU\...\Run`, `HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon` (Shell/Userinit/AppInit_DLLs), `HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<ziel.exe>` (Debugger-Value-Hijack) und `HKLM\System\CurrentControlSet\Services\<name>` für Dienst-Persistenz an. Direkter Aufruf von NtCreateKey umgeht alle User-Mode-Hooks auf advapi32 und vermeidet Artefakte vom Typ CreateRemoteThread.

Erkennungs­möglichkeiten

Der ETW-Provider Microsoft-Windows-Kernel-Registry (`{70EB4F03-C1DE-4F73-A051-33D13D5413BD}`) feuert `EventCreateKey` (Opcode 10) inklusive vollem Pfad und Erzeuger-PID — die hochwertigste Detection-Quelle und vom User-Mode aus nicht zu verbergen. Sysmon Event ID 12 (RegistryEvent: CreateKey / DeleteKey) erfasst dasselbe auf Endpunkten ohne Defender for Endpoint. Besonders zu jagen: Autostart-Keys, IFEO-Unterschlüssel auf gängige LOLBins (`mmc.exe`, `taskmgr.exe`, `osk.exe`) und neue `Services\`-Einträge mit ImagePath außerhalb von `\SystemRoot\System32\`. EDR-Hooks auf advapi32!RegCreateKeyEx werden leicht umgangen; Kernel-ETW nicht.

Direkte Syscall-Beispiele

cCreate or open HKCU Run subkey

// Open / create HKCU\Software\Microsoft\Windows\CurrentVersion\Run via Nt path.
// Pair with NtSetValueKey to drop a persistence entry.
UNICODE_STRING path;
RtlInitUnicodeString(&path,
    L"\\Registry\\User\\<SID>\\Software\\Microsoft\\Windows\\CurrentVersion\\Run");

OBJECT_ATTRIBUTES oa;
InitializeObjectAttributes(&oa, &path, OBJ_CASE_INSENSITIVE, NULL, NULL);

HANDLE hKey = NULL;
ULONG disposition = 0;
NTSTATUS s = NtCreateKey(&hKey, KEY_SET_VALUE, &oa,
                        0, NULL, REG_OPTION_NON_VOLATILE, &disposition);

asmDirect stub (SSN 0x1D)

NtCreateKey PROC
    mov  r10, rcx
    mov  eax, 1Dh
    syscall
    ret
NtCreateKey ENDP

rustntapi crate persistence helper

// Cargo: ntapi = "0.4", winapi = { version = "0.3", features = ["winnt"] }
use ntapi::ntregapi::NtCreateKey;
use ntapi::ntrtl::RtlInitUnicodeString;
use winapi::shared::ntdef::{OBJECT_ATTRIBUTES, OBJ_CASE_INSENSITIVE, UNICODE_STRING};
use winapi::um::winnt::{KEY_SET_VALUE, REG_OPTION_NON_VOLATILE};
use std::ptr::null_mut;

pub unsafe fn open_run_key(sid_path: *const u16) -> *mut core::ffi::c_void {
    let mut us: UNICODE_STRING = core::mem::zeroed();
    RtlInitUnicodeString(&mut us, sid_path);
    let mut oa = OBJECT_ATTRIBUTES {
        Length: core::mem::size_of::<OBJECT_ATTRIBUTES>() as u32,
        RootDirectory: null_mut(),
        ObjectName: &mut us,
        Attributes: OBJ_CASE_INSENSITIVE,
        SecurityDescriptor: null_mut(),
        SecurityQualityOfService: null_mut(),
    };
    let mut h = null_mut();
    let mut disp = 0u32;
    NtCreateKey(&mut h, KEY_SET_VALUE, &mut oa, 0,
                null_mut(), REG_OPTION_NON_VOLATILE, &mut disp);
    h
}

MITRE ATT&CK-Mappings

Last verified: 2026-05-20