Skip to content

Saving Results

This step saves information collected by a module to the Metasploit DB or loot files. The main API owner is Msf::Auxiliary::Report (lib/msf/core/auxiliary/report.rb). Including HttpClient also includes Report.

ResultAPIReason
Attributes of a live hostreport_hostOS and similar data; other APIs often cover this too
Open port / bannerreport_serviceAppears in services
Credentials ready to usecreate_credential / create_credential_login / create_credential_and_loginAppears in creds
Failed logininvalidate_loginRetry control or recordkeeping
Confirmed vulnerabilityreport_vulnA successful exploit session may also be reported automatically
Configuration file, command output, or dumpstore_lootActual file + loot index
Observation that does not fit abovereport_noteUse a dot-separated type
Interesting web page / formreport_web_*Web-related helper

Bundled wiki: How-to-do-reporting-or-store-data-in-module-development.md

report_service(
host: rhost,
port: rport,
proto: 'tcp',
name: ssl? ? 'https' : 'http',
info: res.headers['Server'].to_s
)

If a scanner gets a banner, consider this first.

Use this for data you want to save as a file. It returns the saved path.

path = store_loot(
'example.config', # ltype (type label)
'text/plain', # ctype (approximate MIME type)
rhost, # host; a post module may use session
res.body, # Data
'config.php', # Suggested file name
'ExampleApp config' # Description
)
print_good("Loot saved to #{path}")

A post module example:

data = read_file('/etc/passwd')
store_loot('linux.passwd', 'text/plain', session, data, 'passwd', 'passwd file')

For hashes or passwords ready for immediate login, use the credential API as well as loot.

create_credential_and_login(
workspace_id: myworkspace_id,
origin_type: :service,
module_fullname: fullname,
address: rhost,
port: rport,
protocol: 'tcp',
service_name: 'ssh',
username: user,
private_data: pass,
private_type: :password,
status: Metasploit::Model::Login::Status::SUCCESSFUL
)
MethodPurpose
create_credentialThe credential itself
create_credential_loginRecord of a login to a service
create_credential_and_loginBoth together
invalidate_loginFailed combination

Examples of private_type: :password, :ntlm_hash, :ssh_key.

report_vuln(
host: rhost,
port: rport,
name: name,
refs: references,
info: 'command injection confirmed via id'
)
report_note(
host: rhost,
type: 'example.users',
data: { users: users },
update: :unique_data
)

Use a dot-separated type such as domain.hosts for report_note. That makes it easier for other modules to find.

Modules still run if msfdb is not started, but storage features are less useful. In a test environment, set up Basic Operations and DB first.

db_status
creds
services
loot
vulns
  • Save successful logins as credentials and large text or binary data as loot.
  • Avoid sending the same data indiscriminately to both report_note and store_loot. Give each a clear role.
  • When an exploit opens a session, the framework may also report the vulnerability. Use report_vuln for auxiliary modules or explicit confirmation.

Next is Cleanup.