NtSetSystemEnvironmentValue
Escribe una variable de entorno del sistema BIOS/NV-RAM x86 heredada (interfaz pre-UEFI).
Prototipo
NTSTATUS NtSetSystemEnvironmentValue( PUNICODE_STRING VariableName, PUNICODE_STRING VariableValue );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| VariableName | PUNICODE_STRING | in | UNICODE_STRING que nombra la variable a escribir. Se resuelve por almacenes NV-RAM privados del HAL. |
| VariableValue | PUNICODE_STRING | in | UNICODE_STRING con el nuevo valor. Longitud cero suele eliminar la entrada. |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0x18C | win10-1507 |
| Win10 1607 | 0x195 | win10-1607 |
| Win10 1703 | 0x19B | win10-1703 |
| Win10 1709 | 0x19E | win10-1709 |
| Win10 1803 | 0x1A0 | win10-1803 |
| Win10 1809 | 0x1A1 | win10-1809 |
| Win10 1903 | 0x1A2 | win10-1903 |
| Win10 1909 | 0x1A2 | win10-1909 |
| Win10 2004 | 0x1A8 | win10-2004 |
| Win10 20H2 | 0x1A8 | win10-20h2 |
| Win10 21H1 | 0x1A8 | win10-21h1 |
| Win10 21H2 | 0x1AA | win10-21h2 |
| Win10 22H2 | 0x1AA | win10-22h2 |
| Win11 21H2 | 0x1B3 | win11-21h2 |
| Win11 22H2 | 0x1B7 | win11-22h2 |
| Win11 23H2 | 0x1B7 | win11-23h2 |
| Win11 24H2 | 0x1BA | win11-24h2 |
| Server 2016 | 0x195 | winserver-2016 |
| Server 2019 | 0x1A1 | winserver-2019 |
| Server 2022 | 0x1B0 | winserver-2022 |
| Server 2025 | 0x1BA | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 BA 01 00 00 mov eax, 0x1BA 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
Escritor compañero de NtQuerySystemEnvironmentValue: persistencia BIOS NV-RAM heredada, sin espacio GUID y con un campo de longitud de 16 bits. Requiere SeSystemEnvironmentPrivilege, que sólo poseen por defecto SYSTEM y administradores tras habilitación explícita vía RtlAdjustPrivilege. En máquinas UEFI modernas, la capa de pegamento firmware suele rechazar o ignorar estas escrituras; el trabajo real de persistencia ha migrado a NtSetSystemEnvironmentValueEx.
Uso común por malware
Valor ofensivo moderno marginal. La superficie de persistencia interesante (escribir variables EFI en las que confía el cargador del SO, p. ej. el patrón LoJax) está en la contraparte Ex. Implants en máquinas heredadas y algunos PoC de implants firmware han usado esta llamada para alternar ajustes BIOS, pero es raro en el tradecraft de producción actual.
Oportunidades de detección
Tratar toda llamada exitosa como alta fidelidad: los escritores legítimos se limitan a herramientas tipo bcdedit y a la gestión firmware OEM. Auditar la transición de habilitación de privilegio (ajuste de SeSystemEnvironmentPrivilege vía NtAdjustPrivilegesToken) — es el primer cuello de botella blue-team. ETW Microsoft-Windows-Kernel-General dispara eventos de acceso a firmware.
Ejemplos de syscalls directos
asmx64 direct stub (Win11 24H2)
; Direct syscall stub for NtSetSystemEnvironmentValue (SSN 0x1BA, Win11 24H2)
NtSetSystemEnvironmentValue PROC
mov r10, rcx
mov eax, 1BAh
syscall
ret
NtSetSystemEnvironmentValue ENDPcPrivilege enable + legacy write
// Enable SeSystemEnvironmentPrivilege first — otherwise the syscall returns STATUS_PRIVILEGE_NOT_HELD. BOOLEAN was; RtlAdjustPrivilege(SE_SYSTEM_ENVIRONMENT_PRIVILEGE, TRUE, FALSE, &was); UNICODE_STRING name, value; RtlInitUnicodeString(&name, L"BootOrder"); RtlInitUnicodeString(&value, L"0001000200030004"); NTSTATUS s = NtSetSystemEnvironmentValue(&name, &value); // On a UEFI box prefer NtSetSystemEnvironmentValueEx with a vendor GUID — modern firmware // will not honour legacy-namespace writes.
Mapeos MITRE ATT&CK
Last verified: 2026-05-20