> Windows Syscalls
ntoskrnl.exeT1134T1033T1548.002

NtQueryInformationToken

Récupère une classe d'information spécifiée sur un jeton d'accès.

Prototype

NTSTATUS NtQueryInformationToken(
  HANDLE                  TokenHandle,
  TOKEN_INFORMATION_CLASS TokenInformationClass,
  PVOID                   TokenInformation,
  ULONG                   TokenInformationLength,
  PULONG                  ReturnLength
);

Arguments

NameTypeDirDescription
TokenHandleHANDLEinHandle vers le jeton à interroger. Nécessite TOKEN_QUERY (0x8) ; certaines classes requièrent TOKEN_QUERY_SOURCE (0x10).
TokenInformationClassTOKEN_INFORMATION_CLASSinClasse d'information à récupérer, ex. TokenUser, TokenGroups, TokenPrivileges, TokenIntegrityLevel, TokenElevation.
TokenInformationPVOIDoutBuffer alloué par l'appelant qui reçoit l'information demandée.
TokenInformationLengthULONGinTaille en octets du buffer TokenInformation.
ReturnLengthPULONGoutReçoit le nombre d'octets écrits, ou la taille requise si STATUS_BUFFER_TOO_SMALL est renvoyé.

IDs de syscalls par version de Windows

Version de WindowsID de syscallBuild
Win10 15070x21win10-1507
Win10 16070x21win10-1607
Win10 17030x21win10-1703
Win10 17090x21win10-1709
Win10 18030x21win10-1803
Win10 18090x21win10-1809
Win10 19030x21win10-1903
Win10 19090x21win10-1909
Win10 20040x21win10-2004
Win10 20H20x21win10-20h2
Win10 21H10x21win10-21h1
Win10 21H20x21win10-21h2
Win10 22H20x21win10-22h2
Win11 21H20x21win11-21h2
Win11 22H20x21win11-22h2
Win11 23H20x21win11-23h2
Win11 24H20x21win11-24h2
Server 20160x21winserver-2016
Server 20190x21winserver-2019
Server 20220x21winserver-2022
Server 20250x21winserver-2025

Module noyau

ntoskrnl.exeNtQueryInformationToken

APIs liées

GetTokenInformationNtSetInformationTokenNtAdjustPrivilegesTokenNtDuplicateTokenCheckTokenMembershipNtAccessCheck

Stub du syscall

4C 8B D1            mov r10, rcx
B8 21 00 00 00      mov eax, 0x21
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

NtQueryInformationToken est le pendant lecture de NtSetInformationToken et ce qu'enrobe `advapi32!GetTokenInformation`. Le SSN est **resté stable à `0x21`** de Windows 10 1507 à Windows 11 24H2. Les classes les plus utiles côté offensif sont `TokenUser` (SID utilisateur), `TokenGroups` (SID de groupes — révèle Administrators, BUILTIN\Backup Operators, etc.), `TokenPrivileges`, `TokenStatistics` (contient le LUID nécessaire au lien d'impersonation façon `NtFilterToken`), `TokenIntegrityLevel`, `TokenElevation`, et `TokenLinkedToken` (le jumeau élevé du jeton, utilisé par les bypass UAC Make-Me-Admin).

Usage courant par les malwares

Les implants utilisent NtQueryInformationToken pour la situational awareness juste après l'atterrissage : sommes-nous élevés ? sommes-nous SYSTEM ? à quels groupes appartenons-nous ? quels privilèges sont actifs ? `TokenLinkedToken` est la clé de la famille silencieuse de bypass UAC Make-Me-Admin (chaînes `AppInfo!RAiLaunchAdminProcess`) : un processus admin IL moyen interroge son propre jeton lié pour obtenir un handle vers le jeton IL élevé, puis duplique et impersonne sans déclencher consent.exe. `token::list` de Mimikatz énumère simplement les handles et appelle NtQueryInformationToken avec `TokenUser` puis `TokenStatistics`.

Opportunités de détection

NtQueryInformationToken est extraordinairement bruyant dans les logiciels légitimes — chaque appel COM, chaque extension shell, chaque opération style `whoami` y passe. Ce n'est pas une détection utile en soi. Ce qui est utile : corréler des requêtes `TokenLinkedToken` depuis des processus IL moyen suivies peu après par NtDuplicateToken + CreateProcessWithTokenW (motif Make-Me-Admin), ou des requêtes `TokenStatistics` suivies immédiatement par `NtSetInformationThread(ThreadImpersonationToken)` (chaîne d'impersonation). Le provider ETW `Microsoft-Windows-Kernel-Audit-API-Calls` ne logue pas spécifiquement les requêtes de jeton ; les défenseurs s'appuient typiquement sur le hook user-mode de l'EDR sur `ntdll!NtQueryInformationToken`.

Exemples de syscalls directs

asmx64 direct stub (stable SSN 0x21)

NtQueryInformationToken PROC
    mov  r10, rcx          ; TokenHandle
    mov  eax, 21h          ; SSN stable across all builds
    syscall
    ret
NtQueryInformationToken ENDP

cAm I SYSTEM? (TokenUser + well-known SID compare)

// Check if the current token belongs to NT AUTHORITY\SYSTEM.
BOOL IsRunningAsSystem(HANDLE hToken) {
    BYTE buf[256];
    ULONG ret = 0;
    if (!NT_SUCCESS(NtQueryInformationToken(
            hToken, TokenUser, buf, sizeof(buf), &ret)))
        return FALSE;

    PTOKEN_USER tu = (PTOKEN_USER)buf;
    PSID systemSid = NULL;
    SID_IDENTIFIER_AUTHORITY ntAuth = SECURITY_NT_AUTHORITY;
    AllocateAndInitializeSid(&ntAuth, 1, SECURITY_LOCAL_SYSTEM_RID,
                             0,0,0,0,0,0,0, &systemSid);
    BOOL eq = EqualSid(tu->User.Sid, systemSid);
    FreeSid(systemSid);
    return eq;
}

rustMake-Me-Admin scout: locate linked elevated token

// Locate the elevated split-token sibling of an elevated-but-filtered process.
// If present, a high-IL token handle can be duplicated without UAC prompt.
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Security::{
    TOKEN_LINKED_TOKEN, TOKEN_INFORMATION_CLASS,
};

const TOKEN_LINKED_TOKEN_CLASS: TOKEN_INFORMATION_CLASS = 19; // TokenLinkedToken

extern "system" {
    fn NtQueryInformationToken(
        h: HANDLE, class: TOKEN_INFORMATION_CLASS,
        buf: *mut u8, len: u32, ret: *mut u32) -> i32;
}

pub unsafe fn try_get_linked_token(h: HANDLE) -> Option<HANDLE> {
    let mut lt = TOKEN_LINKED_TOKEN { LinkedToken: 0 };
    let mut ret = 0u32;
    let s = NtQueryInformationToken(
        h, TOKEN_LINKED_TOKEN_CLASS,
        &mut lt as *mut _ as *mut u8,
        std::mem::size_of::<TOKEN_LINKED_TOKEN>() as u32,
        &mut ret);
    if s == 0 && lt.LinkedToken != 0 { Some(lt.LinkedToken) } else { None }
}

Mappings MITRE ATT&CK

Last verified: 2026-05-20