TL;DR
This guide shows you how to automatically search Metasploit for relevant exploits based on vulnerabilities found in your database. We’ll use a simple script to query the database and then run msfconsole commands to find matching modules.
Step-by-step Guide
- Install Required Tools
- You need Metasploit installed. If you don’t have it, follow the instructions on the official website.
- Ensure your vulnerability database is up to date. Run
msfdb reinitif needed. - Access Metasploit Console
- Query the Vulnerability Database
- Create a Script for Automated Searching
- Run the Script
- Interpret the Results
- The script will first output the vulnerability information from the database.
- Then, it will show a list of Metasploit exploits that match your query.
- Review the exploit descriptions and choose the most appropriate one for your target.
- Use the Exploit Module
- Update Vulnerability Database Regularly
Open a terminal and start the Metasploit console by typing msfconsole.
msfconsole
Metasploit stores vulnerability information. We’ll use SQL queries to find specific vulnerabilities. First, connect to the database (usually done automatically when starting msfconsole).
Example query to find all vulnerabilities with a specific CVE ID:
db_status
select * from vulnerability_references where name like '%CVE-2023-1234%'
We’ll create a simple script (e.g., in Python) to automate the search process.
import subprocess
cve_id = "CVE-2023-1234"
# Construct the SQL query
query = f"select * from vulnerability_references where name like '%{cve_id}%'"
# Run the msfconsole command to execute the query
command = f"msfconsole -x 'db_exec("{query}")'"
# Execute the command and capture the output
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Print the results
print(result.stdout)
# Search for matching exploits in Metasploit modules
search_command = f"msfconsole -x 'search type:exploit {cve_id}'"
search_result = subprocess.run(search_command, shell=True, capture_output=True, text=True)
print(search_result.stdout)
Save this script as a .py file (e.g., auto_exploit_search.py).
Execute the Python script from your terminal:
python auto_exploit_search.py
Replace “CVE-2023-1234” with the actual CVE ID you want to search for.
Once you’ve identified an exploit, load it into msfconsole:
use exploit/your_chosen_exploit
Configure the exploit options (RHOSTS, LHOST, etc.) and run it.
Keep your Metasploit vulnerability database updated to ensure you have the latest information. Run msfupdate periodically.

