πŸ₯”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 token

Common Service Account Context:

  • IIS application pools

  • SQL Server service accounts

  • Jenkins execution contexts

  • MSSQL xp_cmdshell execution

πŸ₯” Potato Attack Family

Attack Mechanism

  1. Service account has SeImpersonatePrivilege but limited SYSTEM access

  2. Potato attack tricks SYSTEM process to connect to attacker-controlled process

  3. Token handover occurs during connection authentication

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

Tool
OS Support
Method
Reliability

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

  1. βœ… SeImpersonatePrivilege Enabled - Confirmed in step 3

  2. βœ… PrintSpoofer Success Message - [+] Found privilege: SeImpersonatePrivilege

  3. βœ… SYSTEM Shell Received - whoami returns nt authority\system

  4. βœ… 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

  1. SeImpersonate privilege is extremely powerful for privilege escalation

  2. Service accounts commonly have this privilege enabled

  3. Tool selection depends on target OS version and build

  4. Multiple techniques available - always have backups ready

  5. Common attack vector - expect this in most web applications

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