Windows Access Tokens and Security Context: The Authorization Core
Concept
Section titled โConceptโAn Access Token is a Windows kernel object (nt!_TOKEN) generated by the Local Security Authority Subsystem Service (LSASS) upon successful authentication. It encapsulates the complete security context required for authorization decisions:
- User SID: The primary identity of the account.
- Group SIDs: All local, domain, and well-known group memberships evaluated at logon.
- Privileges List: Operating system capabilities assigned to the principal (
SeDebugPrivilege,SeImpersonatePrivilege), each marked asEnabledorDisabled. - Integrity Level: Mandatory Integrity Control (MIC) classification: Untrusted, Low, Medium, High, or System.
- Token Type: Primary Token (bound to a process) or Impersonation Token (bound to an individual thread to temporarily act on behalf of a client).
- Authentication ID & Logon Session: Unique LUID referencing the logon session.
Why This Matters in DFIR
Section titled โWhy This Matters in DFIRโUnderstanding access tokens is vital to deconstructing in-memory attacks and privilege escalation:
- Token Theft & Impersonation (T1134): An attacker with
SYSTEMrights on a server can inspect memory, duplicate an administratorโs access token (viaincognitoor Mimikatztoken::elevate), and spawn processes under that identity without knowing their credentials. - User Account Control (UAC) Filtering: Interactive administrators receive a split token. By default, processes run under a
Medium Integritytoken stripped of administrative SIDs and privileges. Un-elevated malicious activity will fail against protected resources. SeImpersonatePrivilegeExploitation (Potato Attacks): Service accounts (e.g., IIS pools, SQL service) holding this privilege can force aSYSTEMprocess to authenticate against a local named pipe, capture its token, and elevate immediately.
How It Works
Section titled โHow It Worksโ1. Token Anatomy
Section titled โ1. Token Anatomyโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Access Token โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ User SID : S-1-5-21-...-1105 (jdoe) โ โ Group SIDs : S-1-5-21-...-513 (Domain Users) โ โ S-1-5-32-544 (Administrators) โ โ S-1-1-0 (Everyone) โ โ S-1-5-11 (Authenticated Users) โ โ Privileges : SeChangeNotifyPrivilege (En) โ โ SeDebugPrivilege (Disabled) โ โ Integrity : High (S-1-16-12288) โ โ Token Type : Primary โ โ Impersonation Level : SecurityImpersonation โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโWhen a process calls CreateProcess, the child process inherits a duplicate of the parentโs primary token by default.
2. Primary vs Impersonation Tokens
Section titled โ2. Primary vs Impersonation Tokensโ- Primary Token: Associated with the process. Applied to all threads unless thread-level impersonation is active.
- Impersonation Token: Applied to a specific thread to perform operations in the security context of a client:
SecurityAnonymous: Client identity is unknown.SecurityIdentification: Server knows client identity and SIDs, but cannot access securable objects on its behalf.SecurityImpersonation: Server can access local securable objects on behalf of the client.SecurityDelegation: Server can access remote network resources on behalf of the client (requires Kerberos delegation).
What Is Possible
Section titled โWhat Is Possibleโ- Duplicating Tokens Across Processes: Using
DuplicateTokenEx, an elevated process can copy a token from another session and spawn processes under that user identity. - Enabling Disabled Privileges: If a privilege is present in a token with the
Disabledflag, the process can enable it on demand viaAdjustTokenPrivileges. - Dropping Privileges (Restricted Tokens): Sandboxed applications (e.g., Chrome, Edge) can strip groups and privileges to spawn child processes at
Low Integrity.
What Is Not Possible
Section titled โWhat Is Not Possibleโ- Injecting New SIDs into an Active Token: Once created by LSASS, the SID array within a token is immutable. Gaining new group memberships requires creating a new logon session.
- Writing Objects Under
IdentificationLevel: The SRM strictly blocks access requests requiring write permissions if the threadโs impersonation level is belowSecurityImpersonation. - Reaching Network Hosts with a Stolen Local Token: A stolen access token lacks Kerberos session keys and cannot traverse to remote machines without explicit delegation.
Forensic Traps
Section titled โForensic TrapsโConcrete DFIR Scenario: Named Pipe Impersonation
Section titled โConcrete DFIR Scenario: Named Pipe Impersonationโ- An adversary compromises an IIS application running under
IIS APPPOOL\DefaultAppPool. - Execution of
whoami /privrevealsSeImpersonatePrivilege : Enabled. - The attacker deploys
PrintSpooferorSweetPotato. - The tool creates a local named pipe (
\\.\pipe\spoolss) and triggers the print spooler service (SYSTEM) to validate an RPC binding against it. - When the spooler connects, the exploit calls
ImpersonateNamedPipeClient(). - The thread adopts the spoolerโs
SYSTEMtoken and callsCreateProcessWithTokenW()to spawn an interactive shell with fullSYSTEMauthority.
Forensic Artifacts
Section titled โForensic ArtifactsโEventID: 4672 # Special Privileges Assigned to New LogonSubjectUserName: AdministratorPrivilegeList: SeDebugPrivilege SeImpersonatePrivilege SeTcbPrivilege
Sysmon EventID 10 # Process Access (Token Duplication)SourceImage: C:\Users\Public\mimikatz.exeTargetImage: C:\Windows\System32\lsass.exeGrantedAccess: 0x1410 # PROCESS_VM_READ | PROCESS_QUERY_INFORMATIONKey Takeaways
Section titled โKey Takeawaysโ- The Windows kernel authorizes processes and threads via tokens, not usernames.
- Tokens are snapshot copies of SIDs and privileges frozen at authentication time.
SeImpersonatePrivilegeallows service accounts to escalate directly toSYSTEM.- UAC splits administrative tokens into Medium (filtered) and High (elevated) pairs.