NtQueryInformationByName
Consulta información de archivo por ruta sin un handle abierto, introducida en Windows 10 RS5.
Prototipo
NTSTATUS NtQueryInformationByName( POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| ObjectAttributes | POBJECT_ATTRIBUTES | in | Atributos de objeto que describen la ruta del archivo objetivo. ObjectName es la ruta NT. |
| IoStatusBlock | PIO_STATUS_BLOCK | out | Recibe el estado final y el número de bytes escritos en FileInformation. |
| FileInformation | PVOID | out | Búfer del llamante que recibe la clase de información solicitada. |
| Length | ULONG | in | Tamaño de FileInformation en bytes. |
| FileInformationClass | FILE_INFORMATION_CLASS | in | Clase que identifica qué información devolver (p. ej. FileStatInformation, FileStatBasicInformation). |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1703 | 0x13B | win10-1703 |
| Win10 1709 | 0x13E | win10-1709 |
| Win10 1803 | 0x140 | win10-1803 |
| Win10 1809 | 0x141 | win10-1809 |
| Win10 1903 | 0x142 | win10-1903 |
| Win10 1909 | 0x142 | win10-1909 |
| Win10 2004 | 0x148 | win10-2004 |
| Win10 20H2 | 0x148 | win10-20h2 |
| Win10 21H1 | 0x148 | win10-21h1 |
| Win10 21H2 | 0x149 | win10-21h2 |
| Win10 22H2 | 0x149 | win10-22h2 |
| Win11 21H2 | 0x14F | win11-21h2 |
| Win11 22H2 | 0x151 | win11-22h2 |
| Win11 23H2 | 0x151 | win11-23h2 |
| Win11 24H2 | 0x153 | win11-24h2 |
| Server 2019 | 0x141 | winserver-2019 |
| Server 2022 | 0x14E | winserver-2022 |
| Server 2025 | 0x153 | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 53 01 00 00 mov eax, 0x153 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
Introducido en Windows 10 1709 (uso oficialmente documentado desde RS5/1803), NtQueryInformationByName colapsa el triplete heredado `NtCreateFile → NtQueryInformationFile → NtClose` en un único syscall cuando el llamante solo necesita metadatos. Internamente el kernel todavía debe recorrer la pila filesystem del directorio padre y adquirir un FILE_OBJECT transitorio, pero nunca instala un handle en la tabla de handles del llamante — lo que significa menos eventos ruidosos de Sysmon Event ID 11/15 y cero rotación de la tabla de handles. Solo se aceptan algunos valores `FILE_INFORMATION_CLASS` (FileStatInformation, FileStatBasicInformation, FileStatLxInformation, FileCaseSensitiveInformation, FileStorageReserveIdInformation).
Uso común por malware
Usado por escáneres, loaders con environment-keying y droppers de payload por etapas conscientes de EDR para comprobar la existencia de archivos marcadores (p. ej. prueba de un build específico de un EDR en disco, o un archivo de huella de víctima) sin dejar rastro de telemetría de open-handle. Como no se crea handle, los minifilters de filesystem que dependen de `IRP_MJ_CREATE` ven la apertura como transitoria y efímera; los hooks user-mode sobre `NtCreateFile`/`NtOpenFile` se eluden por completo — la ruta del syscall es directamente `NtQueryInformationByName`. La señal es más débil que el reconocimiento basado en NtCreateFile, que es precisamente el objetivo. Algunos escáneres comerciales (profilers tipo CCleaner, pero también infostealers recientes) han migrado a esta API para reducir el ruido de open-file.
Oportunidades de detección
Los minifilters de filesystem siguen viendo el IRP_MJ_CREATE transitorio — los eventos File de Sysmon configurados con `IncludeTransientHandles=true` (una opción relativamente nueva) los aflorarán. Los eventos ETW Microsoft-Windows-Kernel-File `Create` se emiten con un flag `TransitionTrace` que distingue la consulta por nombre de una apertura con handle retenido. Cazar llamadas `NtQueryInformationByName` que apuntan a `*.exe`, `*.dll` o rutas de instalación de EDR específicas desde un proceso no-sistema es una señal de anomalía más fuerte que el propio syscall. Sysmon Event ID 11 (FileCreate) y Event ID 15 (FileCreateStreamHash) *no* se dispararán — esa ausencia, acoplada con comportamiento condicionado por la existencia del archivo, es la detección.
Ejemplos de syscalls directos
cCheck for EDR install marker without opening a handle
// Probe for the presence of an EDR DLL on disk using the new RS5+ syscall.
#include <windows.h>
#include <winternl.h>
typedef struct _FILE_STAT_BASIC_INFORMATION {
LARGE_INTEGER FileId;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER AllocationSize;
LARGE_INTEGER EndOfFile;
ULONG FileAttributes;
ULONG ReparseTag;
ULONG NumberOfLinks;
ULONG DeviceType;
ULONG DeviceCharacteristics;
ULONG Reserved;
LARGE_INTEGER VolumeSerialNumber;
FILE_ID_128 FileId128;
} FILE_STAT_BASIC_INFORMATION;
typedef NTSTATUS (NTAPI *PNTQUERYINFORMATIONBYNAME)(
POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, PVOID, ULONG, ULONG);
BOOL FileExistsQuietly(LPCWSTR ntPath) {
UNICODE_STRING us;
RtlInitUnicodeString(&us, ntPath);
OBJECT_ATTRIBUTES oa;
InitializeObjectAttributes(&oa, &us, OBJ_CASE_INSENSITIVE, NULL, NULL);
FILE_STAT_BASIC_INFORMATION info;
IO_STATUS_BLOCK iosb;
PNTQUERYINFORMATIONBYNAME f = (PNTQUERYINFORMATIONBYNAME)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtQueryInformationByName");
return f && f(&oa, &iosb, &info, sizeof(info), 75 /* FileStatBasicInformation */) == 0;
}asmx64 direct stub (Win11 24H2, SSN 0x153)
NtQueryInformationByName PROC
mov r10, rcx
mov eax, 153h
syscall
ret
NtQueryInformationByName ENDPMapeos MITRE ATT&CK
Last verified: 2026-05-20