WEB PENETRATION TESTING

How to use Metasploit for Hacking in Kali Linux

PENETRATION TESTING GUIDE

Hi, Welcome to TechCybero. Today You’ll learn “How to use Metasploit for Hacking in Kali Linux”. Metasploit is an open source framework that helps developers to create working exploits as new vulnerabilities are discovered. Metasploit is known as the best vulnerability assessment and exploit development tool. Penetration Testers use Metasploit to check vulnerabilities in the targeted system and run a suitable exploit on the targeted system. 

Prerequisite’s to Use Metasploit 

Metasploit can be used on different operating system like Windows, MacOS and Linux. But I’ll recommend you to use Kali Linux for Web Penetration Testing. Following are the prerequisite’s for using Metasploit: 

  • Setup Your Virtual Lab 
  • Kali Linux Basics 
  • Basic Python Programming and Bash Scripting 

Setup Your Virtual Lab 

If you don’t want to install Kali Linux as Dual Boot in Windows then you can Install VMware or Virtual Box in Windows. VMware helps you to run Kali Linux inside Windows. VMware or Virtual Box are easy to use. You can setup your virtual penetration testing lab by following this tutorial: 

Metasploit Hacking TechCybero

Kali Linux Basics 

You need a basic Kali Linux usage knowledge to use Metasploit for Hacking. If you don’t have any experience of using Kali Linux, Don’t Worry. You can get the free training from Offensive Security from the following link: 

https://kali.training/lessons/introduction/ 

Basic Python Programming and Bash Scripting 

You must have a basic programming language knowledge in Python. Hackers mostly used Python for hacking purposes. Bash Scripting is used for the automation of tasks and you can learn Python and Bash Scripting in Free from Udemy: 

https://www.udemy.com/python-programming-beginners/ 

https://www.udemy.com/bash-shell-scripting-tutorial-for-beginners/ 

Start Using Metasploit 

I hope now you have the basic knowledge of prerequisites to use Metasploit in Kali Linux. Let’s move to the main topic of “how to use Metasploit for Hacking in Kali Linux “. Let’s start Metasploit to attack our first system. To start Metasploit you need to start PostgreSQL database which Metasploit use to track what you do. Open your Terminal in Kali Linux and type the following command: 

/etc/init.d/postgresql start 

Metasploit

 

You have successfully started PostgreSQL database, now you can start Metasploit service. Type the following command in Kali Linux Terminal: 

msfdb init 

Metasploit

 

There are multiple interfaces for using Metasploit but we are using msfconsole. Start the console by typing the following command in the Terminal: 

msfconsole 

Metasploit

 

After typing the command “msfconsole”, you’ll see the result as it is shown in the above image with msf5 prompt. Now type “help” and you’ll see different types of command list in your terminal. 

Finding Metasploit Modules 

Let’s look how we can use Metasploit to exploit an unpatched vulnerability in our Windows XP target. We will exploit the vulnerability in Microsoft Security Bulletin MS08-067. This is the vulnerability that we used to exploit in this tutorial. Now the question is that How do we know that this patch is missing in our Windows XP target? I’ll later guide you “How to find vulnerabilities”. For now, use this vulnerability to learn “How to use Metasploit”.  

Type the following command in the Terminal msf5 prompt to search the vulnerability: 

search ms08-067 

Metasploit

Type the following command in the Terminal msf5 prompt to get detailed information of this vulnerability: 

info exploit/windows/smb/ms08_067_netapi 

Now type the following command in the msf5 prompt to use this vulnerability for attack: 

use windows/smb/ms08_067_netapi 

After executing this command, you are in the exploit module of this vulnerability. 

Setting Module Options in Metasploit: 

To run your chosen module, Metasploit needs an information from you. Type the following command to see different options in this module: 

show options 

Metasploit

You’ll see the four options after executing the command.  

  • RHOST 
  • RPORT 
  • SMBPIPE 
  • Exploit Targets 

RHOST: 

The RHOST refers to the remote host we want to exploit. We want to set the value of RHOST to tell Metasploit to exploit this target system.  To check the IP address of target Windows machine, type ipconfig in the command prompt. If you are targeting Linux system, type ifconfig in the terminal. Type the following command in the msf5 prompt to set the value of RHOST: 

set RHOST [IP address of Your Target] 

*****Sample IP address (192.168.20.10)***** 

RPORT:  

RPORT refers to the remote port to attack the system. A port is just a network socket. When you enter www.google.com a web server somewhere on the Internet is listening on port 80. 

In this case, you’ll see that the RPORT value is set by default. The value will be 445, because we are using Windows SMB service. You can set the value of RHOST manually by typing the following command in the msf5 prompt: 

set RPORT 445 

SMBPIPE: 

Keep the default for the SMBPIPE option was BROWSER. This will work just fine for our purposes. SMB pipes allow us to talk to Windows inter-process communication over a network. 

Exploit Targets: 

The Exploit Target is set to 0 Automatic Targeting x. This is the target operating system and version. You can view the available targets on the module’s info page or just show them with the command show targets. Type the following command to show targets in this module: 

show targets 

The default option set is 0 Automatic Targeting. Keep the default option as it is. 

Payloads: 

Payloads or Shellcode are used in Metasploit after the target vulnerability exploitation. We need to select the compatible payload and tell Metasploit to run this payload after successful exploitation. There are number of payloads included in Metasploit and added to the framework regularly. Type the following command in the msf5 prompt to display payloads: 

show payloads 

If you forgot setting the payload, Metasploit will run the default payload after successful exploitation of target system vulnerability. 

Test Run: 

Let’s keep the things simple and start exploitation with default payload. Type the following command in the msf5 prompt to start exploitation: 

exploit 

After executing the above command, Metasploit will start exploiting the vulnerability of the target system. After successful exploitation, you’ll see the default payload prompt. 

Metasploit will exploit the vulnerability and run the default payload “Meterpreter”. 

Type exit in the Meterpreter prompt to exit from payload. 

Conclusion:   

Congratulations!!!.. You have successfully learned “How to Use Metasploit for Hacking in Kali Linux”. I hope now you have good knowledge of using Metasploit in Kali Linux.  

Click Here to visit our Latest Cyber Security News. 

Looking for your Comments……!!!. Comment here and share your experience with us. Don’t forget to subscribe TechCybero and share this post with your colleagues.

Tags

Syed Jawad Kazmi

Hi, I’m Syed Jawad Kazmi. Welcome to my Blog. I’m a Software Engineer and have experience in different programming languages (Java, C++, Python, Php). My Hobbies are learning new Cyber-Security concepts and techniques, Graphics Designing for Websites and Facebook pages. I have experience in working on Dark-Web projects.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close

Adblock Detected

Please consider supporting us by disabling your ad blocker