Skip to content

register_options

register_options defines the input fields shown by show options in msfconsole. The registered values can be read in code as datastore['NAME'].

register_options(
[
Opt::RPORT(80),
OptString.new('TARGETURI', [true, 'The base path', '/app/']),
OptString.new('USERNAME', [true, 'Username', 'admin']),
OptString.new('PASSWORD', [false, 'Password', '']),
]
)
register_advanced_options(
[
OptFloat.new('HttpClientTimeout', [false, 'HTTP timeout', 20.0]),
OptBool.new('ForceExploit', [false, 'Override check result', false])
]
)

Write this in initialize after super(update_info(...)) (or after a mixin adds its options).

OptSomething.new(name, [required, description, default], aliases: ..., conditions: ...)
ElementMeaning
nameDatastore key; uppercase is conventional
requiredIf true, appears in show missing
descriptionDescription in show options
defaultInitial value; may be omitted if unnecessary
ClassPurposeExample
OptStringStringTARGETURI, USERNAME
OptIntIntegerCustom port or count
OptBooltrue/falseSSL, STOP_ON_SUCCESS
OptPort1–65535Additional port
OptAddressIPSingle address
OptAddressRangeCIDR / rangeIf the module needs its own
OptPathFile pathWordlist or key
OptEnumChoice%w[GET POST]
Opt::RHOST / Opt::RPORTStandard connection targetOften already added by a mixin
Opt::RHOSTSMultiple hostsAdded by Scanner
Opt::LHOST / Opt::LPORTCallback addressFor exploit payloads
OptEnum.new('METHOD', [true, 'HTTP method', 'GET', %w[GET POST]])
OptPath.new('KEY_FILE', [false, 'SSH private key path', nil])
OptBool.new('CREATESESSION', [false, 'Create a session on success', true])
uri = datastore['TARGETURI']
user = datastore['USERNAME']
timeout = datastore['HttpClientTimeout']

A value set with set TARGETURI /x/ appears here. A setg value is visible from the framework if the module has no option with the same name. See the bundled wiki How-to-use-datastore-options.md for details.

When including HttpClient or Scanner, you should generally avoid registering these options again.

MixinExamples already present
HttpClientRHOST, RPORT, VHOST, SSL, Proxies, UserAgent
ScannerRHOSTS, THREADS
AuthBruteUSERNAME, PASSWORD, USER_FILE, PASS_FILE, STOP_ON_SUCCESS, etc.
PostSESSION

Duplicates can cause warnings or unexpected overrides. Add only what is missing.

Registration functionWhere it appears
register_optionsshow options
register_advanced_optionsshow advanced
register_evasion_optionsshow evasion (HttpClient, etc.)

Moving rarely used timeouts or ForceExploit to advanced options keeps basic options readable.

New Opt classes can use conditions: to show an option based on another option. A simple required/default declaration is often enough to start.

use exploit/linux/http/myapp_rce
show options
show missing
set RHOSTS 10.10.11.123
set TARGETURI /app/
set LHOST 10.10.16.10
run

Next, write the actual processing logic in Entry Methods.