Hacktricks-skills windows-named-pipe-impersonation
Windows local privilege escalation via named pipe client impersonation. Use this skill whenever the user mentions privilege escalation, named pipes, ImpersonateNamedPipeClient, Potato attacks, PrintSpoofer, RoguePotato, JuicyPotato, EFSRPC, or wants to escalate from a privileged user to SYSTEM on Windows. This skill helps generate exploit code, identify coercion triggers, and troubleshoot impersonation issues.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation/SKILL.MDWindows Named Pipe Client Impersonation
This skill helps you perform local privilege escalation on Windows by exploiting named pipe client impersonation. The core technique: create a named pipe, coerce a privileged service to connect, impersonate that client's token, and spawn a SYSTEM process.
When to use this skill
Use this skill when:
- You need to escalate privileges on Windows from a privileged user to SYSTEM
- You're working with named pipes and want to impersonate a connecting client
- You need to generate exploit code for PrintSpoofer, RoguePotato, JuicyPotato, or similar techniques
- You're troubleshooting
(1368) orERROR_CANNOT_IMPERSONATE
(1314)ERROR_PRIVILEGE_NOT_HELD - You want to understand how to coerce SYSTEM services to connect to your pipe
Core technique
The attack flow:
- Create a named pipe at
\\.\pipe\<random-name> - Wait for a privileged client (SYSTEM service) to connect
- Read at least one message from the pipe (required before impersonation)
- Call
to adopt the client's security contextImpersonateNamedPipeClient - Duplicate the impersonation token into a primary token
- Spawn a process as the client (typically SYSTEM)
Required privileges
| Privilege | Purpose |
|---|---|
| Required for and |
| May be needed for |
| May be needed for |
Note: When impersonating SYSTEM, the last two are typically satisfied automatically.
Generate exploit code
C implementation
Run the C code generator script to create a minimal named pipe impersonation exploit:
python scripts/generate_c_exploit.py --pipe-name <name> --output <path>
This generates a complete C program with:
- Named pipe creation and connection handling
- Message reading before impersonation
- Token duplication with
DuplicateTokenEx - Process spawning with
orCreateProcessWithTokenWCreateProcessAsUser - Proper cleanup with
RevertToSelf
.NET implementation
Run the .NET code generator script:
python scripts/generate_dotnet_exploit.py --pipe-name <name> --output <path>
This generates a C# program using
NamedPipeServerStream.RunAsClient with P/Invoke for token manipulation.
Common coercion triggers
To get SYSTEM to connect to your pipe, use one of these triggers:
| Trigger | Tool | Description |
|---|---|---|
| Print Spooler RPC | PrintSpoofer | Coerces spoolsv.exe via RPC |
| DCOM activation | RoguePotato | Uses DCOM/NTLM reflection |
| DCOM variants | JuicyPotato/JuicyPotatoNG | Multiple DCOM interfaces |
| EFSRPC | EfsPotato/SharpEfsPotato | Encrypting File System RPC |
| GodPotato | GodPotato | DCOM with SeImpersonatePrivilege |
Print Spooler (PrintSpoofer)
Most reliable on modern Windows. The spooler service connects to named pipes during RPC operations.
DCOM-based (RoguePotato/JuicyPotato)
Works by activating DCOM objects that connect to your pipe. JuicyPotatoNG has the most interface coverage.
EFSRPC (EfsPotato)
Targets the Encrypting File System RPC interface. Works on systems with EFS enabled.
Troubleshooting
ERROR_CANNOT_IMPERSONATE (1368)
Cause: You didn't read from the pipe before calling
ImpersonateNamedPipeClient, or the client restricted impersonation level.
Fix:
- Ensure you call
at least once beforeReadFileImpersonateNamedPipeClient - Check the client's impersonation level with
GetTokenInformation(TokenImpersonationLevel) - If the client used
, you cannot fully impersonateSECURITY_IDENTIFICATION
ERROR_PRIVILEGE_NOT_HELD (1314)
Cause:
CreateProcessWithTokenW requires SeImpersonatePrivilege on the caller.
Fix:
- Enable
in your process token before callingSeImpersonatePrivilege - Or use
after you've already impersonated SYSTEMCreateProcessAsUser
Client won't connect
Cause: The service doesn't know about your pipe, or ACLs block connection.
Fix:
- Use a coercion trigger (PrintSpoofer, RoguePotato, etc.)
- Check your pipe's security descriptor allows the target service
- Default pipes under
are accessible per the server's DACL\\.\pipe
Advanced: Named pipe MITM
For hardened services, you can instrument the trusted client:
- DLL injection: Inject a helper DLL into the client process
- API hooking: Detour
/ReadFile
whenWriteFile
reportsGetFileTypeFILE_TYPE_PIPE - Proxy traffic: Copy buffers to a control pipe, edit/drop/replay, then resume
- PID validation bypass: Connect from inside the trusted process so the server sees the legitimate PID
Tools like pipetap implement this pattern.
Operational notes
- Named pipes are low-latency; long pauses while editing buffers can deadlock services
- Overlapped/completion-port I/O coverage is partial; expect edge cases
- Injection is noisy and unsigned; treat as lab/exploit-dev helper, not stealth implant
- Use VM snapshots when crash-testing fragile IPC parsers