Metasploit Tutorial on Kali Linux [Step-by-Step]

Deepak Prasad

Ethical hacking, Kali Linux

In this post, we are going to dive into the most popular penetration testing framework - Metasploit. We will look at 'What is the Metasploit framework,' 'the Installation process,' and how to use it in ethical hacking. Let's get started.


What is the Metasploit Framework?

The Metasploit framework is the leading exploitation framework used by Penetration testers, Ethical hackers, and even hackers to probe and exploit vulnerabilities on systems, networks, and servers. It is an open-source utility developed by Rapid7 software company , which has also designed other security tools, including the Nexpose vulnerability scanner. For anybody aspiring to get in the security field, you need to master the Metasploit framework to prosper.

Metasploit Tutorial on Kali Linux [Step-by-Step]


Metasploit Framework Interfaces

Metasploit is available in four (4) interfaces:

  • msfcli: Commonly written as 'MSFcli.' It is a single command-line interface for the Metasploit framework.
  • msfconsole: It is the most popular Metasploit interface for the Metasploit framework. It gives you an interactive shell where you can execute commands and run exploits.
  • msfweb: It is the web interface of Metasploit that allows you to set up projects and carry out penetration testing tasks.
  • Armitage: It is the Graphical User Interface (GUI) front-end for Metasploit developed in Java.

The msfconsole is the most popular interface for Metasploit, and it's also the interface we will be using in this post.


Why Learn and Use Metasploit?

Before tools like Metasploit came along, penetration testers had to carry out all tasks manually using various tools, some not even supported by the target system. They had to code their tools and scripts from scratch before deploying them manually on the target system or network. A term like 'Remote testing' used today was uncommon. However, that has changed with Metasploit.

This framework comes with more than 1677 exploits (regularly updated) for over 25 platforms. That includes Android, Windows, Linux, PHP, Java, Cisco, etc. It also comes with more than 500 payloads which include:

  • Dynamic payloads that enable users to generate payloads and scripts that are undetectable by antiviruses.
  • Command shell payloads that enable users to gain access and execute commands/ scripts on the target machine.
  • Meterpreter payloads provide users with an interactive command-line shell that you can use to explore and exploit the target machine.


Minimum System Requirements for Metasploit

Metasploit is available for various platforms (thanks to open-source installers available on the Rapid7 website). The framework supports Debian-based systems, RHEL-based systems, Windows Server 2008 or 2012 R2, Windows 7 SP1+, 8.1, or 10, and more. You can also run Metasploit on Android using applications like Termux.

Even though you can easily install Metasploit on your Linux or Windows system, it's highly recommended you use Metasploit on penetration testing distributions like Kali Linux or Parrot OS. These distributions ship with Metasploit installed and many other hacking tools required for ethical hacking and security auditing.

The minimum hardware requirements for running Metasploit are:

  • 512 MB RAM if you are using a system without GUI. The higher, the better.
  • 2 GB RAM if you are using a Graphical system. The higher, the better.
  • 1 GB Disk space


Getting Started With the Metasploit Framework

In this post, we will run Metasploit on Kali Linux. Kali Linux is the leading penetration testing distribution and ships with more than 600 security tools. You can checkout our step-by-step guide on installing Kali Linux on VirtualBox.


1. Start the PostgreSQL Database Service

To get started Metasploit framework, you need to start the PostgreSQL database. That enables Metasploit to carry out faster searches and store information when scanning or performing an exploit. Launch the Terminal and execute the command below.

sudo service postgresql start
sudo msfdb init

Metasploit Tutorial on Kali Linux [Step-by-Step]


2. Launch Metasploit

As discussed above, there are four interfaces available for use with the Metasploit framework. We will use the msfconsole in this post. Now, there are two ways you can use to launch msfconsole on Kali Linux.

  • Command-line method
  • Graphical Method

With the command-line method, execute the command below on your Terminal.


Metasploit Tutorial on Kali Linux [Step-by-Step]


Alternatively, you can start msfconsole from the Kali GUI by clicking on the Menu button -> Exploitation tools -> Metasploit framework.

Metasploit Tutorial on Kali Linux [Step-by-Step]

That will open the Terminal, and you will be prompted to enter the user password before launching the msfconsole command-line shell.


