Skip to content

Commit f132bdb

Browse files
committed
Enforce single module stance
1 parent 0e3e7b5 commit f132bdb

File tree

5 files changed

+28
-35
lines changed

5 files changed

+28
-35
lines changed

lib/msf/base/simple/auxiliary.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def self.run_simple(omod, opts = {}, job_listener: Msf::Simple::NoopJobListener.
7171
run_uuid = Rex::Text.rand_text_alphanumeric(24)
7272
job_listener.waiting run_uuid
7373
ctx = [mod, run_uuid, job_listener]
74-
if(mod.passive? or opts['RunAsJob'])
74+
run_as_job = opts['RunAsJob'].nil? ? mod.passive? : opts['RunAsJob']
75+
if run_as_job
7576
mod.job_id = mod.framework.jobs.start_bg_job(
7677
"Auxiliary: #{mod.refname}",
7778
ctx,
@@ -240,4 +241,3 @@ def self.job_cleanup_proc(ctx)
240241

241242
end
242243
end
243-

lib/msf/core/exploit/remote/auto_check.rb

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,27 @@ def with_prepended_auto_check
4141
warning_msg = 'ForceExploit is enabled, proceeding with exploitation.'
4242
error_msg = '"set ForceExploit true" to override check result.'
4343

44-
case (checkcode = check)
44+
check_code = check
45+
case check_code
4546
when Exploit::CheckCode::Vulnerable, Exploit::CheckCode::Appears
46-
print_good(checkcode.message)
47-
yield
47+
print_good(check_code.message)
48+
return yield
4849
when Exploit::CheckCode::Detected
49-
print_warning(checkcode.message)
50-
yield
50+
print_warning(check_code.message)
51+
return yield
5152
when Exploit::CheckCode::Safe
52-
if datastore['ForceExploit']
53-
print_warning("#{checkcode.message} #{warning_msg}")
54-
return yield
55-
end
56-
57-
fail_with(Module::Failure::NotVulnerable, "#{checkcode.message} #{error_msg}")
53+
failure_type = Module::Failure::NotVulnerable
5854
when Exploit::CheckCode::Unsupported
59-
if datastore['ForceExploit']
60-
print_warning("#{checkcode.message} #{warning_msg}")
61-
return yield
62-
end
63-
64-
fail_with(Module::Failure::BadConfig, "#{checkcode.message} #{error_msg}")
55+
failure_type = Module::Failure::BadConfig
6556
else
66-
if datastore['ForceExploit']
67-
print_warning("#{checkcode.message} #{warning_msg}")
68-
return yield
69-
end
57+
failure_type = Module::Failure::Unknown
58+
end
7059

71-
fail_with(Module::Failure::Unknown, "#{checkcode.message} #{error_msg}")
60+
if datastore['ForceExploit']
61+
print_warning("#{check_code.message} #{warning_msg}")
62+
return yield
7263
end
64+
fail_with(failure_type, "#{check_code.message} #{error_msg}")
7365
end
7466

7567
end

lib/msf/core/exploit/remote/check_module.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def check
4949
res = mod.run_simple(
5050
'LocalInput' => user_input,
5151
'LocalOutput' => user_output,
52-
'Options' => datastore.merge(check_options)
52+
'Options' => datastore.merge(check_options),
53+
'RunAsJob' => false
5354
)
5455

5556
# Ensure return value is a CheckCode

lib/msf/core/module/module_info.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module Msf::Module::ModuleInfo
33
# CONSTANTS
44
#
55

6-
# The list of options that support merging in an information hash.
7-
UpdateableOptions = [ "Name", "Description", "Alias", "PayloadCompat" ]
6+
# The list of options that don't support merging in an information hash.
7+
UpdateableOptions = [ "Name", "Description", "Alias", "PayloadCompat" , "Stance"]
88

99
#
1010
# Instance Methods
@@ -224,20 +224,20 @@ def merge_info_version(info, val)
224224
# platforms, and options.
225225
#
226226
def update_info(info, opts)
227-
opts.each_pair { |name, val|
227+
opts.each_pair do |name, val|
228228
# If the supplied option name is one of the ones that we should
229229
# override by default
230-
if (UpdateableOptions.include?(name) == true)
230+
if UpdateableOptions.include?(name)
231231
# Only if the entry is currently nil do we use our value
232-
if (info[name] == nil)
232+
if info[name].nil?
233233
info[name] = val
234234
end
235-
# Otherwise, perform the merge operation like normal
235+
# Otherwise, perform the merge operation like normal
236236
else
237237
merge_check_key(info, name, val)
238238
end
239-
}
239+
end
240240

241-
return info
241+
info
242242
end
243243
end

spec/support/shared/examples/msf/module/module_info.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
described_class::UpdateableOptions
66
}
77

8-
it { is_expected.to match_array(%w{Name Description Alias PayloadCompat})}
8+
it { is_expected.to match_array(%w{Name Description Alias PayloadCompat Stance})}
99
end
1010
end
1111

@@ -25,4 +25,4 @@
2525
it { is_expected.to respond_to_protected :merge_info_version }
2626
it { is_expected.to respond_to :name }
2727
it { is_expected.to respond_to_protected :update_info }
28-
end
28+
end

0 commit comments

Comments
 (0)