Skip to content

Metasploit Operations Notes

These notes cover using Metasploit in test environments such as HTB. Resource scripts (.rc) automate connection setup, while target-specific values live in separate profiles. Do not keep credentials or tickets in Git.

The reference code is in the repository’s packages/metasploit-framework directory. The referenced upstream commit is:

Changes after this commit are not included in the referenced version. When using commands or APIs, also check the bundled tree’s update history.

These commands include credential extraction, relay, remote execution, persistence, and other features that can have a substantial impact on target systems. Use them only in a test environment or one for which you have explicit authorization.

#PurposePage
0Workspaces, msfdb, db_nmap, setg, and the working directoryBasics and the Database
1Placement and reuse of .rc filesResource Scripts
2SSH / WinRM login and Meterpreter upgradeSSH / WinRM Login
3Reverse-shell listeners and upgrading to MeterpreterHandlers and Listeners
4Shells, PowerShell, and port forwarding from MeterpreterMeterpreter Operations
5A full TTY for vim / tmux outside MeterpreterFully Interactive TTY
—Misidentified options, failed upgrades, reachability, and PTY failuresTroubleshooting
PurposePage
Starting point and decision tableWriting Modules
Shared steps, one at a timeShared Steps
ExploitExploit
AuxiliaryAuxiliary
PostPost
Mixins and APIsMixins and APIs
Helper functionsHelper Functions
Using send_request_cgisend_request_cgi
  • rc/: Templates tracked in Git. Do not put secrets here.
  • profiles/: Per-target values such as RHOSTS and LHOST. Do not track in Git.
  • logs/: Destination for spool output.
  • loot/: Storage for important files collected manually or moved from Metasploit loot.
  • Write readable, multiline .rc files. For commands pasted into msfconsole, run one line such as run verbose=true option=value.
~/lab/
├── msf/
│ ├── rc/
│ ├── profiles/
│ ├── logs/
│ └── loot/
└── notes/

Metasploit’s own database, configuration, and loot are mixed under ~/.msf4. Keeping custom scripts and per-target records under ~/lab makes them easier to find after SSH login and gives rsync one location to copy to the host OS.

Terminal window
msfconsole -q -r ~/lab/msf/profiles/target.local.rc

After startup, run show options for each module. Option names and defaults, including CreateSession, DOMAIN, RPORT, and payload options, may vary by Metasploit version.

  • Do not save SSH / WinRM credentials in .rc files.
  • In Meterpreter, treat listeners and upgrades from existing sessions as separate tasks.
  • Avoid automating too much enumeration or privilege escalation at once. On difficult targets, important output can get buried.
  • Treat a bind shell as a payload that listens on the target and is contacted from Kali.
  • Inspect Kerberos tickets with klist first, then use a separate procedure if needed. Do not force ticket operations into WinRM / SSH login scripts.