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
| Name | Type | Dir | Description |
|---|---|---|---|
| VariableName | PUNICODE_STRING | in | UNICODE_STRING naming the variable. Maps to legacy BIOS NV-RAM names; no GUID namespace. |
| VariableValue | PWCHAR | out | Caller-allocated buffer that receives the variable's value as a wide-character string. |
| ValueLength | USHORT | in | Capacity of VariableValue in bytes (USHORT-sized: maximum 64 KiB). |
| ReturnLength | PUSHORT | out | Optional pointer that receives the number of bytes actually written. |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0x145 | win10-1507 |
| Win10 1607 | 0x14C | win10-1607 |
| Win10 1703 | 0x152 | win10-1703 |
| Win10 1709 | 0x155 | win10-1709 |
| Win10 1803 | 0x157 | win10-1803 |
| Win10 1809 | 0x158 | win10-1809 |
| Win10 1903 | 0x159 | win10-1903 |
| Win10 1909 | 0x159 | win10-1909 |
| Win10 2004 | 0x15F | win10-2004 |
| Win10 20H2 | 0x15F | win10-20h2 |
| Win10 21H1 | 0x15F | win10-21h1 |
| Win10 21H2 | 0x160 | win10-21h2 |
| Win10 22H2 | 0x160 | win10-22h2 |
| Win11 21H2 | 0x167 | win11-21h2 |
| Win11 22H2 | 0x16A | win11-22h2 |
| Win11 23H2 | 0x16A | win11-23h2 |
| Win11 24H2 | 0x16C | win11-24h2 |
| Server 2016 | 0x14C | winserver-2016 |
| Server 2019 | 0x158 | winserver-2019 |
| Server 2022 | 0x165 | winserver-2022 |
| Server 2025 | 0x16C | winserver-2025 |
Kernel module
Related APIs
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 ENDPcLegacy 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