Install and Use Metasploit on Ubuntu 22.04: Powerful Framework

Posted on

Install and Use Metasploit on Ubuntu 22.04: Powerful Framework

Install and Use Metasploit on Ubuntu 22.04: Powerful Framework

In this guide, we aim to demonstrate how to Install and Use Metasploit on Ubuntu 22.04. The Metasploit framework stands as a highly potent tool, utilized by both cybercriminals and ethical hackers to meticulously probe for systemic vulnerabilities within networks and servers. Its open-source nature facilitates effortless customization and compatibility with a wide range of operating systems. Follow the steps below to install and use Metasploit commands on Ubuntu 22.04.

To leverage Metasploit commands, you must log in to your server as a root user and adhere to the subsequent steps. This guide outlines downloading Metasploit from the source to ensure you install the latest version. Let’s learn how to Install and Use Metasploit on Ubuntu 22.04.

Metasploit Installation on Ubuntu 22.04

First, you need to update your local package index with the following command:

sudo apt update

Then, use the following command to install the required packages and dependencies:

apt install gpgv2 autoconf bison build-essential postgresql libaprutil1 libgmp3-dev libpcap-dev openssl libpq-dev libreadline6-dev libsqlite3-dev libssl-dev locate libsvn1 libtool libxml2 libxml2-dev libxslt-dev wget libyaml-dev ncurses-dev  postgresql-contrib xsel zlib1g zlib1g-dev -y

Now use the following curl command to download Metasploit source code on Ubuntu 22.04:

curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall

Confirm your download Metasploit file by using the command below:

ls -la msfinstall
**Output**
-rw-r--r-- 1 root root 6034 May  7 08:42 **msfinstall**

Next, set the correct permissions for your downloaded file:

chmod 755 msfinstall

Finally, you can use the command below to start your Metasploit installation process on Ubuntu 22.04:

./msfinstall

This will take some time to complete, depending on your system resources.

Access Metasploit Console

At this point, you can simply run the command below to start and access your Metasploit console:

msfconsole
Metasploit commands console

To exit from the console, simply type exit.

Use Metasploit – Perform a Scan

Now that you have installed Metasploit on your Ubuntu 22.04, it is time to perform a scan with Metasploit commands. A Metasploit scan has two types: network scans and host scans.

A network scan identifies the available hosts on a network. This type of scan is useful when performing a penetration test on a network to identify the systems available for further attacks.

On the other hand, a host scan identifies the services running on a host. This type of scan is useful when you want to identify the vulnerabilities in a system.

Run a vulnerability scan with Metasploit

At this point, follow the below steps to run a vulnerability scan with Metasploit on Ubuntu 22.04.

First, you need to start the PostgreSQL service. Metasploit saves all of the data it collects in a database. By default, Metasploit uses the PostgreSQL database.

systemctl start postgresql

Then, you need to initialize a new database for Metasploit by using the following command:

msfdb init

Note: You must run this command as a non-root user.

**Output**
[?] Would you like to init the webservice? (Not Required) [no]:
Clearing http web data service credentials in msfconsole
Running the 'init' command for the database:
Creating database at /home/orca/.msf4/db
Creating db socket file at /tmp
Starting database at /home/orca/.msf4/db...**success**
Creating database users
Writing client authentication configuration file /home/orca/.msf4/db/pg_hba.conf
Stopping database at /home/orca/.msf4/db
Starting database at /home/orca/.msf4/db...**success**
Creating initial database schema
**Database initialization successful**

Now access your Metasploit console again with your non-root user:

msfconsole

Then, from your Metasploit console check your database connection with the command below:

*msf6 >* db_status
**Output**
[*] Connected to msf. Connection type: postgresql.
Load msfcrawler module

At this point, you need to load the msfcrawler module by using the command below. The msfcrawler module is for crawling websites to find vulnerabilities in web applications.

*msf6 >* use auxiliary/scanner/http/crawler
**Output**
msf6 auxiliary(**scanner/http/crawler**) >
Set RHOST and RPORT parameters

The RHOST parameter represents the target host, and the RPORT parameter represents the port number. In this case, you will scan the local host on port 9000.

msf6 auxiliary(**scanner/http/crawler**) > set RHOST localhost
msf6 auxiliary(**scanner/http/crawler**) > set RPORT 9000
Start Crawler

At this point, run the below command to start the crawler. The crawler will start scanning the target host and port. This process can take several minutes, depending on the website’s size.

msf6 auxiliary(**scanner/http/crawler**) > run
**Output**
[*] Running module against 127.0.0.1

[*] Crawling http://localhost:9000/...
[-] Error accessing page The connection was refused by the remote host (localhost:9000).
[-] [00001/00500]    ERR - localhost - http://localhost:9000/
[*] Crawl of http://localhost:9000/ complete
[*] Auxiliary module execution completed
Load WMAP module

At this point, you need to load the WMAP module. This module scans web applications for vulnerabilities. To do this, run the command below:

msf6 auxiliary(**scanner/http/crawler**) > load wmap
**Outut**

