NtLoadEnclaveData
Copies a page-aligned buffer (code or data) from VTL0 host memory into an enclave's VTL1 range before initialisation.
Prototype
NTSTATUS NtLoadEnclaveData( HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, SIZE_T BufferSize, ULONG Protect, PVOID PageInformation, ULONG PageInformationLength, PSIZE_T NumberOfBytesWritten, PULONG EnclaveError );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| ProcessHandle | HANDLE | in | Handle to the host process owning the enclave. Typically NtCurrentProcess(). |
| BaseAddress | PVOID | in | Target VTL1 address inside the enclave where Buffer is copied. Must be page-aligned and inside the enclave's reserved range. |
| Buffer | PVOID | in | Source VTL0 buffer (the mapped enclave image or a data page). Page-aligned. |
| BufferSize | SIZE_T | in | Number of bytes to copy. Must be a multiple of the page size. |
| Protect | ULONG | in | Final page protection inside the enclave (PAGE_READONLY, PAGE_READWRITE, PAGE_EXECUTE_READ — never WRITE+EXECUTE on VBS). |
| PageInformation | PVOID | in | Type-specific descriptor: ENCLAVE_LOAD_DATA_SGX (SECINFO + EADD flags) or ENCLAVE_LOAD_DATA_VBS (page type). |
| PageInformationLength | ULONG | in | Size in bytes of the PageInformation descriptor. |
| NumberOfBytesWritten | PSIZE_T | out | Receives the number of bytes actually written into the enclave (normally equal to BufferSize on success). |
| EnclaveError | PULONG | out | Receives the SGX EADD or securekernel-specific error code on STATUS_ENCLAVE_FAILURE. |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1607 | 0xFA | win10-1607 |
| Win10 1703 | 0xFD | win10-1703 |
| Win10 1709 | 0xFE | win10-1709 |
| Win10 1803 | 0xFF | win10-1803 |
| Win10 1809 | 0x100 | win10-1809 |
| Win10 1903 | 0x101 | win10-1903 |
| Win10 1909 | 0x101 | win10-1909 |
| Win10 2004 | 0x106 | win10-2004 |
| Win10 20H2 | 0x106 | win10-20h2 |
| Win10 21H1 | 0x106 | win10-21h1 |
| Win10 21H2 | 0x107 | win10-21h2 |
| Win10 22H2 | 0x107 | win10-22h2 |
| Win11 21H2 | 0x10C | win11-21h2 |
| Win11 22H2 | 0x10D | win11-22h2 |
| Win11 23H2 | 0x10D | win11-23h2 |
| Win11 24H2 | 0x10F | win11-24h2 |
| Server 2016 | 0xFA | winserver-2016 |
| Server 2019 | 0x100 | winserver-2019 |
| Server 2022 | 0x10B | winserver-2022 |
| Server 2025 | 0x10F | winserver-2025 |
Kernel module
Related APIs
Syscall stub
4C 8B D1 mov r10, rcx B8 0F 01 00 00 mov eax, 0x10F 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
`NtLoadEnclaveData` is the **page-by-page ingest** call that runs *between* `NtCreateEnclave` and `NtInitializeEnclave`. On SGX it lowers into an `EADD` for each source page; on VBS the Secure Kernel `IumLoadEnclaveData` copies the source buffer across the VTL boundary and stamps the destination page's measurement into the running enclave hash. The protection passed here is the *final* protection — the enclave cannot remap it later (no per-page `mprotect` exists in VTL1). For an enclave DLL, `vertdll.dll` makes one call per `IMAGE_SCN_*` section: one PAGE_READONLY for `.rdata`, one PAGE_EXECUTE_READ for `.text`, one PAGE_READWRITE for `.data`. All loads must happen before `NtInitializeEnclave`; afterwards the call returns `STATUS_ENCLAVE_NOT_TERMINATED`.
Common malware usage
From an offensive standpoint, this is the call that physically *places code into VTL1*. The barrier to abuse is that the loaded bytes will be measured into the enclave hash and that hash must match what `IMAGE_ENCLAVE_CONFIG` permits at init time. Two real-world levers: (1) **Microsoft-signed enclave with attacker-controlled data**: load benign data pages whose contents are interpreted as commands by the signed code — equivalent to ROP inside the enclave; (2) **research loader**: the Yuste / Soriano-Salvador work loads a signed *stub* enclave whose 'code' is actually a tiny dispatcher that accepts a shellcode pointer at `NtCallEnclave` time — the malicious payload is never measured into MRENCLAVE, only the dispatcher is. Defenders cannot inspect the loaded bytes after the fact — VTL1 memory is opaque to VTL0.
Detection opportunities
The pre-init load burst is highly characteristic: ten-to-hundreds of `NtLoadEnclaveData` calls in quick succession on the same enclave base address, followed by `NtInitializeEnclave`. The ETW provider `Microsoft-Windows-Kernel-Memory` emits an event per load. EDRs that hook on the host syscall pattern can flag the sequence trivially; the harder problem is attribution — which DLL is being loaded into the enclave. The defender's best lever is the *file source*: the host module performing the loads will have an `IMAGE_ENCLAVE_CONFIG` directory naming the enclave DLL by image hash. Sysmon Event ID 7 (ImageLoad) on the host will show the enclave DLL's PE mapping prior to the load syscalls — pair the two for retroactive identification.
Direct syscall examples
cVBS enclave bring-up (step 2/3 — load image)
// Walk the PE sections of a signed enclave DLL and copy them into the enclave.
// (Helper for the create -> load -> initialize -> call sequence.)
#include <windows.h>
BOOL LoadEnclaveImage(PVOID enclaveBase, PVOID peImage, SIZE_T peSize) {
PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)peImage;
PIMAGE_NT_HEADERS nt = (PIMAGE_NT_HEADERS)((BYTE*)peImage + dos->e_lfanew);
PIMAGE_SECTION_HEADER sec = IMAGE_FIRST_SECTION(nt);
for (WORD i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++) {
ULONG prot = PAGE_READONLY;
if (sec->Characteristics & IMAGE_SCN_MEM_EXECUTE) prot = PAGE_EXECUTE_READ;
else if (sec->Characteristics & IMAGE_SCN_MEM_WRITE) prot = PAGE_READWRITE;
PVOID dst = (BYTE*)enclaveBase + sec->VirtualAddress;
PVOID src = (BYTE*)peImage + sec->PointerToRawData;
SIZE_T size = ((sec->SizeOfRawData + 0xFFF) & ~0xFFFu);
if (!LoadEnclaveData(
GetCurrentProcess(),
dst, src, size, prot,
NULL, 0, // page info (VBS-specific, may be NULL)
NULL, // bytes written
NULL)) { // enclave error
return FALSE;
}
}
return TRUE;
}asmx64 direct stub (Win11 24H2)
; Direct syscall stub for NtLoadEnclaveData (SSN 0x10F on Win11 24H2 / Server 2025)
NtLoadEnclaveData PROC
mov r10, rcx ; ProcessHandle
mov eax, 10Fh ; SSN
syscall
ret
NtLoadEnclaveData ENDPMITRE ATT&CK mappings
Last verified: 2026-05-20