> Windows Syscalls
ntoskrnl.exeT1542.001T1106

NtQuerySystemEnvironmentValue

Reads a legacy x86 BIOS/NV-RAM system environment variable by name (pre-UEFI interface).

Prototype

NTSTATUS NtQuerySystemEnvironmentValue(
  PUNICODE_STRING VariableName,
  PWCHAR          VariableValue,
  USHORT          ValueLength,
  PUSHORT         ReturnLength
);

Arguments

NameTypeDirDescription
VariableNamePUNICODE_STRINGinUNICODE_STRING naming the variable. Maps to legacy BIOS NV-RAM names; no GUID namespace.
VariableValuePWCHARoutCaller-allocated buffer that receives the variable's value as a wide-character string.
ValueLengthUSHORTinCapacity of VariableValue in bytes (USHORT-sized: maximum 64 KiB).
ReturnLengthPUSHORToutOptional pointer that receives the number of bytes actually written.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070x145win10-1507
Win10 16070x14Cwin10-1607
Win10 17030x152win10-1703
Win10 17090x155win10-1709
Win10 18030x157win10-1803
Win10 18090x158win10-1809
Win10 19030x159win10-1903
Win10 19090x159win10-1909
Win10 20040x15Fwin10-2004
Win10 20H20x15Fwin10-20h2
Win10 21H10x15Fwin10-21h1
Win10 21H20x160win10-21h2
Win10 22H20x160win10-22h2
Win11 21H20x167win11-21h2
Win11 22H20x16Awin11-22h2
Win11 23H20x16Awin11-23h2
Win11 24H20x16Cwin11-24h2
Server 20160x14Cwinserver-2016
Server 20190x158winserver-2019
Server 20220x165winserver-2022
Server 20250x16Cwinserver-2025

Kernel module

ntoskrnl.exeNtQuerySystemEnvironmentValue

Related APIs

GetFirmwareEnvironmentVariableWNtQuerySystemEnvironmentValueExNtSetSystemEnvironmentValueRtlAdjustPrivilege

Syscall stub

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

Legacy interface inherited from the original NT/x86 BIOS era for reading non-volatile system environment values. The name resolves through HAL-private NV-RAM stores; on modern UEFI machines this call is mostly vestigial — kernel paths funnel real firmware reads to NtQuerySystemEnvironmentValueEx instead. Requires SeSystemEnvironmentPrivilege. The 16-bit USHORT length cap is an obvious historical artefact and is one reason new code must use the Ex variant.

Common malware usage

Very low offensive signal in 2025. Most modern firmware-aware tradecraft (LoJax, MosaicRegressor, ESPecter) targets the UEFI variable surface via the *Ex* counterparts because that's where Secure Boot keys, BootOrder, and OS-loader handoff state actually live. Occasional appearances in older red-team toolkits surveying BIOS state on legacy machines.

Detection opportunities

ETW Microsoft-Windows-Kernel-General provider emits firmware-access events; pair with SeSystemEnvironmentPrivilege grants on the calling token. Calls from non-firmware-management binaries (anything outside bcdedit.exe, mountvol.exe, fwupdate utilities, vendor management tools) are inherently suspicious. EDRs rarely hook this directly because the legitimate volume is near zero — making any call a high-fidelity signal.

Direct syscall examples

asmx64 direct stub (Win11 24H2)

; Direct syscall stub for NtQuerySystemEnvironmentValue (SSN 0x16C, Win11 24H2)
NtQuerySystemEnvironmentValue PROC
    mov  r10, rcx
    mov  eax, 16Ch
    syscall
    ret
NtQuerySystemEnvironmentValue ENDP

cLegacy NV-RAM read via Win32 wrapper

// Win32 calls back into NtQuerySystemEnvironmentValue under the hood.
// Requires SeSystemEnvironmentPrivilege — enable it first or the call returns ERROR_PRIVILEGE_NOT_HELD.
WCHAR buf[256] = {0};
DWORD len = GetFirmwareEnvironmentVariableW(
    L"BootOrder",
    L"{00000000-0000-0000-0000-000000000000}", // legacy non-UEFI: ignored
    buf,
    sizeof(buf));
if (len == 0) {
    // On modern UEFI systems GetFirmwareEnvironmentVariableW dispatches to the Ex variant.
    // Failure here on a UEFI machine is expected for legacy names.
}

MITRE ATT&CK mappings

Last verified: 2026-05-20