Metasploit

6 min read1,148 words

Metasploit Framework — Practical Ethical-Hacking Guide

Metasploit is a penetration-testing framework used to discover, validate, and demonstrate vulnerabilities in authorized systems. Since you're working with Kali and Metasploitable2, you can practice the full workflow in an isolated lab.

Link -> https://www.metasploit.com/

1. Check Metasploit

msfconsole

Check the version:

version

Get help:

help

Exit:

exit

2. Basic Metasploit Structure

The main concepts are:

Exploit ↓ Payload ↓ Target ↓ Session ↓ Post-exploitation

Exploit

Code that takes advantage of a vulnerability.

Payload

Code executed after exploitation, such as opening a controlled shell.

Auxiliary

Scanning, enumeration, and other supporting modules.

Post

Post-exploitation modules used after obtaining an authorized session.

Encoder

Transforms payloads; historically used for encoding payloads, though encoding is not a reliable way to bypass modern security controls.

3. Start Metasploit

msfconsole

You'll see:

msf6 >

Search modules:

search

Search by service:

search type:exploit ssh

Search by vulnerability:

search type:exploit name:vsftpd

Search by CVE:

search cve:2011-2523

4. Understand a Module

Select a module:

use exploit/...

Then:

info

Show required options:

show options

Show payloads:

show payloads

Show targets:

show targets

5. Set the Target

Metasploit commonly uses:

set RHOSTS 192.168.56.101

For a local callback in your isolated lab, you may need:

set LHOST 192.168.56.1

Check your Kali IP:

ip addr

or:

ip route

Then verify Metasploit configuration:

show options

6. Metasploit Database

Start PostgreSQL:

sudo systemctl start postgresql

Initialize the database if needed:

sudo msfdb init

Start Metasploit:

msfconsole

Check database status:

db_status

You want something similar to:

[*] Connected to msf. Connection type: postgresql.

7. Import Nmap Results

This is particularly useful because you can combine your Nmap workflow with Metasploit.

First:

nmap -sV -O -oX scan.xml 192.168.56.101

Then inside Metasploit:

db_import scan.xml

Check discovered hosts:

hosts

Check services:

services

This gives you a workflow like:

Nmap ↓ Host discovery ↓ Port/service discovery ↓ Metasploit database ↓ Module research ↓ Authorized validation

8. Auxiliary Modules

Auxiliary modules are useful for enumeration without necessarily exploiting a vulnerability.

Search:

search type:auxiliary

For example:

search type:auxiliary scanner

You can inspect a module:

use auxiliary/... info show options

Set the target:

set RHOSTS 192.168.56.101

Then, when appropriate for your lab:

run

9. Exploit Modules

Search:

search type:exploit

You can narrow the search:

search type:exploit platform:linux

or:

search type:exploit platform:windows

For a known CVE:

search cve:YYYY-NNNN

Before using anything:

info <module>

Then:

show options

This is important because you should understand what the module targets and what options it requires rather than blindly running exploits.

10. Payloads

A payload is what Metasploit attempts to execute after successful exploitation.

List available payloads for the selected exploit:

show payloads

You can inspect one:

info <payload>

For a lab, choose a payload compatible with the target and exploit.

Then:

set PAYLOAD <payload>

Check:

show options

11. Running an Exploit in Your Lab

The general pattern is:

search <vulnerability> use <module> info show options set RHOSTS <LAB-IP> set PAYLOAD <compatible-payload> set LHOST <KALI-IP> show options check run

check is useful when the module supports it because it may determine whether the target appears vulnerable without attempting the full exploitation step.

12. Sessions

If a lab exploit successfully creates a session:

sessions

More information:

sessions -l

Interact with a particular session:

sessions -i 1

Background the current session:

background

Return to the session:

sessions -i 1

Close it when finished:

sessions -K

13. Meterpreter Basics

Some authorized lab exploits produce a Meterpreter session.

Useful commands include:

help

System information:

sysinfo

Current user:

getuid

Current directory:

pwd

List files:

ls

Change directory:

cd /tmp

Process information:

ps

Network information:

ipconfig

On Linux targets, you may instead use the underlying shell:

shell

Then:

whoami id uname -a

Exit the shell:

exit

14. Post-Exploitation

Once you have an authorized lab session, Metasploit provides post modules.

Search:

search type:post

For example:

search type:post platform:linux

You can inspect:

info <module>

and configure it with:

show options

Post-exploitation should be treated as a separate phase from initial exploitation.

15. Useful Metasploit Commands

CommandPurpose
helpShow help
searchFind modules
useSelect module
infoModule information
show optionsRequired settings
show payloadsAvailable payloads
setSet an option
unsetRemove an option
show targetsShow supported targets
checkCheck vulnerability when supported
runExecute module
exploitExecute exploit
sessionsManage sessions
backLeave current module
searchSearch modules
jobsView background jobs
db_statusDatabase status
hostsDatabase hosts
servicesDatabase services
exitExit Metasploit

16. Your Recommended Metasploitable2 Lab

Since you're already setting up Kali + Metasploitable2, use this sequence:

Phase 1 — Discover

sudo nmap -sn 192.168.56.0/24

Phase 2 — Enumerate

sudo nmap -sV -O -p- 192.168.56.101

Phase 3 — Save

sudo nmap -sV -O -oX metasploitable.xml 192.168.56.101

Phase 4 — Import

msfconsole
db_import metasploitable.xml hosts services

Phase 5 — Research

search type:exploit

Then investigate a specific service/version discovered by Nmap.

Phase 6 — Validate

use <appropriate-module> info show options check

Only after confirming you're working against your isolated Metasploitable2 machine should you proceed with exploitation.

Phase 7 — Session

If the lab exploit succeeds:

sessions sessions -i 1

Then document what access was obtained and what vulnerability caused it.

The skill you should learn

Don't learn Metasploit as a collection of copy-paste exploits. Learn this chain:

Nmap → Service/version identification → Vulnerability research → Metasploit module → info → show options → check → controlled validation → session → evidence/report

That workflow is much closer to how Metasploit is used in an actual authorized penetration-testing lab.

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy