The Metasploit Framework (MSF) is one of the most powerful and widely-used tools for penetration testing and ethical hacking. It is used for developing and executing exploit code against remote target machines. In this guide, we will walk through the detailed process of installing Metasploit Framework on Ubuntu, one of the most popular Linux distributions used for security testing.
msfdb init
This command sets up PostgreSQL, creates a Metasploit database, and makes sure that Metasploit is configured to use it.
msfconsole
This will load the Metasploit Framework and you should see the msf> prompt where you can start executing commands.
With this guide, you should now have a fully functional Metasploit Framework setup on your Ubuntu system. You can begin using it for penetration testing and exploring the world of ethical hacking. Make sure to keep Metasploit updated and regularly check for the latest exploits and improvements.
Table of Contents
- System Requirements
- Preparing Your Ubuntu System
- Installing Metasploit Framework
- Option 1: Installation via Package Manager
- Option 2: Installation via GitHub Source
- Post-Installation Setup
- Running Metasploit Framework
- Updating Metasploit
- Troubleshooting
- Uninstalling Metasploit
1. System Requirements
Before installing Metasploit Framework, ensure that your system meets the following requirements:- Operating System: Ubuntu 20.04 LTS or later (Ubuntu 22.04 is recommended)
- Memory: At least 4GB RAM (8GB or more is ideal for better performance)
- Disk Space: At least 10GB of free space for Metasploit and its dependencies
- Processor: x86_64 architecture (64-bit)
2. Preparing Your Ubuntu System
Ensure your system is up to date before installing Metasploit. Open a terminal and run the following commands:- Update the package list:
sudo apt update - Upgrade installed packages:
sudo apt upgrade -y - Install essential dependencies: Some packages and dependencies might not be installed by default. Run the following command to install required libraries and utilities:
sudo apt install -y curl gnupg2 build-essential libpq-dev libreadline-dev libsqlite3-dev libpcap-dev libxml2-dev libxslt1-dev liblzma-dev zlib1g-dev - Install and configure PostgreSQL: Metasploit requires PostgreSQL as its database backend. To install PostgreSQL, run:
sudo apt install -y postgresql postgresql-contrib
After installation, start and enable PostgreSQL to run automatically:
sudo systemctl enable postgresql
sudo systemctl start postgresql
3. Installing Metasploit Framework
There are two primary methods to install Metasploit on Ubuntu: using the package manager or by cloning the GitHub repository and installing from source. We will cover both options.3.1 Option 1: Installation via Package Manager
Ubuntu provides a convenient package for Metasploit that can be installed using the APT package manager. This is a quick and straightforward method, but it might not always provide the latest version.- Install Metasploit from the official repository: First, add the necessary repository for Metasploit. Execute the following commands:
curl https://raw.githubusercontent.com/rapid7/metasploit-framework/master/msfupdate | sudo bash - Install the Metasploit package: Once the repository is added, install Metasploit:
sudo apt install metasploit-framework - Verify the installation: After installation, you can verify that Metasploit was installed successfully by running:
msfconsole
This should launch the Metasploit console.
3.2 Option 2: Installation via GitHub Source
If you want the latest stable version or a custom build, you can install Metasploit from the GitHub repository.- Install Git: If you don’t have Git installed, first install it:
sudo apt install git - Clone the Metasploit repository: Clone the Metasploit framework from GitHub into a directory of your choice:
git clone https://github.com/rapid7/metasploit-framework.git - Navigate to the Metasploit directory: Change into the Metasploit directory:
cd metasploit-framework - Install dependencies: Install the required gems (dependencies) for Metasploit:
sudo apt install -y ruby-full
sudo apt install -y libpcap-dev
sudo apt install -y libsqlite3-dev
Then, install the necessary Ruby gems:
bundle install - Configure the database: Metasploit uses PostgreSQL as its backend database. If you have not set up PostgreSQL, do so now.
- Set up the PostgreSQL database user for Metasploit:
sudo msfdb init - This command will initialize the database and configure the environment to work with Metasploit.
- Set up the PostgreSQL database user for Metasploit:
- Run Metasploit: After the installation is complete, you can run Metasploit by executing:
./msfconsole
4. Post-Installation Setup
4.1 Setting Up PostgreSQL Database
After installation, you will need to initialize the database for Metasploit to work. You can do this by running:msfdb init
This command sets up PostgreSQL, creates a Metasploit database, and makes sure that Metasploit is configured to use it.
4.2 Starting and Stopping the Database
To manually start and stop PostgreSQL, use the following commands:- Start PostgreSQL:
sudo systemctl start postgresql - Stop PostgreSQL:
sudo systemctl stop postgresql
5. Running Metasploit Framework
Once Metasploit is installed, you can launch the Metasploit console by typing the following command:msfconsole
This will load the Metasploit Framework and you should see the msf> prompt where you can start executing commands.
Basic Commands
- Search for exploits:
search type:exploit name:<exploit_name> - Use an exploit:
use exploit/windows/smb/ms08_067_netapi - Show available options for the exploit:
show options - Set payload:
set payload windows/meterpreter/reverse_tcp - Launch the exploit:
exploit
6. Updating Metasploit
Metasploit is regularly updated to add new exploits and features. To ensure you are using the latest version, you should update Metasploit periodically.- To update Metasploit: If you installed Metasploit from the package manager, run:
sudo apt update && sudo apt upgrade metasploit-framework
If you installed Metasploit from GitHub, navigate to the Metasploit directory and run:
git pull
bundle install - Update the database: Update the database to ensure you have the latest version:
msfdb update
7. Troubleshooting
Common Issues and Solutions
- PostgreSQL not starting: If PostgreSQL doesn’t start, ensure it’s enabled and running. You can check its status with:
sudo systemctl status postgresql
If it’s not running, try restarting it:
sudo systemctl restart postgresql - Missing dependencies: If Metasploit gives an error about missing dependencies, try installing the required libraries:
sudo apt install -y libpq-dev libreadline-dev libsqlite3-dev - Permission issues: If you encounter permission errors, ensure that you are running commands with sudo where necessary.
8. Uninstalling Metasploit
To uninstall Metasploit, follow the instructions depending on your installation method.If installed via package manager:
sudo apt remove --purge metasploit-frameworkIf installed from GitHub:
- Delete the Metasploit directory:
rm -rf metasploit-framework - Optionally, remove PostgreSQL
sudo apt remove --purge postgresql postgresql-contrib
With this guide, you should now have a fully functional Metasploit Framework setup on your Ubuntu system. You can begin using it for penetration testing and exploring the world of ethical hacking. Make sure to keep Metasploit updated and regularly check for the latest exploits and improvements.