> Windows Syscalls
ntoskrnl.exeT1622T1003.001T1106

NtQueryObject

Devuelve metadatos sobre un handle de objeto del kernel: información básica, nombre, tipo o tabla de tipos del sistema.

Prototipo

NTSTATUS NtQueryObject(
  HANDLE                   Handle,
  OBJECT_INFORMATION_CLASS ObjectInformationClass,
  PVOID                    ObjectInformation,
  ULONG                    ObjectInformationLength,
  PULONG                   ReturnLength
);

Argumentos

NameTypeDirDescription
HandleHANDLEinHandle a consultar. Puede ser NULL para ObjectTypesInformation (lista del sistema).
ObjectInformationClassOBJECT_INFORMATION_CLASSin0=ObjectBasicInformation, 1=ObjectNameInformation, 2=ObjectTypeInformation, 3=ObjectTypesInformation.
ObjectInformationPVOIDoutBuffer asignado por el llamador que recibe la estructura solicitada.
ObjectInformationLengthULONGinTamaño del buffer de salida en bytes.
ReturnLengthPULONGoutRecibe los bytes realmente escritos (o requeridos en STATUS_INFO_LENGTH_MISMATCH).

IDs de syscalls por versión de Windows

Versión de WindowsID de syscallBuild
Win10 15070x10win10-1507
Win10 16070x10win10-1607
Win10 17030x10win10-1703
Win10 17090x10win10-1709
Win10 18030x10win10-1803
Win10 18090x10win10-1809
Win10 19030x10win10-1903
Win10 19090x10win10-1909
Win10 20040x10win10-2004
Win10 20H20x10win10-20h2
Win10 21H10x10win10-21h1
Win10 21H20x10win10-21h2
Win10 22H20x10win10-22h2
Win11 21H20x10win11-21h2
Win11 22H20x10win11-22h2
Win11 23H20x10win11-23h2
Win11 24H20x10win11-24h2
Server 20160x10winserver-2016
Server 20190x10winserver-2019
Server 20220x10winserver-2022
Server 20250x10winserver-2025

Módulo del kernel

ntoskrnl.exeNtQueryObject

APIs relacionadas

NtQueryObjectGetFileInformationByHandleExNtQuerySystemInformationNtDuplicateObject

Stub del syscall

4C 8B D1            mov r10, rcx
B8 10 00 00 00      mov eax, 0x10
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 `0x10` es estable de 1507 a 24H2 — buen candidato a hardcode. Las cuatro clases de información tienen roles muy distintos: `ObjectBasicInformation` devuelve OBJECT_BASIC_INFORMATION con **HandleCount** y **PointerCount** (usado para detectar objetos debugger), `ObjectNameInformation` devuelve la ruta device (p. ej. `\Device\HarddiskVolume3\foo`) — la forma canónica de convertir un handle de archivo/section/clave en ruta, `ObjectTypeInformation` devuelve OBJECT_TYPE_INFORMATION para el tipo de un único handle, y `ObjectTypesInformation` (clase 3) devuelve OBJECT_TYPES_INFORMATION — array empaquetado que describe todos los tipos de objeto que conoce el kernel. El layout empaquetado ha exigido históricamente recorridos `ALIGN_UP_BY(p + sizeof(OBJECT_TYPE_INFORMATION_V2) + name.MaximumLength, sizeof(PVOID))`; phnt fija los offsets por build.

Uso común por malware

Dos abusos estrella. **Anti-depuración vía ObjectTypesInformation**: recorrer la tabla de tipos buscando la entrada `DebugObject` e inspeccionar `TotalNumberOfObjects` / `TotalNumberOfHandles` — valores no nulos = alguien tiene un objeto debug activo (depurador en alguna parte). Vista a nivel OS, también pilla depuradores en procesos hermanos. Barato, sin excepciones y más difícil de falsear que PEB.BeingDebugged. **Enumeración de handles para acceso a credenciales**: los dumpers LSASS conscientes de OPSEC post-2022 (NanoDump, forks tipo NanoDump, variantes de Dumpert) iteran `SystemHandleInformation` con NtQuerySystemInformation, luego llaman a NtQueryObject(ObjectTypeInformation) para descartar todo lo que no sea handle de Process, y luego NtQueryObject(ObjectBasicInformation) + GrantedAccess para encontrar un handle LSASS ya abierto con acceso suficiente — y duplicarlo en lugar de abrir LSASS ellos mismos.