.-.-.-..-.-.-..---..---.
| | | || | | || | || |-'
`-----'`-'-'-'`-^-'`-'
[WMAP 1.5.1] ===  et [  ] metasploit.com 2012
[*] Successfully loaded plugin: wmap

Now run the wmap_sites -a localhost:9000 command to add the target host and port to the scan list:

msf6 auxiliary(**scanner/http/crawler**) > wmap_sites -a localhost:9000
**Output**
[*] Site created.

List all the available target hosts and ports by using the following command:

msf6 auxiliary(**scanner/http/crawler**) > wmap_sites -l
**Output**
[*] Available sites
===============

     Id  Host       Vhost      Port  Proto  # Pages  # Forms
     --  ----       -----      ----  -----  -------  -------
     0   127.0.0.1  localhost  9000  http   1        0

Finally, you can select a target host and start your scan with Metasploit commands on Ubuntu 22.04:

msf6 auxiliary(**scanner/http/crawler**) > wmap_targets -t 127.0.0.1:9000 
msf6 auxiliary(**scanner/http/crawler**) > wmap_run -e

Wait for the scan to finish. When the scan is complete, view the results by running the below command:

vulns

For more information, you can visit the Metasploit Docs page.

Conclusion

At this point, you have learned to Install and Use Metasploit on Ubuntu 22.04. Metasploit is a great tool that cybercriminals and ethical hackers use to probe systematic vulnerabilities on networks and servers.

Hope you enjoy it.

Alternative Solutions

While the article outlines installing Metasploit from source, other methods exist for setting up this powerful framework on Ubuntu 22.04. Here are two alternative approaches:

1. Using the Rapid7 Package (Recommended for Stability)

Rapid7, the company behind Metasploit, provides pre-built packages that offer a more streamlined installation experience compared to building from source. This method ensures stability and often includes pre-configured settings.

Explanation:

The Rapid7 package bundles all necessary components and dependencies, simplifying the installation process. It also benefits from Rapid7’s quality assurance and regular updates, making it a more robust choice for production environments or users who prioritize stability.

Installation Steps:

Unfortunately, providing a precise code example for downloading and installing the Rapid7 package directly is difficult without knowing the exact package URL and version available at a specific point in time. However, the general process involves these steps:

  1. Visit the Rapid7 Downloads Page: Navigate to the official Rapid7 downloads page for Metasploit. This is crucial to ensure you obtain the package from a trusted source.

  2. Locate the Linux Installer: Look for the appropriate installer package for Linux (usually a .run file).

  3. Download the Installer: Download the package to your Ubuntu 22.04 system.

  4. Make the Installer Executable: Use the chmod command to grant execute permissions to the downloaded file. For example:

    chmod +x <installer_filename>.run
  5. Run the Installer: Execute the installer with sudo:

    sudo ./<installer_filename>.run

    The installer will guide you through the installation process, including accepting license agreements and choosing installation directories.

  6. Start Metasploit: After the installation completes, you should be able to launch Metasploit using the msfconsole command.

Benefits:

  • Simplified installation process.
  • Greater stability and reliability.
  • Automatic updates managed by Rapid7.

Drawbacks:

  • Less flexibility in customizing the installation.
  • Potentially a slightly older version compared to building from source (though generally more stable).

2. Using Docker (For Isolation and Reproducibility)

Docker provides a containerization solution, allowing you to run Metasploit in an isolated environment. This method is ideal for users who want to avoid conflicts with existing system configurations or need a reproducible setup.

Explanation:

Docker packages Metasploit and all its dependencies into a self-contained image. This image can be easily deployed on any system with Docker installed, guaranteeing consistent behavior across different environments.

Installation Steps:

  1. Install Docker: If you don’t have Docker installed, you’ll need to install it first. Follow the official Docker documentation for Ubuntu: https://docs.docker.com/engine/install/ubuntu/

  2. Pull the Metasploit Image: Use the docker pull command to download a pre-built Metasploit image from Docker Hub. A popular and frequently updated image is rapid7/metasploit-framework.

    docker pull rapid7/metasploit-framework
  3. Run the Metasploit Container: Use the docker run command to start a Metasploit container. You’ll typically want to map a local directory to the container to persist database data.

    docker run -it -v /path/to/your/data:/data rapid7/metasploit-framework msfconsole
    • -it: Runs the container in interactive mode with a TTY.
    • -v /path/to/your/data:/data: Mounts the local directory /path/to/your/data to the /data directory inside the container. This ensures that your Metasploit database and configurations are preserved even when the container is stopped or removed. Replace /path/to/your/data with the actual path to a directory on your host machine.
    • rapid7/metasploit-framework: Specifies the Docker image to use.
    • msfconsole: Specifies the command to run inside the container (in this case, starting the Metasploit console).

Benefits:

  • Isolated environment, preventing conflicts with other software.
  • Reproducible setup across different systems.
  • Easy to deploy and manage.
  • Clean uninstall – simply remove the container and image.

Drawbacks:

  • Requires Docker knowledge.
  • Slight performance overhead due to containerization.

By exploring these alternative installation methods, users can choose the approach that best suits their needs and technical expertise, ensuring a smooth and efficient Metasploit setup on Ubuntu 22.04. It’s important to remember that when choosing how to Install and Use Metasploit on Ubuntu 22.04, security best practices should always be followed.

Leave a Reply

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