How to Install Metasploit Framework on Linux via Terminal

Brief: Today you will learn how to install Metasploit framework on Linux from the command-line.

The Rapid7-powered Metasploit Framework is the world’s leading penetration testing framework. The Project is a collaboration between the open-source community and Rapid7 to provide a tool for developing and executing exploit code against a target machine.

It is mostly known for:

  • Write, test, and execute exploit code
  • Intrusion Detection System (IDS) signature development
  • Vulnerability Assessment and Pentesting
  • Test security vulnerabilities, enumerate networks, execute attacks, and evade detection.

H. D. Moore created Metasploit in 2003 as a portable network tool using Perl. By 2007, the Metasploit Framework had been completely rewritten in Ruby. On October 21, 2009, the Metasploit Project announced that it had been acquired by Rapid7, a security company that provides unified vulnerability management solutions.

By default, Kali Linux and Parrot OS provide the Metasploit Framework within their operating systems. Even other distributions such as Debian, Ubuntu, Fedora, AlmaLinux, Manjaro, etc., can easily install it on their systems.


How to Install Metasploit Framework on Linux via Terminal

To install Metasploit Framework on your system, you need to have a curl package (a command-line tool that enables data transfer over various network protocols) installed. That can be done using any of the below commands depending upon your Linux distribution.

$ sudo apt install curl          #Installing curl for Debian, Ubuntu, Linux Mint, Pop!_os
$ sudo dnf install curl          #Installing curl for Arch, Manjaro, EndeavorOS
$ sudo pacman -Sy curl           #Installing curl for RHEL, Fedora, Alma Linux

Now, you can easily install the Metasploit Framework package and add the build repository to your system via terminal using the following command.

$ curl > msfinstall && chmod 755 msfinstall && ./msfinstall

Below is the output of the above command.

How to Install Metasploit Framework on Linux from command-line
Installing Metasploit Framework on Linux from command-line

After the installation is successfully completed, open your terminal and execute the following command to start the msfconsole.

$ msfconsole

For a fresh installation, it will ask you to set up a new database. Type “y” for “yes” to run the initial configuration script to create the initial database.

Setup Metasploit new database
Setup Metasploit new database

Next, it will ask you to set up web services for APIs that may rarely be of any use to you. Type “n” or “no“.

Setup Metasploit new webservice
Setup Metasploit new webservice

If all goes well, you will be presented with the Metasploit console as shown below.

Metasploit console
Metasploit console

Run the following command in the Metasploit console to make sure the database is up and running.

$ db_status

If the Metasploit Framework successfully connects to the database, the following status will display:

Test Metasploit database is up and running
Test Metasploit database is up and running

In case the database failed to initialize, run the following command outside the Metasploit console.

$ msfdb init

It will ask you to initialize the web service; type “n” or “no“, and then to delete your existing data and configuration, type “y” or “yes“, as shown below.

Setting up Metasploit database
Setting up Metasploit database

Now that the PostgreSQL service is up and running and the database is initialized, you can launch msfconsole and verify database connectivity with the db_status command as shown below.

Retest Metasploit database is up and running
Retest Metasploit database is up and running

After the database starts, you can use any of the following commands to manage the database:

msfdb reinitTo delete and reinitialize the database
msfdb deleteTo delete the database
msfdb startTo start the database
msfdb stopTo stop the database
msfdb statusShows the database status

Common Commands Used with msfconsole.

helpTo list all the options available in msfconsole
help handler or help workspaceYou can prepend help to any command to see a list of available options
search name:mysqlTo search modules using a descriptive name
use [MODULE]Will change your context to a specific module, exposing type-specific commands
show exploitsTo get a listing of all exploits contained in the framework
show payloadsDisplay the payloads that are compatible with that particular exploit
info [EXPLOIT NAME]Shows detailed information about a particular module including all options, targets, and other information
use [EXPLOIT]Will change your context to a specific module, exposing type-specific commands
show optionsDisplay which settings are available and/or required for that specific module
set [PAYLOAD]Allows you to set the specific payload for your exploit
show targetTo see which targets are supported
show advancedTo see more advanced options
set RHOST [TARGET IP]Allows you to configure Framework options and parameters for the current module you are working with
set LHOST [TARGET IP]Allows you to set up the localhost IP address for the reverse communications needed to open the reverse command shell
connect [IP ADDRESS]Connect to a remote host from within msfconsole the same as you would with Netcat or Telnet
editEdit the specific exploit that you’re working on
backTo move out of the current context
jobsList all the running modules in the background
kill [PID]Kill the specific jobs with the PID specified
exitExit from msfconsole

Uninstalling Metasploit from Linux

This article is incomplete without showing you Metasploit removal steps. It is recommended to take a backup of your project data that you may want to keep, like reports and host data, before uninstalling Metasploit.

Once you decide to remove it, open your terminal using a Ctrl+Alt+t keyboard shortcut and follow the below steps to remove Metasploit from your Linux systems.

$ sudo apt purge metasploit-framework

Press Y and the above command will remove the Metasploit framework from your system, as shown below.

Removing Metasploit Framework from the command line using the APT package manager
Removing Metasploit Framework from the command line using the APT package manager

Lastly, execute the below command to remove the dependencies installed along with the Metasploit.

$ sudo apt autoremove

Below is the output of the above command.

Removing Metasploit Dependencies
Removing Metasploit Dependencies

Wrap Up

The Metasploit Framework is a popular and well-known tool for penetration testers. If you are interested in learning more, then visit the Offensive Security website to get free documentation on different usages of the msfconsole command.

That’s all for now. For any queries or questions, feel free to ask in the comment section.

Leave a Reply

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.