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
| Name | Type | Dir | Description |
|---|---|---|---|
| VariableName | PUNICODE_STRING | in | UNICODE_STRING que nombra la variable. Mapea a nombres BIOS NV-RAM heredados; sin espacio GUID. |
| VariableValue | PWCHAR | out | Búfer asignado por el llamador que recibe el valor de la variable como cadena de caracteres anchos. |
| ValueLength | USHORT | in | Capacidad de VariableValue en bytes (tamaño USHORT: máximo 64 KiB). |
| ReturnLength | PUSHORT | out | Puntero opcional que recibe el número de bytes efectivamente escritos. |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | 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 |
Módulo del kernel
APIs relacionadas
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 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.
}Mapeos MITRE ATT&CK
Last verified: 2026-05-20