Named Pipe Impersonation
Last updated
Last updated
Named pipes are a form of IPC technology which allow sharing and communication of data between two processes. The term pipe simply describes the section of shared memory used by these two processes.
Named Pipes are a FILE_OBJECT which is handled by a file system named the Named Pipe File System(NPFS). Because a Named Pipe is a FILE_OBJECT, interacting and accessing the named pipe is essentially the same as accessing a regular file.
Named pipes allow for "Impersonation", which allows a thread to execute in another security context from it's own security context. This usually applies to a Client-Server architecture where a client connects to a server and for some reason, the server needs to impersonate the client to do some other action.
For a server to impersonate a client, the client must send some sort of data to named pipe before the server can impersonate the client. The server must also need the SeImpersonatePrivilege or be running as high integrity.
For this lab(ish), we are a high level overview of the steps needed to perform this:
Create a named pipe via CreateNamedPipe()
Create a service
Use that service to write data to the named pipe we created
Call ImpersonateNamedPipeClient which allows the server to impersonate any client that connects to its pipe
Create new process with that SYSTEM token
Profit
This is a POC that I have stolen from:
You can read the comments to get a brief overview on what it does, but for a more technical view, I recommend you go over to Microsoft and see some documentation:
Compile this and run it.
Before we press enter(i put a getchar), lets check for our named pipe with this powershell command
As we can see, we can find our named pipe.
Now let's continue execution.
We should now see a quick text message alerting us that our service creation was successful, and a new cmd popup.
Lets check its privs!
As we can see, we are now system.