Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 37 ยท Getting Started

Workspaces, Hosts, Services and Loot

Organise an engagement with Metasploit workspaces and read the database commands hosts, services, vulns, creds, notes and loot, then export data for reports.

Every finding a Metasploit module makes can be stored in the database. Used well, this turns a pile of console output into a searchable record of what exists on the network. The key idea is the workspace: a separate bucket of data per engagement, so results from different clients (or different lab exercises) never mix.

This lesson uses typical example output. The database tables are shown read-only; the Python stand-ins mimic the queries.

Workspaces

TEXT
msf6 > workspace
* default
msf6 > workspace -a lab-week1
[*] Added workspace: lab-week1
[*] Workspace: lab-week1
msf6 > workspace
  default
* lab-week1

workspace -a name creates one, workspace name switches, workspace -d name deletes, and workspace -r old new renames. The asterisk marks the active workspace. Make it a habit: first command of any engagement is a new workspace named after it. The prompt can be set to show the workspace name, which prevents "wrong client" mistakes.

The data model

The database has a handful of core tables, each with a console command.

flowchart TD
    H["hosts: IP, OS guess, state"] --> S["services: port, protocol, name, banner"]
    S --> V["vulns: weakness on a host/service"]
    H --> N["notes: free-form findings"]
    H --> C["creds: usernames, secrets, source"]
    H --> L["loot: files, dumps, saved evidence"]

Everything hangs off a host. A service belongs to a host, a vulnerability to a service or host.

Command Shows
hosts Every host seen, with address, name, OS and notes
services Open ports and what is running; filter with -p 80 or -s http
vulns Vulnerabilities recorded by modules or imports
creds Credentials found or tested (treat as sensitive data)
notes Free-text observations
loot Files and dumps collected during the test

Example services output (invented, shaped like the real table):

TEXT
Services
========
host         port  proto  name  state  info
----         ----  -----  ----  -----  ----
10.10.10.20  22    tcp    ssh   open   OpenSSH 8.x
10.10.10.20  80    tcp    http  open   Example web server 2.4
10.10.10.21  445   tcp    smb   open

Useful options: hosts -c address,os_name chooses columns, hosts -S linux searches, services -u shows only open ports, services -R copies the matching hosts into RHOSTS for the current module, which is a quick way to run a module against everything found, as long as every host is in scope.

services -R and hosts -R fill RHOSTS automatically. Check show options afterwards: a scan can discover hosts outside the agreed range.

Importing and exporting

You can bring in results from other scanners and take data out for reports:

  • db_import file.xml reads scanner output (for example Nmap XML, see Nmap and importing results).
  • db_export -f xml report.xml writes the whole workspace to a file for archiving.
  • db_nmap ... runs Nmap from inside the console and imports its results.

Keep exported evidence in the engagement folder, protected like any sensitive document. Credentials and loot must be encrypted at rest and deleted when the contract says so.

Modelling the host and service tables

The stand-in uses Python dictionaries as a tiny database. It adds hosts and services as a scan would and then answers a typical question: which hosts expose a web service?

Python A tiny hosts and services database

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.

Workspaces keep engagements apart

This second stand-in shows why workspaces matter: the same address can mean different machines for different clients (private ranges overlap constantly).

Python Why workspaces exist

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.

Data handling

The database is evidence. Treat it as confidential: encrypt the disk of your attacker machine, do not sync workspaces to cloud storage you do not control, and delete workspaces after the retention period in your contract (workspace -d). Notes are the right place for observations like "service banner shows an outdated version"; they become the raw material of the report.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use a separate workspace per engagement?

    Overlapping private IP ranges and confidentiality both require separate buckets.
  2. 2. Which command lists open ports and what runs on them?

    services shows port, protocol, name, state and banner information.
  3. 3. What is a risk of services -R?

    Always check show options after using -R, because discovered hosts may be out of scope.
  4. 4. Which command imports an Nmap XML file?

    db_import reads scanner output such as Nmap XML into the current workspace.

Summary

  • Create a workspace first; switch with workspace name.
  • hosts, services, vulns, creds, notes and loot read the database.
  • Import with db_import, export with db_export.
  • The database holds sensitive evidence: protect and delete it according to the contract.

Next: The Framework Architecture