NtQueryInformationFile
Lit les métadonnées d'un fichier ouvert — timestamps, taille, EA, streams, points de reparse, etc.
Prototype
NTSTATUS NtQueryInformationFile( HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| FileHandle | HANDLE | in | Handle vers un fichier ou répertoire ouvert ; l'accès requis dépend de la classe d'information. |
| IoStatusBlock | PIO_STATUS_BLOCK | out | Reçoit le NTSTATUS et le nombre d'octets effectivement écrits dans FileInformation. |
| FileInformation | PVOID | out | Tampon alloué par l'appelant ; la disposition correspond à la structure FILE_INFORMATION_CLASS demandée. |
| Length | ULONG | in | Taille en octets du tampon FileInformation ; STATUS_INFO_LENGTH_MISMATCH si trop petit. |
| FileInformationClass | FILE_INFORMATION_CLASS | in | Enum sélecteur — FileBasicInformation, FileStandardInformation, FileEaInformation, FileStreamInformation, etc. |
IDs de syscalls par version de Windows
| Version de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0x11 | win10-1507 |
| Win10 1607 | 0x11 | win10-1607 |
| Win10 1703 | 0x11 | win10-1703 |
| Win10 1709 | 0x11 | win10-1709 |
| Win10 1803 | 0x11 | win10-1803 |
| Win10 1809 | 0x11 | win10-1809 |
| Win10 1903 | 0x11 | win10-1903 |
| Win10 1909 | 0x11 | win10-1909 |
| Win10 2004 | 0x11 | win10-2004 |
| Win10 20H2 | 0x11 | win10-20h2 |
| Win10 21H1 | 0x11 | win10-21h1 |
| Win10 21H2 | 0x11 | win10-21h2 |
| Win10 22H2 | 0x11 | win10-22h2 |
| Win11 21H2 | 0x11 | win11-21h2 |
| Win11 22H2 | 0x11 | win11-22h2 |
| Win11 23H2 | 0x11 | win11-23h2 |
| Win11 24H2 | 0x11 | win11-24h2 |
| Server 2016 | 0x11 | winserver-2016 |
| Server 2019 | 0x11 | winserver-2019 |
| Server 2022 | 0x11 | winserver-2022 |
| Server 2025 | 0x11 | winserver-2025 |
Module noyau
APIs liées
Stub du syscall
4C 8B D1 mov r10, rcx B8 11 00 00 00 mov eax, 0x11 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
NtQueryInformationFile est le lecteur de métadonnées générique pour un fichier ou répertoire ouvert. La signature (handle, IOSB, buf, len, *classe d'information*) est mirroirée par `NtSetInformationFile` côté écriture et `NtQueryDirectoryFile` pour l'énumération. Le SSN `0x11` est stable depuis Windows 10 1507. Classes d'information à connaître : `FileBasicInformation` (4 × LARGE_INTEGER timestamps + FileAttributes), `FileStandardInformation` (taille, count de liens, delete-pending, flag répertoire), `FileEaInformation` (taille des attributs étendus), `FileStreamInformation` (énumération ADS / alternate data streams), `FileAttributeTagInformation` (interrogation de tag reparse — lien symbolique, jonction, IO_REPARSE_TAG_*), et `FileAlignmentInformation` (alignement secteur / device).
Usage courant par les malwares
Côté lecture, NtQueryInformationFile est le syscall principal du **timestomping read-back** (T1070.006) : un attaquant lit `FileBasicInformation` d'un fichier voisin bénin (ex. `kernel32.dll`), puis utilise `NtSetInformationFile` avec la même structure pour copier CreationTime / LastWriteTime / ChangeTime sur un payload malveillant — le faisant se fondre visuellement dans les listings et survivre aux chasses sommaires d'anomalies de timestamps. `FileStreamInformation` est utilisé par les infostealers et frameworks de persistance pour découvrir les Alternate Data Streams (`file.txt:hidden.exe`) servant à cacher des payloads sur NTFS. `FileAttributeTagInformation` permet à du code de stage-check de distinguer un vrai répertoire d'une jonction/symlink avant de déposer une persistance — important quand les cibles résident sur des chemins user-writable jonctionnables.
Opportunités de détection
Comme NtOpenFile, NtQueryInformationFile est extrêmement courant en logiciel légitime (explorer.exe seul l'appelle des milliers de fois par seconde sur les systèmes chargés) et n'est pas un signal utile seul. Les points d'inspection utiles sont (1) la *classe d'information* et (2) la *cible* : un processus non système appelant NtQueryInformationFile + NtSetInformationFile tous deux avec `FileBasicInformation` sur le même handle en succession rapide est le pattern canonique du timestomp. L'ETW `Microsoft-Windows-Kernel-File` expose des événements d'accès métadonnées par classe d'information. Les drivers mini-filter EDR voient le `IRP_MJ_QUERY_INFORMATION` sous-jacent.
Exemples de syscalls directs
asmx64 direct stub
; Direct syscall stub for NtQueryInformationFile (SSN 0x11, stable since Win10 1507)
NtQueryInformationFile PROC
mov r10, rcx ; FileHandle
mov eax, 11h ; SSN
syscall
ret
NtQueryInformationFile ENDPcRead FileBasicInformation timestamps
// Read CreationTime/LastAccessTime/LastWriteTime/ChangeTime + Attributes
// — the read-half of a classic timestomp.
#include <windows.h>
#include <winternl.h>
typedef struct _FILE_BASIC_INFORMATION {
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
ULONG FileAttributes;
} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
NTSTATUS GetBasicInfo(HANDLE h, FILE_BASIC_INFORMATION *out) {
IO_STATUS_BLOCK iosb = {0};
return NtQueryInformationFile(h, &iosb, out, sizeof(*out),
FileBasicInformation);
}cEnumerate Alternate Data Streams
// FileStreamInformation walk — discovers hidden ADS payloads on NTFS.
#include <windows.h>
#include <winternl.h>
typedef struct _FILE_STREAM_INFORMATION {
ULONG NextEntryOffset;
ULONG StreamNameLength;
LARGE_INTEGER StreamSize;
LARGE_INTEGER StreamAllocationSize;
WCHAR StreamName[1];
} FILE_STREAM_INFORMATION, *PFILE_STREAM_INFORMATION;
void ListStreams(HANDLE h) {
BYTE buf[4096]; IO_STATUS_BLOCK iosb = {0};
if (NtQueryInformationFile(h, &iosb, buf, sizeof(buf),
FileStreamInformation) < 0) return;
PFILE_STREAM_INFORMATION p = (PFILE_STREAM_INFORMATION)buf;
for (;;) {
wprintf(L"%.*s (%lld bytes)\n",
p->StreamNameLength / 2, p->StreamName,
p->StreamSize.QuadPart);
if (!p->NextEntryOffset) break;
p = (PFILE_STREAM_INFORMATION)((BYTE*)p + p->NextEntryOffset);
}
}Mappings MITRE ATT&CK
Last verified: 2026-05-20