Oportunidades de detección

NtQueryObject(ObjectNameInformation) sobre handles de archivo es habitual en código legítimo (Process Explorer, antivirus). La señal fuerte es **la clase 3 (ObjectTypesInformation) llamada desde un proceso no de sistema y no depurador** — casi no hay razón legítima para que código no privilegiado enumere la tabla global de tipos. Los EDR vigilan ese número de clase en su stub hookeado. Saltarlo con syscall directa elimina la traza usermode pero deja ETW Microsoft-Windows-Kernel-Audit-API-Calls visible; los vendors correlacionan también `NtQuerySystemInformation(SystemHandleInformation)` seguido inmediatamente de una ráfaga de `NtQueryObject` — la huella canónica del recorrido de handle-table.

Ejemplos de syscalls directos

asmx64 direct stub

; Direct syscall stub for NtQueryObject (SSN 0x10, all builds)
NtQueryObject PROC
    mov  r10, rcx          ; syscall convention
    mov  eax, 10h          ; SSN
    syscall
    ret
NtQueryObject ENDP

cDebugObject anti-debug via ObjectTypesInformation

// Walk the global object-type table looking for the "DebugObject" entry
// and report its TotalNumberOfObjects. Non-zero = a debugger exists somewhere.
#include <windows.h>
#include <winternl.h>

#define ObjectTypesInformation 3

typedef struct _OBJECT_TYPE_INFORMATION_V2 {
    UNICODE_STRING TypeName;
    ULONG TotalNumberOfObjects;
    ULONG TotalNumberOfHandles;
    ULONG TotalPagedPoolUsage;
    ULONG TotalNonPagedPoolUsage;
    ULONG TotalNamePoolUsage;
    ULONG TotalHandleTableUsage;
    ULONG HighWaterNumberOfObjects;
    // ... truncated for brevity
} OBJECT_TYPE_INFORMATION_V2;

typedef struct _OBJECT_TYPES_INFORMATION {
    ULONG NumberOfTypes;
} OBJECT_TYPES_INFORMATION;

typedef NTSTATUS (NTAPI *pNtQueryObject)(
    HANDLE, ULONG, PVOID, ULONG, PULONG);

BOOL HasDebugObjects(void) {
    pNtQueryObject NtQueryObject = (pNtQueryObject)GetProcAddress(
        GetModuleHandleA("ntdll.dll"), "NtQueryObject");
    ULONG need = 0;
    NtQueryObject(NULL, ObjectTypesInformation, NULL, 0, &need);
    PBYTE buf = (PBYTE)LocalAlloc(LPTR, need + 0x1000);
    if (!NT_SUCCESS(NtQueryObject(NULL, ObjectTypesInformation,
                                  buf, need + 0x1000, &need))) return FALSE;
    // Caller responsibility: walk the packed array with proper alignment.
    // Search for TypeName == L"DebugObject" and read TotalNumberOfObjects.
    LocalFree(buf);
    return TRUE;
}

rustNameInformation: handle -> NT path

// Cargo: windows-sys = "0.59", ntapi = "0.4"
use ntapi::ntobapi::{NtQueryObject, ObjectNameInformation};
use windows_sys::Win32::Foundation::HANDLE;

pub unsafe fn handle_to_nt_path(h: HANDLE) -> Option<String> {
    let mut need: u32 = 0;
    let _ = NtQueryObject(h as _, ObjectNameInformation,
                          std::ptr::null_mut(), 0, &mut need);
    let mut buf = vec![0u8; need as usize + 0x100];
    let st = NtQueryObject(h as _, ObjectNameInformation,
                           buf.as_mut_ptr() as _, buf.len() as u32, &mut need);
    if st < 0 { return None; }
    // OBJECT_NAME_INFORMATION: UNICODE_STRING followed by buffer
    let name = &*(buf.as_ptr() as *const ntapi::ntobapi::OBJECT_NAME_INFORMATION);
    let slice = std::slice::from_raw_parts(
        name.Name.Buffer, (name.Name.Length / 2) as usize);
    Some(String::from_utf16_lossy(slice))
}

Mapeos MITRE ATT&CK

Last verified: 2026-05-20