Token Impersonation
Windows privileges are powerful rights assigned to user accounts that can be abused for privilege escalation. This document focuses on how to identify and exploit common Windows token privileges.
Understanding Windows Privileges
Each Windows user has a set of assigned privileges that control what system-level operations they can perform. These privileges are independent of regular file/object permissions and can often be abused to escalate to higher access levels.
Checking Privileges
To check the privileges assigned to your current token:
whoami /privThe output will show all privileges and their state (Enabled/Disabled). A privilege must typically be enabled to be used, but some exploits can enable disabled privileges.
Exploitable Privileges
The most commonly abusable privileges include:
SeBackupPrivilege
Allows reading any file
Extract sensitive files (SAM, SYSTEM)
SeRestorePrivilege
Allows writing any file
Replace system files
SeTakeOwnershipPrivilege
Take ownership of any object
Replace system executables
SeImpersonatePrivilege
Impersonate clients
Use for token impersonation attacks
SeAssignPrimaryTokenPrivilege
Replace process token
Similar to impersonation
SeLoadDriverPrivilege
Load and unload drivers
Load malicious kernel drivers
SeDebugPrivilege
Debug any process
Access restricted processes, read memory
SeCreateTokenPrivilege
Create tokens
Create custom privileged tokens
SeBackup / SeRestore Exploitation
These privileges allow reading and writing to any file on the system, ignoring DACLs.
Exploitation Steps
Verify privileges are present:
Backup the SAM and SYSTEM registry hives:
Transfer the hives to your attack machine using SMB or other methods:
Extract password hashes using impacket:
Use the hashes for Pass-the-Hash attacks:
SeTakeOwnership Exploitation
This privilege allows taking ownership of any object in the system.
Exploitation Steps
Verify the privilege is present:
Take ownership of a critical system file (e.g., utilman.exe):
Grant yourself full permissions:
Replace the file with a copy of cmd.exe:
Lock the screen and click the "Ease of Access" button to spawn a SYSTEM shell
SeImpersonate / SeAssignPrimaryToken Exploitation
These privileges allow a process to impersonate other users.
How Token Impersonation Works
In Windows, services often need to perform actions on behalf of users. The impersonation privileges allow a service to "borrow" the access token of a connecting user:
User authenticates to a service
Service with impersonation privileges can use the user's token
Service can perform actions with the user's security context
Common Vulnerable Accounts
LOCAL SERVICE
NETWORK SERVICE
IIS Application Pool Identities (e.g., "iis apppool\defaultapppool")
Exploitation with RogueWinRM
The RogueWinRM attack exploits the fact that the BITS service connects to port 5985 (WinRM) using SYSTEM privileges when started.
Verify impersonation privileges:
Setup a listener on your attack machine:
Run the RogueWinRM exploit:
When the BITS service starts, it will connect to your fake WinRM service, allowing you to impersonate the SYSTEM user
Alternative: Potato Attacks
Several "Potato" attacks exist that abuse impersonation privileges:
JuicyPotato - Works on Windows 7, 8, 10, Server 2008, and Server 2012
RoguePotato - Works on newer systems with some adjustments
PrintSpoofer - Exploits the Print Spooler service
Example with PrintSpoofer:
SeDebug Exploitation
SeDebug allows you to debug any process, including those run by SYSTEM.
Exploitation Steps
Verify the privilege is present:
Use mimikatz to extract credentials from LSASS process:
Alternatively, dump the LSASS process and analyze offline:
Real-World Example: SeBackup / SeRestore
A server administrator created a "Backup Operators" group and added a user for backup purposes. This user had the SeBackup and SeRestore privileges.
Identify that we have the required privileges:
Exploit to extract registry hives:
Extract hashes and gain access:
Mitigations
To protect against privilege abuse:
Limit the assignment of powerful privileges to only necessary users
Use Protected Process Light (PPL) for critical processes
Implement Just Enough Administration (JEA) for administrative tasks
Use Windows Defender Credential Guard to protect against credential theft
Regular audit privilege assignments with security baseline tools
Consider using AppLocker or similar to restrict execution of known exploitation tools
OSCP Notes
For the OSCP exam, focus on the following privileges:
SeBackup / SeRestore (registry hive extraction)
SeTakeOwnership (system file replacement)
SeImpersonate / SeAssignPrimaryToken (token impersonation attacks)
These attacks typically don't require complex tools, making them suitable for the exam environment.
The Potato Attacks (Hot Potato, Rotten Potato, Juicy Potato)
"Potato" attacks are a family of privilege escalation techniques that exploit Windows token impersonation to elevate privileges from a standard user to SYSTEM. These attacks leverage various Windows services and protocols to obtain a SYSTEM token that can be impersonated.
Hot Potato
Hot Potato (aka: Potato) is a technique that combines:
A local NBNS (NetBIOS Name Service) spoofer
A fake WPAD (Web Proxy Auto-Discovery) proxy server
NTLM relay attack
It exploits the way Windows resolves names through NBNS and how it uses WPAD for proxy discovery, combined with NTLM relay to elevate privileges.
Requirements for Hot Potato
Windows 7, 8, or early builds of Windows 10 / Windows Server 2016
Local administrator rights (to create the necessary sockets)
SeImpersonatePrivilege or SeAssignPrimaryTokenPrivilege
How Hot Potato Works
The attack tool starts a local NBNS spoofer that responds to broadcast NBNS queries
It also starts a rogue WPAD proxy server
When Windows tries to resolve the WPAD server (for proxy settings), the NBNS spoofer provides a response pointing to the attacker's machine
Windows attempts to connect to the fake WPAD server using NTLM authentication
The NTLM authentication attempt is relayed back to the local system, creating a SYSTEM token
Using SeImpersonatePrivilege, the attacker impersonates this token and executes commands as SYSTEM
Using Hot Potato
Rotten Potato
Rotten Potato is an evolution of Hot Potato that focuses solely on the NTLM relay component. It exploits the DCOM (Distributed Component Object Model) service to force authentication and obtain a SYSTEM token.
Requirements for Rotten Potato
SeImpersonatePrivilege or SeAssignPrimaryTokenPrivilege
Works on Windows 8.1, 10, Server 2012, Server 2016
Using Rotten Potato
Juicy Potato
Juicy Potato is a further refinement that exploits the COM marshalling mechanism in Windows. It leverages the fact that some COM servers run as SYSTEM and allow for token impersonation.
Requirements for Juicy Potato
SeImpersonatePrivilege or SeAssignPrimaryTokenPrivilege
Windows versions before certain security patches (doesn't work on Windows Server 2019)
Using Juicy Potato
Note: The CLSID (-c parameter) depends on the Windows version. A list of CLSIDs can be found in the Juicy Potato repository.
Sweet Potato
Sweet Potato combines techniques from both Rotten and Juicy Potato but works on newer Windows versions where Juicy Potato fails, including Windows 10 and Server 2019.
Using Sweet Potato
PrintSpoofer and RoguePotato
These are newer alternatives when Juicy/Sweet Potato doesn't work:
Mitigation Against Potato Attacks
To defend against these attacks:
Apply the latest Windows security updates
Restrict the assignment of SeImpersonatePrivilege and SeAssignPrimaryTokenPrivilege
Use Protected Users security group for sensitive accounts
Implement network segmentation to prevent NBNS/WPAD spoofing
Use WPAD Group Policy settings to disable automatic proxy discovery
Monitor for suspicious process creation and token manipulation events
OSCP Exam Notes
For the OSCP exam:
Hot Potato is useful for older Windows systems
Juicy Potato works well on Windows 7 through early Windows 10
Always check for SeImpersonatePrivilege or SeAssignPrimaryTokenPrivilege first
Have multiple versions of potato exploits ready
Document the specific technique and parameters used
Last updated