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 /priv

The 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:

Privilege
Description
Potential Abuse

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

  1. Verify privileges are present:

  2. Backup the SAM and SYSTEM registry hives:

  3. Transfer the hives to your attack machine using SMB or other methods:

  4. Extract password hashes using impacket:

  5. Use the hashes for Pass-the-Hash attacks:

SeTakeOwnership Exploitation

This privilege allows taking ownership of any object in the system.

Exploitation Steps

  1. Verify the privilege is present:

  2. Take ownership of a critical system file (e.g., utilman.exe):

  3. Grant yourself full permissions:

  4. Replace the file with a copy of cmd.exe:

  5. 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:

  1. User authenticates to a service

  2. Service with impersonation privileges can use the user's token

  3. 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.

  1. Verify impersonation privileges:

  2. Setup a listener on your attack machine:

  3. Run the RogueWinRM exploit:

  4. 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

  1. Verify the privilege is present:

  2. Use mimikatz to extract credentials from LSASS process:

  3. 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.

  1. Identify that we have the required privileges:

  2. Exploit to extract registry hives:

  3. Extract hashes and gain access:

Mitigations

To protect against privilege abuse:

  1. Limit the assignment of powerful privileges to only necessary users

  2. Use Protected Process Light (PPL) for critical processes

  3. Implement Just Enough Administration (JEA) for administrative tasks

  4. Use Windows Defender Credential Guard to protect against credential theft

  5. Regular audit privilege assignments with security baseline tools

  6. 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:

  1. A local NBNS (NetBIOS Name Service) spoofer

  2. A fake WPAD (Web Proxy Auto-Discovery) proxy server

  3. 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

  1. The attack tool starts a local NBNS spoofer that responds to broadcast NBNS queries

  2. It also starts a rogue WPAD proxy server

  3. When Windows tries to resolve the WPAD server (for proxy settings), the NBNS spoofer provides a response pointing to the attacker's machine

  4. Windows attempts to connect to the fake WPAD server using NTLM authentication

  5. The NTLM authentication attempt is relayed back to the local system, creating a SYSTEM token

  6. 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:

  1. Apply the latest Windows security updates

  2. Restrict the assignment of SeImpersonatePrivilege and SeAssignPrimaryTokenPrivilege

  3. Use Protected Users security group for sensitive accounts

  4. Implement network segmentation to prevent NBNS/WPAD spoofing

  5. Use WPAD Group Policy settings to disable automatic proxy discovery

  6. 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