Named pipe impersonation

Understanding Named Pipes

What Are Named Pipes?

Think of named pipes like a direct phone line between two applications. Just as you might have a dedicated hotline between departments in a company, named pipes provide a direct communication channel between processes on the same computer or across a network.

Named pipes are a form of Inter-Process Communication (IPC) that allows processes to exchange data. In Windows, they're implemented as special files in the \\.\pipe\ namespace and can be accessed by name, making them "named" pipes.

How Named Pipes Work

Basic Communication Flow:

  1. Server process creates a named pipe with a specific name (like \\.\pipe\mypipe)

  2. Server listens for connections on this pipe

  3. Client process connects to the pipe by name

  4. Data flows bidirectionally between server and client

  5. Authentication occurs using the security context of connecting processes

Named Pipe Structure:

\\ComputerName\pipe\PipeName

Local pipe example:

\\.\pipe\spoolss          (Print Spooler service)
\\.\pipe\samr             (Security Account Manager)
\\.\pipe\lsarpc           (Local Security Authority)

Security Context and Impersonation

This is where named pipes become interesting for privilege escalation:

Normal Scenario:

  • Client connects to server's named pipe

  • Server processes client requests

  • Server maintains its own security context

Impersonation Scenario:

  • Client connects to server's named pipe

  • Server can "impersonate" the client's security context

  • Server temporarily gains client's privileges and permissions

  • Server can perform actions as if it were the client

The Security Risk: If an attacker can create a malicious named pipe server and trick a high-privileged process into connecting as a client, the attacker can impersonate that high-privileged security context.

Named Pipe Security Model

Authentication Levels

Anonymous: No authentication required Identification: Server can get client identity but not impersonate Impersonation: Server can impersonate client on local machine Delegation: Server can impersonate client across network

Access Control

Named pipes support standard Windows security descriptors:

  • Owner - Who owns the pipe

  • Primary Group - Default group for the pipe

  • DACL - Discretionary Access Control List (who can access)

  • SACL - System Access Control List (auditing)

Real-World Named Pipe Examples

Print Spooler Service (\\.\pipe\spoolss):

  • Used for printer management

  • Runs as SYSTEM

  • Accepts connections from users to manage print jobs

  • Can be abused for SYSTEM impersonation

Windows Management Instrumentation (\\.\pipe\wmiApRpl):

  • Used for WMI operations

  • Often runs with elevated privileges

  • Can be targeted for privilege escalation


Named Pipe Enumeration and Discovery

Discovering Named Pipes

Using PipeList (Sysinternals)

Basic pipe enumeration:

Sample PipeList output interpretation:

PowerShell Named Pipe Discovery

Enumerate named pipes with PowerShell:

Advanced Pipe Enumeration

Using .NET classes for detailed pipe information:

Identifying Vulnerable Pipes

Criteria for Exploitable Pipes

High-Value Targets:

  • Pipes created by SYSTEM processes

  • Pipes with permissive security descriptors

  • Pipes that accept unauthenticated connections

  • Pipes used by services with SeImpersonatePrivilege

Manual Pipe Testing

Test pipe accessibility:

Automated Pipe Discovery

PowerShell comprehensive pipe scanner:


Impersonation Attack Techniques

Creating Malicious Named Pipe Servers

The core of named pipe impersonation attacks involves creating a fake named pipe server that mimics a legitimate service, then tricking high-privileged processes into connecting to it.

Basic Named Pipe Server

Simple PowerShell pipe server:

Advanced Pipe Server with Persistence

Enhanced pipe server with multiple connections:

Triggering High-Privilege Connections

Creating the malicious pipe server is only half the attack. The other half is convincing a high-privileged process to connect to your pipe.

Print Spooler Abuse

Abusing Print Spooler for pipe impersonation:

Service Control Manager Abuse

Triggering SCM connections:

Metasploit Named Pipe Modules

Using Metasploit for Named Pipe Attacks

Metasploit named pipe exploits:

Manual Meterpreter named pipe attack:

Advanced Named Pipe Techniques

Pipe Squatting

Monitoring for pipe creation opportunities:

Race Condition Attacks

Exploiting service restart race conditions:

Last updated

Was this helpful?