Abusing Tokens
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
If you don't know what are Windows Access Tokens read this page before continuing:
Access TokensMaybe you could be able to escalate privileges abusing the tokens you already have
This is privilege that is held by any process allows the impersonation (but not creation) of any token, given that a handle to it can be obtained. A privileged token can be acquired from a Windows service (DCOM) by inducing it to perform NTLM authentication against an exploit, subsequently enabling the execution of a process with SYSTEM privileges. This vulnerability can be exploited using various tools, such as juicy-potato, RogueWinRM (which requires winrm to be disabled), SweetPotato, and PrintSpoofer.
RoguePotato, PrintSpoofer, SharpEfsPotato, GodPotatoJuicyPotatoIt is very similar to SeImpersonatePrivilege, it will use the same method to get a privileged token. Then, this privilege allows to assign a primary token to a new/suspended process. With the privileged impersonation token you can derivate a primary token (DuplicateTokenEx). With the token, you can create a new process with 'CreateProcessAsUser' or create a process suspended and set the token (in general, you cannot modify the primary token of a running process).
If you have enabled this token you can use KERB_S4U_LOGON to get an impersonation token for any other user without knowing the credentials, add an arbitrary group (admins) to the token, set the integrity level of the token to "medium", and assign this token to the current thread (SetThreadToken).
The system is caused to grant all read access control to any file (limited to read operations) by this privilege. It is utilized for reading the password hashes of local Administrator accounts from the registry, following which, tools like "psexec" or "wmiexec" can be used with the hash (Pass-the-Hash technique). However, this technique fails under two conditions: when the Local Administrator account is disabled, or when a policy is in place that removes administrative rights from Local Administrators connecting remotely. You can abuse this privilege with:
following IppSec in https://www.youtube.com/watch?v=IfCysW0Od8w&t=2610&ab_channel=IppSec
Or as explained in the escalating privileges with Backup Operators section of:
Permission for write access to any system file, irrespective of the file's Access Control List (ACL), is provided by this privilege. It opens up numerous possibilities for escalation, including the ability to modify services, perform DLL Hijacking, and set debuggers via Image File Execution Options among various other techniques.
SeCreateTokenPrivilege is a powerful permission, especially useful when a user possesses the ability to impersonate tokens, but also in the absence of SeImpersonatePrivilege. This capability hinges on the ability to impersonate a token that represents the same user and whose integrity level does not exceed that of the current process.
Key Points:
Impersonation without SeImpersonatePrivilege: It's possible to leverage SeCreateTokenPrivilege for EoP by impersonating tokens under specific conditions.
Conditions for Token Impersonation: Successful impersonation requires the target token to belong to the same user and have an integrity level that is less or equal to the integrity level of the process attempting impersonation.
Creation and Modification of Impersonation Tokens: Users can create an impersonation token and enhance it by adding a privileged group's SID (Security Identifier).
This privilege allows to load and unload device drivers with the creation of a registry entry with specific values for ImagePath
and Type
. Since direct write access to HKLM
(HKEY_LOCAL_MACHINE) is restricted, HKCU
(HKEY_CURRENT_USER) must be utilized instead. However, to make HKCU
recognizable to the kernel for driver configuration, a specific path must be followed.
This path is \Registry\User\<RID>\System\CurrentControlSet\Services\DriverName
, where <RID>
is the Relative Identifier of the current user. Inside HKCU
, this entire path must be created, and two values need to be set:
ImagePath
, which is the path to the binary to be executed
Type
, with a value of SERVICE_KERNEL_DRIVER
(0x00000001
).
Steps to Follow:
Access HKCU
instead of HKLM
due to restricted write access.
Create the path \Registry\User\<RID>\System\CurrentControlSet\Services\DriverName
within HKCU
, where <RID>
represents the current user's Relative Identifier.
Set the ImagePath
to the binary's execution path.
Assign the Type
as SERVICE_KERNEL_DRIVER
(0x00000001
).
More ways to abuse this privilege in https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/privileged-accounts-and-token-privileges#seloaddriverprivilege
This is similar to to SeRestorePrivilege. Its primary function allows a process to assume ownership of an object, circumventing the requirement for explicit discretionary access through the provision of WRITE_OWNER access rights. The process involves first securing ownership of the intended registry key for writing purposes, then altering the DACL to enable write operations.
This privilege permits the debug other processes, including to read and write in the memore. Various strategies for memory injection, capable of evading most antivirus and host intrusion prevention solutions, can be employed with this privilege.
You could use ProcDump from the SysInternals Suite to capture the memory of a process. Specifically, this can apply to the Local Security Authority Subsystem Service (LSASS) process, which is responsible for storing user credentials once a user has successfully logged into a system.
You can then load this dump in mimikatz to obtain passwords:
If you want to get a NT SYSTEM
shell you could use:
The tokens that appear as Disabled can be enable, you you actually can abuse Enabled and Disabled tokens.
If you have tokens disables, you can use the script EnableAllTokenPrivs.ps1 to enable all the tokens:
Or the script embed in this post.
Full token privileges cheatsheet at https://github.com/gtworek/Priv2Admin, summary below will only list direct ways to exploit the privilege to obtain an admin session or read sensitive files.
Privilege | Impact | Tool | Execution path | Remarks |
---|---|---|---|---|
| Admin | 3rd party tool | "It would allow a user to impersonate tokens and privesc to nt system using tools such as potato.exe, rottenpotato.exe and juicypotato.exe" | Thank you Aurélien Chalot for the update. I will try to re-phrase it to something more recipe-like soon. |
| Threat | Built-in commands | Read sensitve files with | - May be more interesting if you can read %WINDIR%\MEMORY.DMP
- |
| Admin | 3rd party tool | Create arbitrary token including local admin rights with | |
| Admin | PowerShell | Duplicate the | Script to be found at FuzzySecurity |
| Admin | 3rd party tool | 1. Load buggy kernel driver such as | 1. The |
| Admin | PowerShell | 1. Launch PowerShell/ISE with the SeRestore privilege present. 2. Enable the privilege with Enable-SeRestorePrivilege). 3. Rename utilman.exe to utilman.old 4. Rename cmd.exe to utilman.exe 5. Lock the console and press Win+U | Attack may be detected by some AV software. Alternative method relies on replacing service binaries stored in "Program Files" using the same privilege |
| Admin | Built-in commands | 1. | Attack may be detected by some AV software. Alternative method relies on replacing service binaries stored in "Program Files" using the same privilege. |
| Admin | 3rd party tool | Manipulate tokens to have local admin rights included. May require SeImpersonate. To be verified. |
Take a look to this table defining Windows tokens: https://github.com/gtworek/Priv2Admin
Take a look to this paper about privesc with tokens.
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)