> Windows Syscalls
ntoskrnl.exeT1542.001T1106

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

NameTypeDirDescription
VariableNamePUNICODE_STRINGinUNICODE_STRING que nombra la variable a escribir. Se resuelve por almacenes NV-RAM privados del HAL.
VariableValuePUNICODE_STRINGinUNICODE_STRING con el nuevo valor. Longitud cero suele eliminar la entrada.

IDs de syscalls por versión de Windows

Versión de WindowsID de syscallBuild
Win10 15070x18Cwin10-1507
Win10 16070x195win10-1607
Win10 17030x19Bwin10-1703
Win10 17090x19Ewin10-1709
Win10 18030x1A0win10-1803
Win10 18090x1A1win10-1809
Win10 19030x1A2win10-1903
Win10 19090x1A2win10-1909
Win10 20040x1A8win10-2004
Win10 20H20x1A8win10-20h2
Win10 21H10x1A8win10-21h1
Win10 21H20x1AAwin10-21h2
Win10 22H20x1AAwin10-22h2
Win11 21H20x1B3win11-21h2
Win11 22H20x1B7win11-22h2
Win11 23H20x1B7win11-23h2
Win11 24H20x1BAwin11-24h2
Server 20160x195winserver-2016
Server 20190x1A1winserver-2019
Server 20220x1B0winserver-2022
Server 20250x1BAwinserver-2025

Módulo del kernel

ntoskrnl.exeNtSetSystemEnvironmentValue

APIs relacionadas

SetFirmwareEnvironmentVariableWNtSetSystemEnvironmentValueExNtQuerySystemEnvironmentValueRtlAdjustPrivilege

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 ENDP

cPrivilege 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