mkfifo (named pipes)
What is mkfifo?
If you're even a moderate Linux command line user, you must be aware of pipes, a fundamental command line feature that allows processes to communicate. Then there's a concept of named pipes (yeah, pipes with names, so that you can do more with pipes). The mkfifo
command lets you create such named pipes.
How to use mkfifo
Example 1
In Linux, we can create a FIFO with the command mkfifo: (FIFO = first in first out)
Here, we can see that our FIFO’s file type is indicated with the letter “p”.
This mechanism allows us to create more complex applications using our shell.
Named and anonymous pipes can be used together. Let’s create a reverse shell combining both FIFOs and pipes.
We’ll use the nc utility to create a client/server application, in which the “server” side will provide its shell, and the “client” side will be able to access it.
First, let’s install the netcat-openbsd
package. We can install it on any Ubuntu/Debian system using:
Next, let’s create a FIFO called fifo_reverse typing mkfifo fifo_reverse
.
Then, let’s log in with two different users that will each act as a “client” (let’s say, “user1”) and as a “server” (let’s say, “user2”). Let’s run this pipeline on the user2 shell:
"In this one-liner, the shell reads the content of our FIFO and passes it to an interactive Bash shell.
Next, both the stdout and the stderr of the interactive shell will be passed to the nc command, which will be listening at port 1234 of address 127.0.0.1.
And finally, when the “client” establishes a connection successfully, nc will write what is received to our FIFO, and the interactive shell will be able to execute what is received".
Now, using the user1 shell, let’s type:
Example 2
References
Last updated
Was this helpful?