Skip to content

Commit 319037e

Browse files
authored
Merge pull request rapid7#20097 from smashery/action_run_arg
Action run arg
2 parents 3a3a2db + b0f8df0 commit 319037e

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

lib/msf/base/simple/exploit.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def self.exploit_simple(oexploit, opts, &block)
6565

6666
# Import options from the OptionStr or Option hash.
6767
exploit._import_extra_options(opts)
68+
exploit.datastore['ACTION'] = opts['Action'] if opts['Action']
6869
opts['Payload'] ||= exploit.datastore['Payload']
6970

7071
unless opts['Quiet']

lib/msf/ui/console/command_dispatcher/exploit.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def cmd_exploit(*args, opts: {})
124124
mod.options.include?('rhosts')
125125

126126
opts = {
127+
'Action' => args[:action],
127128
'Encoder' => args[:encoder] || mod_with_opts.datastore['ENCODER'],
128129
'Payload' => args[:payload] || mod_with_opts.datastore['PAYLOAD'],
129130
'Target' => args[:target] || mod_with_opts.datastore['TARGET'],

lib/msf/ui/console/module_argument_parsing.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def parse_exploit_opts(args)
6161
help_cmd = proc do |_result|
6262
cmd_exploit_help
6363
end
64-
parse_opts(@@exploit_opts, args, help_cmd: help_cmd)&.except(:action)
64+
parse_opts(@@exploit_opts, args, help_cmd: help_cmd)
6565
end
6666

6767
def print_module_run_or_check_usage(command:, description: nil, options: @@module_opts)
@@ -149,7 +149,11 @@ def parse_opts(opts, args, help_cmd:, action: nil)
149149

150150
if resembles_datastore_assignment?(val)
151151
name, val = val.split('=', 2)
152-
append_datastore_option(datastore_options, name, val)
152+
if name.upcase == 'ACTION'
153+
result[:action] = val
154+
else
155+
append_datastore_option(datastore_options, name, val)
156+
end
153157
elsif resembles_rhost_value?(val)
154158
append_datastore_option(datastore_options, 'RHOSTS', val)
155159
else

spec/msf/ui/console/module_argument_parsing_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@
6565
expect(subject.send(opts[:method_name], ['-o', 'RHOSTS=192.168.172.1', '-o', 'RPORT=1337', '-o', 'rhosts=192.168.172.2'])).to include(expected_result)
6666
end
6767

68+
it 'allows setting action inline' do
69+
expected_result = {
70+
datastore_options: {
71+
'RHOSTS' => '192.168.172.1',
72+
'RPORT' => '1337',
73+
}
74+
}
75+
expected_result[:action] = 'action-name' unless opts[:method_name] == 'parse_check_opts'
76+
result = subject.send(opts[:method_name], ['RHOSTS=192.168.172.1', 'RPORT=1337', 'action=action-name'])
77+
expect(result).to include(expected_result)
78+
end
79+
6880
it 'parses the option str directly into its components' do
6981
expected_result = {
7082
datastore_options: {
@@ -344,6 +356,7 @@ def cmd_exploit_help
344356
it 'handles no arguments being supplied' do
345357
args = []
346358
expected_result = {
359+
action: nil,
347360
jobify: false,
348361
quiet: false,
349362
datastore_options: {}
@@ -377,6 +390,7 @@ def cmd_exploit_help
377390
'example.com'
378391
]
379392
expected_result = {
393+
action: nil,
380394
jobify: false,
381395
quiet: true,
382396
datastore_options: {

0 commit comments

Comments
 (0)