> Windows Syscalls
ntoskrnl.exeT1134T1033T1548.002

NtQueryInformationToken

Recupera una clase de información especificada sobre un token de acceso.

Prototipo

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

Argumentos

NameTypeDirDescription
TokenHandleHANDLEinHandle al token a consultar. Requiere TOKEN_QUERY (0x8); algunas clases requieren TOKEN_QUERY_SOURCE (0x10).
TokenInformationClassTOKEN_INFORMATION_CLASSinClase de información a recuperar, p. ej. TokenUser, TokenGroups, TokenPrivileges, TokenIntegrityLevel, TokenElevation.
TokenInformationPVOIDoutBuffer asignado por el llamante que recibe la información solicitada.
TokenInformationLengthULONGinTamaño en bytes del buffer TokenInformation.
ReturnLengthPULONGoutRecibe los bytes escritos, o el tamaño requerido si se devuelve STATUS_BUFFER_TOO_SMALL.

IDs de syscalls por versión de Windows

Versión 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

Módulo del kernel

ntoskrnl.exeNtQueryInformationToken

APIs relacionadas

GetTokenInformationNtSetInformationTokenNtAdjustPrivilegesTokenNtDuplicateTokenCheckTokenMembershipNtAccessCheck

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

Notas no documentadas

NtQueryInformationToken es la contraparte de lectura de NtSetInformationToken y lo que envuelve `advapi32!GetTokenInformation`. El SSN ha permanecido **estable en `0x21`** desde Windows 10 1507 hasta Windows 11 24H2. Las clases más útiles desde el lado ofensivo son `TokenUser` (SID de usuario), `TokenGroups` (SID de grupos — revela Administrators, BUILTIN\Backup Operators, etc.), `TokenPrivileges`, `TokenStatistics` (contiene el LUID necesario para vincular impersonación tipo `NtFilterToken`), `TokenIntegrityLevel`, `TokenElevation`, y `TokenLinkedToken` (el gemelo elevado del token usado por los bypass UAC Make-Me-Admin).

Uso común por malware

Los implantes usan NtQueryInformationToken para situational awareness justo tras el aterrizaje: ¿estamos elevados? ¿somos SYSTEM? ¿a qué grupos pertenecemos? ¿qué privilegios están activos? `TokenLinkedToken` es la pieza clave de la familia silenciosa de bypass UAC Make-Me-Admin (cadenas `AppInfo!RAiLaunchAdminProcess`): un proceso admin de IL medio consulta su propio token vinculado para obtener un handle al token de IL alto, luego duplica e impersona sin disparar consent.exe. `token::list` de Mimikatz simplemente enumera handles y llama a NtQueryInformationToken con `TokenUser` y `TokenStatistics`.

Oportunidades de detección

NtQueryInformationToken es extraordinariamente ruidoso en software legítimo — cada llamada COM, cada extensión shell, cada operación tipo `whoami` pasa por aquí. No es una detección útil por sí sola. Lo que sí es útil: correlacionar consultas `TokenLinkedToken` desde procesos de IL medio seguidas poco después por NtDuplicateToken + CreateProcessWithTokenW (patrón Make-Me-Admin), o consultas `TokenStatistics` seguidas inmediatamente por `NtSetInformationThread(ThreadImpersonationToken)` (cadena de impersonación). El provider ETW `Microsoft-Windows-Kernel-Audit-API-Calls` no registra específicamente las consultas de token; los defensores se apoyan habitualmente en el hook de user-mode del EDR sobre `ntdll!NtQueryInformationToken`.

Ejemplos de syscalls directos

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

Mapeos MITRE ATT&CK

Last verified: 2026-05-20