NtSetInformationObject
Establece atributos a nivel de handle (herencia, protección contra cierre) sobre un handle de objeto del kernel.
Prototipo
NTSTATUS NtSetInformationObject( HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass, PVOID ObjectInformation, ULONG ObjectInformationLength );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| Handle | HANDLE | in | Handle cuyos atributos se van a modificar. |
| ObjectInformationClass | OBJECT_INFORMATION_CLASS | in | Típicamente ObjectHandleFlagInformation (4) — la única clase aceptada por NtSetInformationObject. |
| ObjectInformation | PVOID | in | Puntero a OBJECT_HANDLE_FLAG_INFORMATION { BOOLEAN Inherit; BOOLEAN ProtectFromClose; }. |
| ObjectInformationLength | ULONG | in | Tamaño del buffer de entrada; sizeof(OBJECT_HANDLE_FLAG_INFORMATION) == 2. |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0x5C | win10-1507 |
| Win10 1607 | 0x5C | win10-1607 |
| Win10 1703 | 0x5C | win10-1703 |
| Win10 1709 | 0x5C | win10-1709 |
| Win10 1803 | 0x5C | win10-1803 |
| Win10 1809 | 0x5C | win10-1809 |
| Win10 1903 | 0x5C | win10-1903 |
| Win10 1909 | 0x5C | win10-1909 |
| Win10 2004 | 0x5C | win10-2004 |
| Win10 20H2 | 0x5C | win10-20h2 |
| Win10 21H1 | 0x5C | win10-21h1 |
| Win10 21H2 | 0x5C | win10-21h2 |
| Win10 22H2 | 0x5C | win10-22h2 |
| Win11 21H2 | 0x5C | win11-21h2 |
| Win11 22H2 | 0x5C | win11-22h2 |
| Win11 23H2 | 0x5C | win11-23h2 |
| Win11 24H2 | 0x5C | win11-24h2 |
| Server 2016 | 0x5C | winserver-2016 |
| Server 2019 | 0x5C | winserver-2019 |
| Server 2022 | 0x5C | winserver-2022 |
| Server 2025 | 0x5C | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 5C 00 00 00 mov eax, 0x5C 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
El SSN `0x5C` es estable en todos los builds cubiertos. NtSetInformationObject solo acepta realmente la clase **ObjectHandleFlagInformation (4)** con una estructura de 2 bytes: dos BOOLEAN, `Inherit` y `ProtectFromClose`. Es la primitiva del kernel detrás del Win32 `SetHandleInformation`. Activar `ProtectFromClose=TRUE` hace que NtClose posteriores sobre ese handle devuelvan STATUS_HANDLE_NOT_CLOSABLE sin liberar la referencia — el kernel mantiene la entrada, y un re-flip a FALSE vuelve a permitir el cierre. Inherit solo importa en CreateProcess (el handle pasa a la tabla del hijo).
Uso común por malware
Conocido como contramedida contra la sonda anti-debug clásica `NtClose(0xDEADBEEF) -> STATUS_INVALID_HANDLE`: el malware activa `ProtectFromClose` en sus propios handles reales antes de invocar defensivamente NtClose sobre ellos, de modo que sobreviven aunque un depurador altere la ruta de cierre (Themida y VMProtect llevan este truco). También es pieza de la **contra-contramedida anti-NtClose**: poner `ProtectFromClose=TRUE` sobre un handle voluntariamente inválido silencia STATUS_INVALID_HANDLE bajo depurador adjunto. Uso más oscuro: manipular herencia justo antes de CreateProcessAsUser para controlar exactamente qué handles se filtran a un hijo sandboxeado (lo usan algunos loaders sandbox-aware para pasar un token privilegiado sin conceder PROCESS_DUP_HANDLE al hijo).
Oportunidades de detección
Volumen muy bajo en software legítimo fuera de Office, WSL y hosts de consola. Sysmon no registra este syscall actualmente, pero está expuesto vía ETW Microsoft-Windows-Kernel-Audit-API-Calls y alcanzable desde ObRegisterCallbacks. Detección de alto valor: **ProtectFromClose=TRUE aplicado a handles estándar (0xFFFFFFFE/-1 = pseudo del proceso actual) o a handles dentro de un proceso cuyo padre mapeó ntdll de forma sospechosa recientemente** — outliers extremos. Los vendors correlacionan también flips de ProtectFromClose seguidos inmediatamente de NtClose con retorno no cero (patrón anti-debug).
Ejemplos de syscalls directos
asmx64 direct stub
; Direct syscall stub for NtSetInformationObject (SSN 0x5C, all builds)
NtSetInformationObject PROC
mov r10, rcx ; syscall convention
mov eax, 5Ch ; SSN
syscall
ret
NtSetInformationObject ENDPcProtect a handle from NtClose tampering
// Defeat NtClose-based anti-debug probes by marking the handle non-closable
// before any defensive NtClose() call.
#include <windows.h>
#define ObjectHandleFlagInformation 4
typedef struct _OBJECT_HANDLE_FLAG_INFORMATION {
BOOLEAN Inherit;
BOOLEAN ProtectFromClose;
} OBJECT_HANDLE_FLAG_INFORMATION;
typedef NTSTATUS (NTAPI *pNtSetInformationObject)(
HANDLE, ULONG, PVOID, ULONG);
BOOL ProtectHandle(HANDLE h) {
pNtSetInformationObject NtSetInformationObject = (pNtSetInformationObject)
GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtSetInformationObject");
OBJECT_HANDLE_FLAG_INFORMATION info = { FALSE, TRUE };
NTSTATUS s = NtSetInformationObject(h, ObjectHandleFlagInformation,
&info, sizeof(info));
return NT_SUCCESS(s);
}rustStrip inherit flag before sandbox spawn
// Cargo: ntapi = "0.4"
// Make a privileged token handle non-inheritable just before spawning a
// low-integrity child via CreateProcessAsUser. Combined with bInheritHandles=
// FALSE this gives belt-and-braces leak control.
use ntapi::ntobapi::NtSetInformationObject;
const ObjectHandleFlagInformation: u32 = 4;
#[repr(C)]
struct ObjectHandleFlagInfo { inherit: u8, protect_from_close: u8 }
pub unsafe fn strip_inherit(h: isize) {
let info = ObjectHandleFlagInfo { inherit: 0, protect_from_close: 0 };
let _ = NtSetInformationObject(
h as _,
ObjectHandleFlagInformation as _,
&info as *const _ as _,
std::mem::size_of::<ObjectHandleFlagInfo>() as u32,
);
}Mapeos MITRE ATT&CK
Last verified: 2026-05-20