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 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. For example, Microsoft promotes the use of access tokens as a security best practice. Administrators should log in as a standard user but run their tools with administrator privileges using the built-in access token manipulation commandrunas
. (Citation: Microsoft runas)Adversaries may use access tokens to operate under a different user or system security context to perform actions and evade detection. An adversary can use built-in Windows API functions to copy access tokens from existing processes; this is known as token stealing. 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 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. (Citation: Pentestlab Token Manipulation)
Access tokens can be leveraged by adversaries through three methods: (Citation: BlackHat Atkinson Winchester Token Manipulation)
'''Token Impersonation/Theft''' - An adversary creates a new access token that duplicates an existing token using
DuplicateToken(Ex)
. The token can then be used withImpersonateLoggedOnUser
to allow the calling thread to impersonate a logged on user's security context, or withSetThreadToken
to assign the impersonated token to a thread. This is useful for when the target user has a non-network logon session on the system.'''Create Process with a Token''' - An adversary creates a new access token with
DuplicateToken(Ex)
and uses it withCreateProcessWithTokenW
to create a new process running under the security context of the impersonated user. This is useful for creating a new process under the security context of a different user.'''Make and Impersonate Token''' - An adversary has a username and password but the user is not logged onto the system. The adversary can then create a logon session for the user using the
LogonUser
function. The function will return a copy of the new session's access token and the adversary can useSetThreadToken
to assign the token to a thread.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.Metasploit’s Meterpreter payload allows arbitrary token manipulation and uses token impersonation to escalate privileges. (Citation: Metasploit access token) The Cobalt Strike beacon payload allows arbitrary token impersonation and can also create tokens. (Citation: Cobalt Strike Access Token)
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. (Citation: Microsoft Command-line Logging)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
(Citation: Microsoft LogonUser),DuplicateTokenEx
(Citation: Microsoft DuplicateTokenEx), andImpersonateLoggedOnUser
(Citation: Microsoft ImpersonateLoggedOnUser)). 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. (Citation: BlackHat Atkinson Winchester Token Manipulation)
Platforms: Windows
Data Sources: API monitoring, Access Tokens
Effective Permissions: SYSTEM
Permissions Required: User, Administrator
Contributors: Tom Ueltschi @c_APT_ure, Travis Smith, Tripwire, Jared Atkinson, @jaredcatkinson, Robby Winchester, @robwinchester3
Creates a process as another user Requires Administrator Privileges To Execute Test
Supported Platforms: Windows
Name | Description | Type | Default Value |
---|---|---|---|
target_user | Username To Steal Token From | String | SYSTEM |
#list processes by user,
$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}
#Steal Token
. .\src\T1134.ps1