File Transfer in Linux

Last modified: 2023-11-11

Linux

Using Wget

In machine A, Start a web server.

python -m http.server

# We can specify which directory to host by `--directory` option.
python -m http.server --directory /usr/bin

In machine B, download a file from the web server of machine A.

wget http://<ip-for-machine-A>:8000/example.txt

# Download recursively
# -r: recursive
# -np: no parent
# Don't forget "/" after the directory name
wget -r -np http://<ip-for-machine-A>/somedir/

Using Netcat

Transfer a File

In machine A, start a listener for receiving a file.

# -l: Listen mode
# -p: Port
nc -lp 4444 > example.txt

In machine B, send a file to machine A.

nc <machineA-ip> 4444 < example.txt

Transfer a Directory

In machine A, start a listener for receiving a directory.

nc -lvnp 4444 > out.tar

In machine B, compress a directory using tar and transfer it.

tar -cf - example/ | nc <machineA-ip> 4444

In machine A, decompress the tar file and get the directory.

tar -xf out.tar

Using Base64

In machine A, encode a file with base64 and copy the encoded Base64 string.

# -w 0: disabe line wrapping
base64 exploit.sh -w 0

In machine B, paste the encoded Base64 string.

echo '123...def==' | base64 -d > exploit.sh