> Windows Syscalls
ntoskrnl.exeT1622T1003.001T1106

NtQueryObject

Renvoie des métadonnées sur un handle d'objet noyau : info de base, nom, type ou table de types système.

Prototype

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

Arguments

NameTypeDirDescription
HandleHANDLEinHandle à interroger. Peut être NULL pour ObjectTypesInformation (liste globale).
ObjectInformationClassOBJECT_INFORMATION_CLASSin0=ObjectBasicInformation, 1=ObjectNameInformation, 2=ObjectTypeInformation, 3=ObjectTypesInformation.
ObjectInformationPVOIDoutBuffer alloué par l'appelant recevant la structure demandée.
ObjectInformationLengthULONGinTaille du buffer de sortie en octets.
ReturnLengthPULONGoutReçoit le nombre d'octets effectivement écrits (ou requis si STATUS_INFO_LENGTH_MISMATCH).

IDs de syscalls par version de Windows

Version 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

Module noyau

ntoskrnl.exeNtQueryObject

APIs liées

NtQueryObjectGetFileInformationByHandleExNtQuerySystemInformationNtDuplicateObject

Stub du 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

Notes non documentées

Le SSN `0x10` est stable de 1507 à 24H2 — bon candidat au hardcode. Les quatre classes d'information ont des rôles très différents : `ObjectBasicInformation` renvoie OBJECT_BASIC_INFORMATION avec **HandleCount** et **PointerCount** (utilisé pour détecter les objets debugger), `ObjectNameInformation` renvoie le chemin device (ex. `\Device\HarddiskVolume3\foo`) — la manière canonique de convertir un handle fichier/section/clé en chemin, `ObjectTypeInformation` renvoie OBJECT_TYPE_INFORMATION pour le type d'un handle unique, et `ObjectTypesInformation` (classe 3) renvoie OBJECT_TYPES_INFORMATION — tableau compacté décrivant tous les types d'objet connus du noyau. Le layout compact a historiquement exigé des parcours `ALIGN_UP_BY(p + sizeof(OBJECT_TYPE_INFORMATION_V2) + name.MaximumLength, sizeof(PVOID))` ; phnt fixe les offsets par build.

Usage courant par les malwares

Deux abus phares. **Anti-débogage via ObjectTypesInformation** : parcourir la table de types pour l'entrée `DebugObject` et inspecter `TotalNumberOfObjects` / `TotalNumberOfHandles` — valeurs non nulles = quelqu'un a un objet debug actif (débogueur attaché quelque part). Vue OS, ce qui attrape aussi les débogueurs sur processus voisins. Pas cher, sans exception, et plus difficile à mentir que PEB.BeingDebugged. **Énumération de handles pour accès aux credentials** : les dumpers LSASS soucieux d'OPSEC post-2022 (NanoDump, forks NanoDump-like, variantes Dumpert) itèrent `SystemHandleInformation` via NtQuerySystemInformation, puis appellent NtQueryObject(ObjectTypeInformation) pour ne garder que les handles Process, puis NtQueryObject(ObjectBasicInformation) + GrantedAccess pour trouver un handle LSASS déjà ouvert avec assez d'accès — et le dupliquer plutôt que d'ouvrir LSASS eux-mêmes.

Opportunités de détection

NtQueryObject(ObjectNameInformation) sur des handles fichier est banal dans le code légitime (Process Explorer, antivirus). Le signal fort est **la classe 3 (ObjectTypesInformation) appelée par un processus non système et non débogueur** — il n'y a presque aucune raison légitime pour du code non privilégié d'énumérer la table de types globale. Les EDR surveillent ce numéro de classe dans leur stub hooké. Contourner via syscall direct supprime la trace usermode mais laisse ETW Microsoft-Windows-Kernel-Audit-API-Calls visible ; les vendors corrèlent aussi `NtQuerySystemInformation(SystemHandleInformation)` suivi immédiatement d'une rafale d'appels `NtQueryObject` — l'empreinte canonique du parcours de la handle-table.

Exemples de syscalls directs

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))
}

Mappings MITRE ATT&CK

Last verified: 2026-05-20