How to Use Metasploit for Exploitation and Payload Delivery in Kali Linux

Install Metasploit on Kali Linux

Kali Linux is a powerful open-source platform for penetration testing and security auditing. It comes with a wide range of tools, including Metasploit, which is a powerful exploitation and payload delivery framework. In this tutorial, we will show you how to install Metasploit on Kali Linux and use it for exploitation and payload delivery.

To install Metasploit on Kali Linux, open a terminal window and type the following command:

sudo apt-get install metasploit-framework

Once the installation is complete, you can start using Metasploit by typing the following command:

msfconsole

This will launch the Metasploit console, which you can use to search for exploits, select an exploit, configure the exploit, launch the exploit, verify the exploit, and clean up after the exploit.

Now that you have installed Metasploit on Kali Linux, you are ready to start using it for exploitation and payload delivery. For more information on how to use Metasploit, please refer to the Metasploit Unleashed guide.

Search for Exploits

In this step, we will search for exploits that can be used to exploit the target system. To do this, we will use the Metasploit Framework, which is included in Kali Linux. To search for exploits, open a terminal window and type the following command: searchsploit <target>. Replace <target> with the name of the target system. This will search the Exploit Database for exploits that can be used to exploit the target system. The results will be displayed in the terminal window.

Once you have found an exploit that you want to use, you can use the show command to view the details of the exploit. This will display the name of the exploit, the type of exploit, the platform it is designed for, and the version of the target system that it is designed to exploit. You can also use the search command to search for specific exploits. For example, if you want to search for exploits that target a specific version of a system, you can use the search <version> command.

Once you have found an exploit that you want to use, you can use the use command to select the exploit. This will load the exploit into the Metasploit Framework and allow you to configure it for use.

Select an Exploit

Once you have installed Metasploit on Kali Linux, you can begin searching for exploits. To do this, you can use the search command in the Metasploit console. This command will search the Metasploit database for exploits that match the criteria you specify. For example, if you wanted to search for exploits related to Microsoft Windows, you could use the following command:

search type:exploit platform:windows
This will return a list of exploits that are related to Microsoft Windows. You can then select the exploit you want to use by typing the exploit name in the Metasploit console. For example, if you wanted to use the EternalBlue exploit, you would type the following command:
use exploit/windows/smb/ms17_010_eternalblue
Once you have selected the exploit, you can configure it to your needs.

Configure the Exploit

Now that you have selected an exploit, it's time to configure it. This step is crucial for successful exploitation. Depending on the exploit, you may need to set certain parameters such as the target IP address, port, and payload. To configure the exploit, you can use the set command in Metasploit. For example, if you are using the MS17-010 EternalBlue exploit, you can use the following command to set the target IP address:

set RHOST 192.168.1.1

Once you have set the parameters, you can use the show options command to verify that the exploit is configured correctly. If everything looks good, you can move on to the next step.

Launch the Exploit

Now that you have configured the exploit, you can launch it. To do this, type the following command in the terminal: msfconsole. This will open the Metasploit console. From here, you can type exploit to launch the exploit. If the exploit is successful, you will see a message indicating that the target has been compromised. You can then use the sessions command to view the active sessions on the target machine. You can also use the sessions -i command to interact with the target machine. Once you have finished exploiting the target, you can use the sessions -k command to terminate the session.

It is important to note that launching an exploit can be dangerous and should only be done with caution. Before launching an exploit, make sure you understand the implications of doing so and that you have the necessary permissions to do so. Additionally, it is important to clean up after launching an exploit. This includes removing any files or programs that were installed on the target machine and ensuring that the exploit is no longer active.

Verify the Exploit

Once you have launched the exploit, you need to verify that it was successful. To do this, you can use the netstat command to check the status of the connection. If the connection is established, then the exploit was successful. You can also use the ps command to check the running processes on the target machine. If the payload is running, then the exploit was successful. If the exploit was successful, you can then use the payload to gain access to the target machine.

To verify the exploit, open a terminal window in Kali Linux and type the following command:

netstat -an
This will show you the status of the connection. If the connection is established, then the exploit was successful. You can also use the ps command to check the running processes on the target machine. To do this, type the following command:
ps -ef
This will show you the running processes on the target machine. If the payload is running, then the exploit was successful.

Verifying the exploit is an important step in the exploitation process. It ensures that the exploit was successful and that the payload was delivered to the target machine. Once the exploit is verified, you can then use the payload to gain access to the target machine.

Clean Up

Once you have verified that the exploit was successful, it is important to clean up the environment. This includes removing any files that were created during the exploitation process, as well as any other files that may have been left behind. To do this, you can use the rm command in Kali Linux. For example, if you created a file called exploit.sh, you can remove it with the command rm exploit.sh. Additionally, you can use the find command to search for any other files that may have been created during the exploitation process. For example, you can use the command find / -name "*exploit*" to search for any files that contain the word "exploit" in their name. Once you have identified any files that need to be removed, you can use the rm command to delete them. It is also important to make sure that any services that were running during the exploitation process are stopped. This can be done using the service command in Kali Linux. For example, if you were running a web server during the exploitation process, you can stop it with the command service apache2 stop. Finally, it is important to make sure that any changes that were made to the system during the exploitation process are reverted. This can be done using the revert command in Kali Linux. For example, if you changed the permissions of a file during the exploitation process, you can revert them with the command revert permissions exploit.sh.

Useful Links