Metasploit Tutorial

After successfully launching msfconsole, you will see a Terminal prompt with the format msf[metasploit_version]. For example, in our case, we are getting a msf5 > prompt, as shown below. That means we are running Metasploit version 5. If you are using a newer version, say Metasploit version 6, you will see a msf6 > prompt.

Metasploit Tutorial on Kali Linux [Step-by-Step]


1. help command

The first and the most basic command you should execute is the help command. If you are lost and don't know which command to use, you can always refer to this documentation. It shows you all the commands you can run and a description of what they do.


Metasploit Tutorial on Kali Linux [Step-by-Step]

Metasploit exploits an existing vulnerability on a system. Therefore, if there is no vulnerability or it's already patched, Metasploit won't penetrate the system.


2. search command

The other very useful command is search. It allows you to search for a particular module among the hundreds of modules available in Metasploit. This command can take three parameters:

  • type
  • platform
  • name

For example, I will use the syntax below to search for a common Unix exploit for VSFTPD version 2.3.4.

search type:exploit platform:unix vsftpd

Metasploit Tutorial on Kali Linux [Step-by-Step]


3. use command

The other most helpful command is the use command. It allows you to load a module that you want to use to attack or penetrate a system. These modules include exploits, payloads, auxiliaries, encoders, evasions, nops, and posts.

As a demonstration, we will use a module to exploit an existing vulnerability on VSFTPD version 2.3.4. On the msfconsole, run the use command below to load our vsftpd_234_backdoor exploit.

use exploit/unix/ftp/vsftpd_234_backdoor

Metasploit Tutorial on Kali Linux [Step-by-Step]

If the module were successfully loaded, the prompt would change, as shown in the image above. It appends the path of the module in a different color (mostly red). If you see a similar message like "No payload configured, defaulting to...," don't worry. It means Metasploit could not automatically load the payload, and you will need to do it manually. In simple terms, a Payload is the code/ script executed through the said exploit. 


4. show options command

After successfully loading a module, the following command you need to execute is the show options command. 

show options

Metasploit Tutorial on Kali Linux [Step-by-Step]

This command shows you the different options you can change with the module. For example, in the image above, we see this module requires us to set the RHOST and RPORT.

  • RHOST: That is the IP address of the remote system that you want to exploit.
  • RPORT: That is the target port you wish to use on the target system.


5. set command

The other helpful command is set. This one allows you to set the various value displayed using the show options command. For example, if you wish to assign values to RHOST and RPORT we would use the syntax below.

set RHOST [target_IP]
set RPORT [traget_Port]
set RPORT 21

Metasploit Tutorial on Kali Linux [Step-by-Step]

If you rerun the show options command, you will notice there is a difference. The options RHOSTS and RPORT now have values assigned to them.

Metasploit Tutorial on Kali Linux [Step-by-Step]

Some modules will have several options to set (more than six). In case you find some terms hard to understand their meaning, you can always use the help command.


6. show payloads command

The other command you need to run after this step is show payloads. This command lists all the payloads compatible with this module. 

show payloads

Metasploit Tutorial on Kali Linux [Step-by-Step]

Running this command on our module only gave us one compatible payload. However, some modules will have more than ten compatible modules to choose from.


7. set payload command

To load a particular payload, use the set command as shown below.

set payload cmd/unix/interact

Metasploit Tutorial on Kali Linux [Step-by-Step]


8. run command

After successfully loading the payload, you are now ready to run this exploit against an existing vulnerability on the target system. Execute the command below.


Metasploit Tutorial on Kali Linux [Step-by-Step]

From the image above, you can see we successfully ran the exploit against a target system and obtained a command shell session. That means we are now inside the system, and we can now run any Linux commands from our msfconsole, and they will execute on our target system.



That's it! I believe you now have a good understanding of the Metasploit framework and how to get started. If you are setting foot in the security field, please check out our post on Setting Up a Hacking Lab with Metasploitable. That is an intentionally vulnerable machine that helps you learn Metasploit at an in-depth level, as there are so many vulnerabilities in this system that you can exploit.


Views: 366

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can reach out to him on his LinkedIn profile or join on Facebook page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

Leave a Comment

GoLinuxCloud Logo

We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Programming Languages