Skip to content

Commit 10b0e03

Browse files
authored
Merge pull request #1644 from HackTricks-wiki/update_pipetap__a_Windows_named_pipe_proxy_tool_20251207_123451
pipetap a Windows named pipe proxy tool
2 parents 422ff97 + 7050dc2 commit 10b0e03

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

src/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,51 @@ from-high-integrity-to-system-with-name-pipes.md
122122
service-triggers.md
123123
{{#endref}}
124124

125+
## Named Pipe IPC Abuse & MITM (DLL Injection, API Hooking, PID Validation Bypass)
126+
127+
Named-pipe hardened services can still be hijacked by instrumenting the trusted client. Tools like [pipetap](https://sensepost.com/blog/2025/pipetap-a-windows-named-pipe-proxy-tool/) drop a helper DLL into the client, proxy its traffic, and let you tamper with privileged IPC before the SYSTEM service consumes it.
128+
129+
### Inline API hooking inside trusted processes
130+
- Inject the helper DLL (OpenProcess → CreateRemoteThread → LoadLibrary) into any client.
131+
- The DLL Detours `ReadFile`, `WriteFile`, etc., but only when `GetFileType` reports `FILE_TYPE_PIPE`, copies each buffer/metadata to a control pipe, lets you edit/drop/replay it, then resumes the original API.
132+
- Turns the legitimate client into a Burp-style proxy: pause UTF-8/UTF-16/raw payloads, trigger error paths, replay sequences, or export JSON traces.
133+
134+
### Remote client mode to defeat PID-based validation
135+
- Inject into an allow-listed client, then in the GUI choose the pipe plus that PID.
136+
- The DLL issues `CreateFile`/`ConnectNamedPipe` inside the trusted process and relays the I/O back to you, so the server still observes the legitimate PID/image.
137+
- Bypasses filters that rely on `GetNamedPipeClientProcessId` or signed-image checks.
138+
139+
### Fast enumeration and fuzzing
140+
- `pipelist` enumerates `\\.\pipe\*`, shows ACLs/SIDs, and forwards entries to other modules for immediate probing.
141+
- The pipe client/message composer connects to any name and builds UTF-8/UTF-16/raw-hex payloads; import captured blobs, mutate fields, and resend to hunt deserializers or unauthenticated command verbs.
142+
- The helper DLL can host a loopback TCP listener so tooling/fuzzers can drive the pipe remotely via the Python SDK.
143+
144+
```bash
145+
pip install pipetap
146+
```
147+
148+
```python
149+
import pipetap
150+
client = pipetap.Client(("127.0.0.1", 47001))
151+
client.write(b"OP\x00\x01...")
152+
```
153+
154+
Combine the TCP bridge with VM snapshot restores to crash-test fragile IPC parsers.
155+
156+
### Operational considerations
157+
- Named pipes are low-latency; long pauses while editing buffers can deadlock brittle services.
158+
- Overlapped/completion-port I/O coverage is partial, so expect edge cases.
159+
- Injection is noisy and unsigned, so treat it as a lab/exploit-dev helper rather than a stealth implant.
160+
125161
## Troubleshooting and gotchas
126162
- You must read at least one message from the pipe before calling ImpersonateNamedPipeClient; otherwise you’ll get ERROR_CANNOT_IMPERSONATE (1368).
127163
- If the client connects with SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, the server cannot fully impersonate; check the token’s impersonation level via GetTokenInformation(TokenImpersonationLevel).
128164
- CreateProcessWithTokenW requires SeImpersonatePrivilege on the caller. If that fails with ERROR_PRIVILEGE_NOT_HELD (1314), use CreateProcessAsUser after you already impersonated SYSTEM.
129165
- Ensure your pipe’s security descriptor allows the target service to connect if you harden it; by default, pipes under \\.\pipe are accessible according to the server’s DACL.
130166

131-
## Detection and hardening
132-
- Monitor named pipe creation and connections. Sysmon Event IDs 17 (Pipe Created) and 18 (Pipe Connected) are useful to baseline legitimate pipe names and catch unusual, random-looking pipes preceding token-manipulation events.
133-
- Look for sequences: process creates a pipe, a SYSTEM service connects, then the creating process spawns a child as SYSTEM.
134-
- Reduce exposure by removing SeImpersonatePrivilege from nonessential service accounts and avoiding unnecessary service logons with high privileges.
135-
- Defensive development: when connecting to untrusted named pipes, specify SECURITY_SQOS_PRESENT with SECURITY_IDENTIFICATION to prevent servers from fully impersonating the client unless necessary.
136-
137167
## References
138-
- Windows: ImpersonateNamedPipeClient documentation (impersonation requirements and behavior). https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-impersonatenamedpipeclient
139-
- ired.team: Windows named pipes privilege escalation (walkthrough and code examples). https://ired.team/offensive-security/privilege-escalation/windows-namedpipes-privilege-escalation
168+
- [Windows: ImpersonateNamedPipeClient documentation](https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-impersonatenamedpipeclient)
169+
- [ired.team: Windows named pipes privilege escalation](https://ired.team/offensive-security/privilege-escalation/windows-namedpipes-privilege-escalation)
170+
- [pipetap – a Windows named pipe proxy tool](https://sensepost.com/blog/2025/pipetap-a-windows-named-pipe-proxy-tool/)
140171

141172
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)