Database Management in Metasploit
Overview
The database in Metasploit serves as a central repository for managing scan results, vulnerabilities, credentials, and other information collected during penetration tests. Leveraging the database streamlines workflows, enhances organization, and integrates seamlessly with scanning tools like Nmap.
Setting Up PostgreSQL
Metasploit uses PostgreSQL as its backend database. Below are the steps to configure and connect Metasploit with PostgreSQL.
Check PostgreSQL Status:
Verify that PostgreSQL is installed and running:
Output should display
Active: active (exited)
.
Start PostgreSQL:
If PostgreSQL is not running, start it:
Initialize the Metasploit Database:
Configure the database schema:
This creates the database user
msf
and prepares the schema.
Troubleshooting:
If initialization fails, ensure all dependencies are up to date:
Verify Database Connection:
Open Metasploit and check the database status:
Output should display:
Using the Database
The Metasploit database allows testers to store, query, and manage data efficiently. Here’s how to leverage it for penetration testing.
Key Commands:
db_status
Check the database connection status.
db_connect
Manually connect to a database.
db_disconnect
Disconnect from the database.
db_export <file>
Export the database contents to a file.
db_import <file>
Import scan results or data from a file.
hosts
View a list of discovered hosts.
services
List services running on discovered hosts.
creds
View stored credentials.
loot
Manage and view gathered files or data.
Workspaces
Workspaces help organize data by project, IP range, or domain.
List Workspaces:
Create a New Workspace:
Switch Between Workspaces:
Delete a Workspace:
Help Menu for Workspaces:
Importing Scan Results
Metasploit integrates with tools like Nmap to directly import scan results into the database.
Importing Nmap Results:
Use Nmap Directly from Metasploit:
Viewing Imported Data:
List discovered hosts:
List services running on hosts:
Exporting and Backing Up Data
Export Database Contents:
Export all stored data to a file:
Import Previously Exported Data:
Restore data from an XML file:
Backing Up Workspaces:
Backup specific workspaces for later reuse.
Common Use Cases
Storing Scanned Hosts and Services:
Use
db_nmap
to scan a network and populate the database:View the results:
Credential Management:
Automatically store discovered credentials:
Collaborative Penetration Testing:
Use the database to synchronize data across team members by sharing exports.
Tracking Progress Across Engagements:
Separate each client’s data using workspaces.
Command Cheatsheet
db_status
Check if the database is connected.
db_connect
Connect to the database manually.
db_import <file>
Import Nmap or Nessus scan results.
db_export <file>
Export database content to a file.
workspace
List or manage workspaces.
hosts
Display discovered hosts.
services
List services running on discovered hosts.
creds
View stored credentials.