Skip to content

Commit b24b23f

Browse files
authored
Merge pull request #21138 from g0tmi1k/rhosts
[Bug Fix] Auxiliary: Check if module is meant to have rhosts
2 parents 55152da + c0a9794 commit b24b23f

File tree

3 files changed

+133
-7
lines changed

3 files changed

+133
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def cmd_run(*args, action: nil, opts: {})
6262

6363
begin
6464
# Check if this is a scanner module or doesn't target remote hosts
65-
if rhosts.blank? || mod.class.included_modules.include?(Msf::Auxiliary::MultipleTargetHosts)
65+
if rhosts.blank? ||
66+
mod.class.included_modules.include?(Msf::Auxiliary::MultipleTargetHosts) ||
67+
!mod.datastore.options.key?('RHOSTS')
6668
mod_with_opts.run_simple(
6769
'Action' => args[:action],
6870
'LocalInput' => driver.input,

modules/auxiliary/scanner/oracle/isqlplus_sidbrute.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def initialize
3535
])
3636

3737
deregister_options(
38-
"RHOST", "USERNAME", "PASSWORD", "USER_FILE", "PASS_FILE", "USERPASS_FILE",
38+
"USERNAME", "PASSWORD", "USER_FILE", "PASS_FILE", "USERPASS_FILE",
3939
"BLANK_PASSWORDS", "USER_AS_PASS", "REMOVE_USER_FILE", "REMOVE_PASS_FILE",
4040
"BRUTEFORCE_SPEED" # Slow as heck anyway
4141
)

spec/lib/msf/ui/console/command_dispatcher/auxiliary_spec.rb

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def cleanup
145145
mod
146146
end
147147

