Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 37 ยท Architecture and Modules

The Metasploit Architecture: Libraries, Interfaces and Modules

Understand how the Metasploit Framework is built: the Rex library, the MSF core, interfaces like msfconsole, the module tree, plugins, tools and where files live on disk.

Knowing how Metasploit is organised makes everything else easier: you will know where a module lives, why options behave the same everywhere and what to read when something misbehaves. The framework is a layered Ruby program. Each layer depends only on the ones below it.

This lesson is a map. Later lessons zoom into module types, module anatomy and options.

The layers

flowchart TD
    UI["Interfaces: msfconsole, msfvenom, msfdb, RPC / API"] --> BASE["Framework Base and Core"]
    BASE --> MODS["Modules: exploits, auxiliary, post, payloads, encoders, nops, evasion"]
    BASE --> PLUG["Plugins and tools"]
    BASE --> REX["Rex library: sockets, protocols, text, encoding"]
    MODS --> REX
    REX --> OS["Ruby and the operating system"]

Interfaces call the framework; the framework loads modules; everything uses Rex for low-level work.

  • Rex (Ruby EXtensions) is the foundation library: network sockets, protocol clients and parsers (HTTP, SMB, DNS), text and encoding helpers, and data structures.
  • MSF Core defines the framework's concepts: modules, sessions, the datastore (option storage), events and the module manager.
  • MSF Base builds friendly pieces on top of the core: simple wrappers, the console's command dispatchers, session handling and logging.
  • Modules are the actual tests, written against the module API.
  • Plugins extend the console at runtime (for example to integrate other scanners or add commands).
  • Tools are standalone helper scripts that are not modules.

Four moving parts

Interfaces How you talk to it.
Core Sessions, options, events.
Rex Sockets and protocols.
Modules The checks themselves.

Layers keep modules small and consistent.

1 / 2

Interfaces

You will meet several front doors to the same framework:

Interface Purpose
msfconsole The main interactive console
msfvenom Payload generation and encoding (covered in payloads)
msfdb Database management
msfrpcd An RPC daemon so other programs can drive the framework
Resource scripts Replay a list of console commands

Because they share the core, the same module works from the console, a script and the RPC API.

Where files live

On a typical Linux install the framework sits in a directory such as /usr/share/metasploit-framework/ (it differs by installer). Inside it you find:

TEXT
modules/        exploits, auxiliary, post, payloads, encoders, nops, evasion
lib/            msf/ (core) and rex/ (library)
data/           wordlists, templates, binaries used by modules
plugins/        loadable plugins
tools/          standalone helper scripts
scripts/        legacy Meterpreter scripts

Your own modules and settings belong in a separate folder in your home directory (~/.msf4/), which Metasploit also scans. Putting custom code there means updates to the framework never overwrite it. The directory also holds msfconsole.rc (commands run at start), the history file, logs and loot.

The directory layout under modules/ mirrors the module path you type: modules/auxiliary/scanner/example/version_scan.rb is loaded as auxiliary/scanner/example/version_scan.

Plugins

A plugin hooks into the console while it runs. You load one with load name and list commands with help. Common uses: importing results from vulnerability scanners, adding a logging plugin or integrating a team server. Plugins are code, so only load ones from sources you trust.

The module tree as data

The stand-in maps file paths to module paths and groups them by type, the same way the loader does. It is a handy way to see that the directory is the namespace.

Python Directory layout becomes module path

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Files that are not under modules/ are not modules, so they map to None.

How a module run flows through the layers

When you type run, the console asks the core's module manager for a fresh instance of the module, copies the options from the datastore into it, and calls its run method. The module uses Rex to open a socket, send protocol data and parse the answer. Anything discovered is reported to the database through the framework API. The next stand-in imitates the "instance and options" step with a small class.

Python A module instance reads its options

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Nothing is sent over the network; the stand-in just shows the validation pattern every real module follows.

Why the architecture matters to defenders

Metasploit's structure explains its footprint. Modules built on Rex use ordinary protocol libraries, so their traffic resembles real clients and is not trivially identifiable by a single string. But the framework also reuses defaults (certain user agents, default option values, known stager patterns), and those are exactly what signature-based detection looks for. The exploit modules lesson and the defence chapter return to this.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Rex?

    Rex (Ruby EXtensions) provides low-level building blocks used by the core and modules.
  2. 2. Where should you put your own custom modules?

    The user directory survives updates and is also scanned for modules.
  3. 3. How does a module path relate to the file system?

    modules/auxiliary/scanner/x/y.rb loads as auxiliary/scanner/x/y.
  4. 4. Which interface lets other programs drive the framework?

    msfrpcd exposes the framework through an RPC API.

Summary

  • Layers: interfaces, core/base, modules and plugins, all built on Rex.
  • Module paths mirror directories; custom modules go in your user folder.
  • Options live in the datastore and are validated by each module.
  • Framework defaults are what detections often key on.

Next: Module Types