π₯SeImpersonate & SeAssignPrimaryToken
π― Overview
SeImpersonate and SeAssignPrimaryToken are powerful privileges that allow escalation from service accounts to SYSTEM level access. These privileges enable processes to impersonate other users' security tokens, commonly exploited through "Potato-style" attacks.
π Token Impersonation Fundamentals
Access Token Concepts
Process tokens contain security context information
Token impersonation allows assuming another user's identity
SeImpersonatePrivilege required to utilize stolen tokens
Memory-based attacks target token locations in process memory
Key Privileges
SeImpersonatePrivilege # Impersonate client after authentication
SeAssignPrimaryTokenPrivilege # Replace process level tokenCommon Service Account Context:
IIS application pools
SQL Server service accounts
Jenkins execution contexts
MSSQL xp_cmdshell execution
π₯ Potato Attack Family
Attack Mechanism
Service account has SeImpersonatePrivilege but limited SYSTEM access
Potato attack tricks SYSTEM process to connect to attacker-controlled process
Token handover occurs during connection authentication
Token abuse elevates privileges to NT AUTHORITY\SYSTEM
JuicyPotato - Legacy Systems
Prerequisites
SeImpersonate OR SeAssignPrimaryToken privilege
Windows Server 2016 and earlier (before build 1809)
DCOM/NTLM reflection capabilities
Basic Usage
Parameters:
-l- COM server listening port-p- Program to launch-a- Arguments passed to program-t- CreateProcess call type (* = try both)
PrintSpoofer - Modern Systems
Advantages
Windows Server 2019 and Windows 10 build 1809+ compatible
Print Spooler service abuse mechanism
Multiple execution modes available
Usage Examples
RoguePotato - Alternative Approach
OXID resolver abuse technique
Named pipe impersonation method
Server 2019 and Windows 10 compatible
π» Practical Exploitation Scenario
SQL Server Service Account Compromise
Initial Access via MSSQL
Privilege Assessment
JuicyPotato Exploitation
PrintSpoofer Alternative
Verification
π οΈ Tool Comparison
JuicyPotato
β€ Server 2016
DCOM/NTLM Reflection
High
PrintSpoofer
Server 2019+ Win10 1809+
Print Spooler Service
High
RoguePotato
Server 2019+ Win10+
OXID Resolver
Medium
SweetPotato
Universal
Multiple methods
High
π― HTB Academy Lab Solution
Lab Environment
Target:
10.129.43.43(ACADEMY-WINLPE-SRV01)Credentials:
sql_dev:Str0ng_P@ssw0rd!Objective: Escalate privileges and retrieve flag
Detailed Step-by-Step Solution
1. Initial Connection with MSSQL
2. Enable xp_cmdshell for Command Execution
3. Enumerate Privileges - Key Step!
β
Critical Finding: SeImpersonatePrivilege is Enabled - this allows privilege escalation!
4. Set Up Reverse Shell Listener (New Terminal)
5. Execute PrintSpoofer Privilege Escalation
6. Receive SYSTEM Shell
7. Verify SYSTEM Access & Retrieve Flag
Alternative Methods
Using JuicyPotato (for older systems)
Key Success Indicators
β SeImpersonatePrivilege Enabled - Confirmed in step 3
β PrintSpoofer Success Message -
[+] Found privilege: SeImpersonatePrivilegeβ SYSTEM Shell Received -
whoamireturnsnt authority\systemβ Flag Retrieved - Successfully read from Administrator desktop
Troubleshooting Common Issues
If PrintSpoofer Fails:
If Connection Issues:
If Tools Not Present:
π Detection Indicators
Process Behavior
Event Logs
Event ID 4648 - Explicit credential logon (token impersonation)
Event ID 4672 - Special privileges assigned to logon
Event ID 4624 - Account logon events
π‘οΈ Defense Strategies
Privilege Hardening
Detection Rules
π SeImpersonate Exploitation Checklist
Prerequisites
Execution Steps
Post-Exploitation
π‘ Key Takeaways
SeImpersonate privilege is extremely powerful for privilege escalation
Service accounts commonly have this privilege enabled
Tool selection depends on target OS version and build
Multiple techniques available - always have backups ready
Common attack vector - expect this in most web applications
High success rate when prerequisites are met
SeImpersonate privilege escalation remains one of the most reliable Windows privilege escalation techniques, particularly in service account compromise scenarios.
Last updated