NtQueryInformationFile
Liest Metadaten einer geöffneten Datei — Timestamps, Größe, EAs, Streams, Reparse-Points u. a.
Prototyp
NTSTATUS NtQueryInformationFile( HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass );
Argumente
| Name | Type | Dir | Description |
|---|---|---|---|
| FileHandle | HANDLE | in | Handle auf eine geöffnete Datei oder ein Verzeichnis; benötigter Zugriff hängt von der Info-Klasse ab. |
| IoStatusBlock | PIO_STATUS_BLOCK | out | Empfängt den NTSTATUS und die tatsächlich nach FileInformation geschriebenen Bytes. |
| FileInformation | PVOID | out | Vom Caller allokierter Buffer; das Layout entspricht der angeforderten FILE_INFORMATION_CLASS-Struktur. |
| Length | ULONG | in | Größe des FileInformation-Buffers in Byte; STATUS_INFO_LENGTH_MISMATCH bei zu klein. |
| FileInformationClass | FILE_INFORMATION_CLASS | in | Selektor-Enum — FileBasicInformation, FileStandardInformation, FileEaInformation, FileStreamInformation usw. |
Syscall-IDs pro Windows-Version
| Windows-Version | Syscall-ID | 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 |
Kernel-Modul
Verwandte APIs
Syscall-Stub
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
Undokumentierte Hinweise
NtQueryInformationFile ist der generische Metadaten-Reader für eine geöffnete Datei oder ein Verzeichnis. Die Signatur (Handle, IOSB, Buf, Len, *Information-Class*) wird auf der Schreibseite von `NtSetInformationFile` und für die Enumeration von `NtQueryDirectoryFile` gespiegelt. Die SSN `0x11` ist seit Windows 10 1507 stabil. Erwähnenswerte Information-Classes: `FileBasicInformation` (4 × LARGE_INTEGER Timestamps + FileAttributes), `FileStandardInformation` (Größe, Link-Anzahl, Delete-Pending, Verzeichnis-Flag), `FileEaInformation` (Extended-Attribute-Größe), `FileStreamInformation` (ADS / Alternate-Data-Stream-Enumeration), `FileAttributeTagInformation` (Reparse-Tag-Abfrage — Symlink, Junction, IO_REPARSE_TAG_*) und `FileAlignmentInformation` (Sektor- / Geräte-Alignment).
Häufige Malware-Nutzung
Auf der Read-Seite ist NtQueryInformationFile der primäre Syscall beim **Timestomping-Read-Back** (T1070.006): Ein Angreifer liest `FileBasicInformation` einer harmlosen Nachbardatei (z. B. `kernel32.dll`), nutzt dann `NtSetInformationFile` mit derselben Struktur, um CreationTime / LastWriteTime / ChangeTime auf eine bösartige Payload zu übertragen — und lässt sie sich so in Verzeichnislistings einfügen und oberflächliche Timestamp-Anomalie-Hunts überleben. `FileStreamInformation` wird von Infostealern und Persistenz-Frameworks genutzt, um Alternate Data Streams (`file.txt:hidden.exe`) zu entdecken, in denen Payloads auf NTFS versteckt werden. `FileAttributeTagInformation` erlaubt Stage-Check-Code, ein echtes Verzeichnis von einer Junction/einem Symlink zu unterscheiden, bevor Persistenz abgelegt wird — wichtig, wenn Ziele auf benutzerbeschreibbaren, junction-fähigen Pfaden liegen.
Erkennungsmöglichkeiten
Wie NtOpenFile ist NtQueryInformationFile in legitimer Software extrem häufig (explorer.exe ruft ihn auf belasteten Systemen allein tausende Male pro Sekunde) und für sich kein nützliches Signal. Sinnvolle Inspektionspunkte sind (1) die *Information-Class* und (2) das *Ziel*: Ein Nicht-System-Prozess, der NtQueryInformationFile + NtSetInformationFile beide mit `FileBasicInformation` auf demselben Handle in schneller Folge aufruft, ist das kanonische Timestomp-Muster. ETW `Microsoft-Windows-Kernel-File` liefert Metadaten-Zugriffsevents pro Information-Class. EDR-Mini-Filter sehen das zugrundeliegende `IRP_MJ_QUERY_INFORMATION`.
Direkte Syscall-Beispiele
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);
}
}MITRE ATT&CK-Mappings
Last verified: 2026-05-20