Metasploit Architecture: Modules, Payloads and Sessions
The Metasploit Framework (open source, maintained by Rapid7) is the best-known exploitation framework, and almost every tester meets it in training labs. It is worth understanding as architecture: a library of interchangeable modules with typed options, a database that stores what was found, and a session layer that manages access once gained. Knowing the architecture lets a tester read a module before trusting it, explain to a client what the tool did, and recognise the framework's traces as a defender. This lesson describes the parts, shows a labelled lab transcript that stops at identification, and builds a toy module registry in Python that enforces scope before any module runs.
No exploit is run in this lesson, and no payload is generated: those details are deliberately left out.
The parts
| Part | What it is | Examples of what it contains |
|---|---|---|
| Modules | the units of work, each with metadata (description, references such as CVE IDs, platforms, reliability notes) and options | see the module types below |
| Options | typed, validated settings of a module | RHOSTS (targets), RPORT, THREADS, credentials; required options must be set before running |
| Database | a PostgreSQL store of workspaces, hosts, services, credentials, vulnerabilities and notes | imported Nmap XML, results of auxiliary modules |
| Sessions | the handles to access obtained on a target | a plain command shell session, or Meterpreter, the framework's own in-memory agent |
| Interfaces | how a human or a program drives it | msfconsole (interactive), resource scripts, an RPC API |
Module types:
- auxiliary: scanners, version detectors, protocol enumerators, login checkers. Most of a test's framework use, when it is used at all, is here.
- exploit: code that uses a specific vulnerability to execute a payload. Each records its target platforms, its rank (an estimate of reliability and side effects, from "excellent" to "manual") and whether it implements a
checkmethod that tests vulnerability without exploitation (many don't). - payload: what runs after successful exploitation. Conceptually there are singles (self-contained), stagers (a small first stage that fetches the rest) and stages. They connect either bind (the target listens, the tester connects) or reverse (the target connects back to a listener). Payload construction is intentionally not covered in this course.
- post: modules that run through an existing session: gather system information, list users. In a test their use is bounded by the post-exploitation rules.
- encoder, nop and evasion modules: transformations of payloads, including attempts to avoid detection by security products. Evasion is outside the scope of professional testing unless the RoE specifically covers testing detection, and outside the scope of this course entirely.
A lab transcript: identification only
Lab session. Authorised internal test of 10.10.0.0/24 from 10.10.0.99, window 2026-12-03 09:00–17:00 UTC. Target legacy01.lab.test (10.10.0.20) is a deliberately vulnerable lab VM (Metasploitable 2). The RoE allows identification with auxiliary modules and forbids running exploit modules without per-finding approval. Output abridged.
msf6 > workspace -a lab-2026-12
[*] Added workspace: lab-2026-12
msf6 > db_import scans/servers.xml
[*] Importing 'Nmap XML' data
[*] Successfully imported scans/servers.xml
msf6 > services -p 21
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.0.20 21 tcp ftp open vsftpd 2.3.4
msf6 > use auxiliary/scanner/ftp/ftp_version
msf6 auxiliary(scanner/ftp/ftp_version) > set RHOSTS 10.10.0.20
RHOSTS => 10.10.0.20
msf6 auxiliary(scanner/ftp/ftp_version) > run
[+] 10.10.0.20:21 - FTP Banner: '220 (vsFTPd 2.3.4)\x0d\x0a'
[*] 10.10.0.20:21 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/ftp/ftp_version) > search vsftpd type:exploit
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/unix/ftp/vsftpd_234_backdoor 2011-07-03 excellent Yes VSFTPD 2.3.4 Backdoor Command Execution
msf6 auxiliary(scanner/ftp/ftp_version) > notes -a -t validation -n "banner 2.3.4; exploit not run per RoE; binary verified with admin (rung 2)" 10.10.0.20The transcript shows the architecture at work: the Nmap results enter the database, an auxiliary module confirms the banner, and the framework's metadata says there is an exploit module for this version, ranked "excellent" (reliable), with a check method. Reading the module's source shows what that check does: it compares the banner and the server's reply to a USER command and reports "appears vulnerable". That is the same banner evidence again, not proof of the backdoored build, and the module also runs the check by itself before exploiting (AutoCheck). The tester stops here, records the decision as a note, and validates the finding by package and binary check with the administrator as in Safe Validation.
A toy registry that enforces scope
Frameworks validate options (is RHOSTS set? is RPORT a port number?), but they don't know your scope. Professional teams wrap them, or use their own scripts, so that every module run is checked against the scope and logged. The toy below has the same shape as a framework's core: modules register with metadata and options, and a runner validates before running. Its one "module" reads banners from a dictionary of simulated lab services, so nothing leaves the page.
import ipaddress
SCOPE = [ipaddress.ip_network("10.10.0.0/24")]
EXCLUDED = [ipaddress.ip_network("10.10.0.1/32"), ipaddress.ip_network("10.10.0.200/29")]
SIMULATED_BANNERS = {("10.10.0.20", 21): "220 (vsFTPd 2.3.4)", ("10.10.0.25", 25): "220 mail.lab.test ESMTP Postfix"}
REGISTRY, LOG = {}, []
def module(name, kind, options, allowed_by_roe):
def register(fn):
REGISTRY[name] = {"kind": kind, "options": options, "roe": allowed_by_roe, "run": fn}
return fn
return register
@module("auxiliary/banner", "auxiliary", {"RHOST": str, "RPORT": int}, allowed_by_roe=True)
def banner(opts):
return SIMULATED_BANNERS.get((opts["RHOST"], opts["RPORT"]), "no answer")
@module("exploit/example_backdoor", "exploit", {"RHOST": str, "RPORT": int}, allowed_by_roe=False)
def not_implemented(opts):
raise RuntimeError("exploit modules are not part of this course")
def in_scope(host):
ip = ipaddress.ip_address(host)
return any(ip in n for n in SCOPE) and not any(ip in n for n in EXCLUDED)
def run(name, **opts):
mod = REGISTRY[name]
for key, typ in mod["options"].items():
if key not in opts or not isinstance(opts[key], typ):
return f"refused: option {key} missing or not {typ.__name__}"
if not mod["roe"]:
return f"refused: {mod['kind']} modules need per-finding approval in the RoE"
if not in_scope(opts["RHOST"]):
return f"refused: {opts['RHOST']} is out of scope"
result = mod["run"](opts)
LOG.append((name, opts["RHOST"], opts["RPORT"], result))
return result
print(run("auxiliary/banner", RHOST="10.10.0.20", RPORT=21))
print(run("auxiliary/banner", RHOST="10.10.0.25", RPORT=25))
print(run("auxiliary/banner", RHOST="10.10.0.203", RPORT=22))
print(run("auxiliary/banner", RHOST="10.10.0.20", RPORT="21"))
print(run("exploit/example_backdoor", RHOST="10.10.0.20", RPORT=21))
print("activity log:", len(LOG), "entries")220 (vsFTPd 2.3.4)
220 mail.lab.test ESMTP Postfix
refused: 10.10.0.203 is out of scope
refused: option RPORT missing or not int
refused: exploit modules need per-finding approval in the RoE
activity log: 2 entries
Options are validated by type, the RoE decides which module kinds may run at all, scope is checked on every run, and only runs that happened reach the activity log. That is a framework's architecture plus the two checks a professional adds.
How framework use is detected
Defenders see framework activity at several layers. IDS rule sets contain signatures for many exploit modules' network traffic and for default payload communication. EDR products flag Meterpreter's in-memory behaviour and the process patterns of common payloads (a service process spawning a shell, or making an outbound connection to an unusual port). Default settings (listener ports, TLS certificates, user agents) are well known to threat-hunting teams. In a test with an announced blue team, every framework run is a chance to record whether it was detected; see Shells and Processes for the process view.
How the underlying weaknesses are fixed
Every exploit module corresponds to a vulnerability with a fix: the module's references list the CVE and advisories. For the transcript's case, the fix is to remove the backdoored vsftpd, rebuild the host from trusted sources and investigate; generally, patch, remove unneeded services, and segment so that a reachable vulnerable service is rare.
Pitfalls
- Running exploit modules because they exist. The rank says how reliable it is, not whether the client agreed.
- Trusting
checkblindly. Many checks are version comparisons, with the same false-positive problems as scanners. - Forgetting the database. It holds client data (hosts, credentials). Encrypt it, keep one workspace per engagement, and delete it at the end.
Practice
- Add an
"auxiliary/ssh_version"module to the toy registry and a simulated banner for10.10.0.10:22. What must every new module declare to be run byrun()? - A colleague proposes running the vsftpd exploit module "just to be sure". Which three lessons' rules does that break?
Answers
- A name, a kind, typed options including
RHOSTandRPORT(the runner's scope check readsRHOST), and anallowed_by_roeflag; then add("10.10.0.10", 22): "SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.10"to the simulated banners. - The RoE (exploit modules need per-finding approval), safe validation (the finding was already proven at rung 2; exploiting adds risk without proof) and exploitation concepts (the action would open a root shell listener on the network, not a minimal step).
Test yourself
Which Metasploit module type contains scanners and version detectors?
- exploit
- auxiliary
- payload
- encoder
What does an exploit module's 'Check: No' mean?
- It can't be run
- It has no method to test vulnerability without exploiting
- It is unreliable
- It is out of scope
What is the difference between a bind and a reverse connection, conceptually?
- Speed
- Bind: the target listens and the tester connects; reverse: the target connects out to the tester's listener
- Encryption
- Bind is only for Windows
What does the toy runner add that a framework's own option validation doesn't provide?
- Faster scans
- Checks against the engagement's scope and RoE, and an activity log
- Encryption
- More modules