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.