> Windows Syscalls
ntoskrnl.exeT1542.001T1106

NtQuerySystemEnvironmentValue

Lee una variable de entorno del sistema BIOS/NV-RAM x86 heredada por nombre (interfaz pre-UEFI).

Prototipo

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

Argumentos

NameTypeDirDescription
VariableNamePUNICODE_STRINGinUNICODE_STRING que nombra la variable. Mapea a nombres BIOS NV-RAM heredados; sin espacio GUID.
VariableValuePWCHARoutBúfer asignado por el llamador que recibe el valor de la variable como cadena de caracteres anchos.
ValueLengthUSHORTinCapacidad de VariableValue en bytes (tamaño USHORT: máximo 64 KiB).
ReturnLengthPUSHORToutPuntero opcional que recibe el número de bytes efectivamente escritos.

IDs de syscalls por versión de Windows

Versión de WindowsID de syscallBuild
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

Módulo del kernel

ntoskrnl.exeNtQuerySystemEnvironmentValue

APIs relacionadas

GetFirmwareEnvironmentVariableWNtQuerySystemEnvironmentValueExNtSetSystemEnvironmentValueRtlAdjustPrivilege

Stub del syscall

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

Notas no documentadas

Interfaz heredada de la era original NT/x86 BIOS para leer valores de entorno de sistema no volátiles. El nombre se resuelve mediante almacenes NV-RAM privados del HAL; en máquinas UEFI modernas la llamada es esencialmente vestigial — las rutas del kernel canalizan las lecturas reales de firmware a NtQuerySystemEnvironmentValueEx. Requiere SeSystemEnvironmentPrivilege. El límite USHORT de 16 bits es un artefacto histórico evidente y uno de los motivos por los que el código nuevo debe usar la variante Ex.

Uso común por malware

Señal ofensiva muy baja en 2025. La mayor parte del tradecraft moderno consciente del firmware (LoJax, MosaicRegressor, ESPecter) apunta a la superficie de variables UEFI vía las contrapartes *Ex*, porque allí residen realmente las claves de Secure Boot, BootOrder y el estado de transferencia al cargador de SO. Apariciones ocasionales en kits red-team antiguos auditando estado de BIOS en máquinas heredadas.

Oportunidades de detección

El proveedor ETW Microsoft-Windows-Kernel-General emite eventos de acceso a firmware; correlacionar con concesiones de SeSystemEnvironmentPrivilege en el token llamante. Llamadas desde binarios no relacionados con gestión de firmware (fuera de bcdedit.exe, mountvol.exe, utilidades fwupdate, herramientas de fabricante) son intrínsecamente sospechosas. Los EDR raramente lo hookean directamente porque el volumen legítimo es prácticamente cero — cualquier llamada se convierte en señal de alta fidelidad.

Ejemplos de syscalls directos

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.
}

Mapeos MITRE ATT&CK

Last verified: 2026-05-20