githubEdit

Token Manipulation

Token Manipulation

Tools: Meterpreter , CrackMapExec/Netexec , irs.exe , incognito.exe , masky

1) Meterpreter

  • use incognito

  • impersonate_token DOMAIN\USER

2) CrackMapExec/Netexec

  • netexec smb IP -u USER -p PASSWORD -M impersonate

3) irs.exe

  • irs.exe list

  • irs.exe exec --pid PID --command COMMAND

4) Incognito.exe

  • .\incognito.exe list_tokens -u

  • ./incognito.exe execute -c "DOMAIN\USER" powershell.exe

These techniques can give us further privileged ACLs to gain more cleartext credentials or creating persistent mechanisms

Extract credentials with certificate authentication (ADCS required)

  • masky -d DOMAIN -u USER (-p PASSWORD || -k || -H HASH) -ca CERTIFICATE_AUTHORITY IP

With this technique, we can perform Lateral movement via NTLM, Kerberos or Certificate.

List all tokens

List all tokens on the machine

List all unique, usable tokens on the machine

Start a new process with a specific token

Token of a user

Token of a process

Token impersonation with command execution and user addition

List available tokens, and find an interesting token ID

With only SeImpersonatePrivilege, if a privileged user's token is present on the machine, it is possible to run code on the domain as him and add a new user in the domain (and add him to the Domain Admins by default):

With SeImpersonatePrivilege and SeAssignPrimaryToken, if a privileged user's token is presents on the machine, it is possible to execute comands on the machine as him:

Token impersonation via session leaking

Basically, as long as a token is linked to a logon session (the ReferenceCount != 0), the logon session can't be closed, even if the user has logged off. AcquireCredentialsHandle() is used with a session LUID to increase the ReferenceCount and block the session release. Then InitializeSecurityContext() and AcceptSecurityContext() are used to negotiate a new security context, and QuerySecurityContextToken() get an usable token.

Server

List logon session

Monitor logon session with SID filtering

Capture one token per SID found in new logon sessions

Client part (only available as Cobalt Strike BOF for the moment)

List captured tokens

List group SIDs for a captured token

Impersonate a captured token by specifying the session LUID

Release all captured tokens

Tokens and ADCS

With administrative access to a (or multiple) computer, it is possible to retrieve the different process tokens, impersonate them and request CSRs and PEM certificate for the impersonated users.

Python

List available tokens, and find an interesting token ID

With only SeImpersonatePrivilege, if a privileged user's token is present on the machine, it is possible to run code on the domain as him and add a new user in the domain (and add him to the Domain Admins by default):

With SeImpersonatePrivilege and SeAssignPrimaryToken, if a privileged user's token is present on the machine, it is possible to execute commands on the machine as him:

Tokens and ADCS

With administrative access to a (or multiple) computer, it is possible to retrieve the different process tokens, impersonate them and request CSRs and PEM certificate for the impersonated users.

Last updated