148-
let(:aux_mod_with_option_validation) do
148+
let(:aux_mod_with_rhost_option_validation) do
149149
mod_klass = Class.new(Msf::Auxiliary) do
150150
def initialize(info = {})
151151
super(
@@ -157,6 +157,53 @@ def initialize(info = {})
157157

158158
register_options(
159159
[
160+
Msf::Opt::RHOST,
161+
Msf::OptString.new('USERNAME', [ true, 'Set me to be greeted']),
162+
Msf::OptString.new('PASSWORD', [ false, 'Secret value' ])
163+
]
164+
)
165+
end
166+
167+
def validate
168+
super
169+
170+
if datastore['PASSWORD'] != 'PleaseThrowTheBall'
171+
raise Msf::OptionValidateError.new({'PASSWORD' => 'Nuh uh uh, you didn\'t say the magic word.'})
172+
end
173+
end
174+
175+
def check
176+
print_status('Check completed!')
177+
end
178+
179+
def run
180+
print("Hello #{datastore['USERNAME']}")
181+
print_status('Run completed!')
182+
end
183+
end
184+
185+
mod = mod_klass.new
186+
datastore = Msf::ModuleDataStore.new(mod)
187+
allow(mod).to receive(:framework).and_return(framework)
188+
mod.send(:datastore=, datastore)
189+
datastore.import_options(mod.options)
190+
Msf::Simple::Framework.simplify_module(mod)
191+
mod
192+
end
193+
194+
let(:aux_mod_with_file_format_option_validation) do
195+
mod_klass = Class.new(Msf::Auxiliary) do
196+
def initialize(info = {})
197+
super(
198+
'Name' => 'mock file format module',
199+
'Description' => 'mock file format module',
200+
'Author' => ['Unknown'],
201+
'License' => MSF_LICENSE
202+
)
203+
204+
register_options(
205+
[
206+
Msf::OptString.new('FILENAME', [ false, 'The file name', 'foo.zip']),
160207
Msf::OptString.new('USERNAME', [ true, 'Set me to be greeted']),
161208
Msf::OptString.new('PASSWORD', [ false, 'Secret value' ])
162209
]
@@ -431,8 +478,46 @@ def run
431478
end
432479
end
433480

434-
context 'when running an auxiliary module with option validation' do
435-
let(:current_mod) { aux_mod_with_option_validation }
481+
context 'when running an auxiliary module with rhost option validation' do
482+
let(:current_mod) { aux_mod_with_rhost_option_validation }
483+
484+
it 'reports options that fail validation' do
485+
allow(current_mod).to receive(:check).and_call_original
486+
allow(current_mod).to receive(:validate).and_call_original
487+
current_mod.datastore['RHOSTS'] = '192.0.2.1'
488+
current_mod.datastore['USERNAME'] = 'Jackson'
489+
current_mod.datastore['PASSWORD'] = 'ThrowTheBall'
490+
subject.cmd_check
491+
expected_output = [
492+
'Msf::OptionValidateError The following options failed to validate:',
493+
'Invalid option PASSWORD: Nuh uh uh, you didn\'t say the magic word.'
494+
]
495+
496+
expect(@combined_output).to match_array(expected_output)
497+
expect(subject.mod).not_to have_received(:check)
498+
expect(subject.mod).to have_received(:validate).at_least(:once)
499+
end
500+
501+
it 'runs when validation passes' do
502+
allow(current_mod).to receive(:check).and_call_original
503+
allow(current_mod).to receive(:validate).and_call_original
504+
current_mod.datastore['RHOSTS'] = '192.0.2.1'
505+
current_mod.datastore['USERNAME'] = 'Jackson'
506+
current_mod.datastore['PASSWORD'] = 'PleaseThrowTheBall'
507+
subject.cmd_check
508+
expected_output = [
509+
'Check completed!',
510+
'192.0.2.1 - Check failed: The state could not be determined.'
511+
]
512+
513+
expect(@combined_output).to match_array(expected_output)
514+
expect(subject.mod).to have_received(:check)
515+
expect(subject.mod).to have_received(:validate).at_least(:once)
516+
end
517+
end
518+
519+
context 'when running an auxiliary module with file format option validation' do
520+
let(:current_mod) { aux_mod_with_file_format_option_validation }
436521

437522
it 'reports options that fail validation' do
438523
allow(current_mod).to receive(:check).and_call_original
@@ -804,8 +889,8 @@ def run
804889
end
805890
end
806891

807-
context 'when running an auxiliary module with option validation' do
808-
let(:current_mod) { aux_mod_with_option_validation }
892+
context 'when running an auxiliary rhost module with option validation' do
893+
let(:current_mod) { aux_mod_with_rhost_option_validation }
809894

810895
it 'reports options that fail validation' do
811896
allow(current_mod).to receive(:run).and_call_original
@@ -843,6 +928,45 @@ def run
843928
expect(subject.mod).to have_received(:validate).at_least(:once)
844929
end
845930
end
931+
932+
context 'when running an auxiliary file format module with option validation' do
933+
let(:current_mod) { aux_mod_with_file_format_option_validation }
934+
935+
it 'reports options that fail validation' do
936+
allow(current_mod).to receive(:run).and_call_original
937+
allow(current_mod).to receive(:validate).and_call_original
938+
current_mod.datastore['RHOSTS'] = '192.0.2.1'
939+
current_mod.datastore['USERNAME'] = 'Jackson'
940+
current_mod.datastore['PASSWORD'] = 'ThrowTheBall'
941+
subject.cmd_run
942+
expected_output = [
943+
'Msf::OptionValidateError The following options failed to validate:',
944+
'Invalid option PASSWORD: Nuh uh uh, you didn\'t say the magic word.'
945+
]
946+
947+
expect(@combined_output).to match_array(expected_output)
948+
expect(subject.mod).not_to have_received(:run)
949+
expect(subject.mod).to have_received(:validate).at_least(:once)
950+
end
951+
952+
it 'runs when validation passes' do
953+
allow(current_mod).to receive(:run).and_call_original
954+
allow(current_mod).to receive(:validate).and_call_original
955+
current_mod.datastore['RHOSTS'] = '192.0.2.1'
956+
current_mod.datastore['USERNAME'] = 'Jackson'
957+
current_mod.datastore['PASSWORD'] = 'PleaseThrowTheBall'
958+
subject.cmd_run
959+
expected_output = [
960+
'Auxiliary module execution completed',
961+
'Hello Jackson',
962+
'Run completed!',
963+
]
964+
965+
expect(@combined_output).to match_array(expected_output)
966+
expect(subject.mod).to have_received(:run)
967+
expect(subject.mod).to have_received(:validate).at_least(:once)
968+
end
969+
end
846970
end
847971

848972
describe '#cmd_rerun' do

0 commit comments

Comments
 (0)