Access Token Manipulation

Adversaries may modify access tokens to operate under a different user or system security context to perform actions and bypass access controls. Windows uses access tokens to determine the ownership of a running process. A user can manipulate access tokens to make a running process appear as though it is the child of a different process or belongs to someone other than the user that started the process. When this occurs, the process also takes on the security context associated with the new token.

An adversary can use built-in Windows API functions to copy access tokens from existing processes; this is known as token stealing. These token can then be applied to an existing process (i.e. Token Impersonation/Theft) or used to spawn a new process (i.e. Create Process with Token). An adversary must already be in a privileged user context (i.e. administrator) to steal a token. However, adversaries commonly use token stealing to elevate their security context from the administrator level to the SYSTEM level. An adversary can then use a token to authenticate to a remote system as the account for that token if the account has appropriate permissions on the remote system.[1]

Any standard user can use the runas command, and the Windows API functions, to create impersonation tokens; it does not require access to an administrator account. There are also other mechanisms, such as Active Directory fields, that can be used to modify access tokens.

ID: T1134
Tactics: Defense Evasion, Privilege Escalation
Platforms: Windows
Permissions Required: Administrator, User
Effective Permissions: SYSTEM
Data Sources: API monitoring, Access tokens, Authentication logs, Process command-line parameters, Process monitoring, Windows event logs
Defense Bypassed: File system access controls, Heuristic Detection, Host forensic analysis, System access controls, Windows User Account Control
CAPEC ID: CAPEC-633
Contributors: Jared Atkinson, @jaredcatkinson; Robby Winchester, @robwinchester3; Tom Ueltschi @c_APT_ure; Travis Smith, Tripwire
Version: 2.0
Created: 14 December 2017
Last Modified: 16 April 2020

Procedure Examples

Name Description
Blue Mockingbird

Blue Mockingbird has used JuicyPotato to abuse the SeImpersonate token privilege to escalate from web application pool accounts to NT Authority\SYSTEM.[13]

Duqu

Duqu examines running system processes for tokens that have specific system privileges. If it finds one, it will copy the token and store it for later use. Eventually it will start new processes with the stored token attached. It can also steal tokens to acquire administrative privileges.[9]

Empire

Empire can use PowerSploit's Invoke-TokenManipulation to manipulate access tokens.[7]

Hydraq

Hydraq creates a backdoor through which remote attackers can adjust token privileges.[10]

PoshC2

PoshC2 can use Invoke-TokenManipulation for manipulating tokens.[8]

PowerSploit

PowerSploit's Invoke-TokenManipulation Exfiltration module can be used to manipulate tokens.[5][6]

Ryuk

Ryuk has attempted to adjust its token privileges to have the SeDebugPrivilege.[12]

SslMM

SslMM contains a feature to manipulate process privileges and tokens.[11]

Mitigations

Mitigation Description
Privileged Account Management

Limit permissions so that users and user groups cannot create tokens. This setting should be defined for the local system account only. GPO: Computer Configuration > [Policies] > Windows Settings > Security Settings > Local Policies > User Rights Assignment: Create a token object. [2] Also define who can create a process level token to only the local and network service through GPO: Computer Configuration > [Policies] > Windows Settings > Security Settings > Local Policies > User Rights Assignment: Replace a process level token.[3]

Administrators should log in as a standard user but run their tools with administrator privileges using the built-in access token manipulation command runas.[4]

User Account Management

An adversary must already have administrator level access on the local system to make full use of this technique; be sure to restrict users and accounts to the least privileges they require.

Detection

If an adversary is using a standard command-line shell, analysts can detect token manipulation by auditing command-line activity. Specifically, analysts should look for use of the runas command. Detailed command-line logging is not enabled by default in Windows.[14]

If an adversary is using a payload that calls the Windows token APIs directly, analysts can detect token manipulation only through careful analysis of user network activity, examination of running processes, and correlation with other endpoint and network behavior.

There are many Windows API calls a payload can take advantage of to manipulate access tokens (e.g., LogonUser [15], DuplicateTokenEx[16], and ImpersonateLoggedOnUser[17]). Please see the referenced Windows API pages for more information.

Query systems for process and thread token information and look for inconsistencies such as user owns processes impersonating the local SYSTEM account.[18]

Look for inconsistencies between the various fields that store PPID information, such as the EventHeader ProcessId from data collected via Event Tracing for Windows (ETW), Creator Process ID/Name from Windows event logs, and the ProcessID and ParentProcessID (which are also produced from ETW and other utilities such as Task Manager and Process Explorer). The ETW provided EventHeader ProcessId identifies the actual parent process.

References