Files
metasploit-gs/lib/msf/core/exploit/auto_check.rb
T
2020-11-11 22:15:40 +00:00

64 lines
1.8 KiB
Ruby

# -*- coding: binary -*-
module Msf
module Exploit::Remote::AutoCheck
def self.included(base)
raise NotImplementedError, "#{self.name} should not be included, it should be prepended"
end
def initialize(info = {})
super
register_advanced_options([
OptBool.new('AutoCheck', [false, 'Run check before exploitation', true]),
OptBool.new('ForceExploit', [false, 'Override check result', false])
])
end
def exploit
unless datastore['AutoCheck']
print_warning('AutoCheck is disabled, proceeding with exploitation')
return super
end
print_status('Executing automatic check (disable AutoCheck to override)')
warning_msg = 'ForceExploit is enabled, proceeding with exploitation.'
error_msg = 'Enable ForceExploit to override check result.'
case (checkcode = check)
when Exploit::CheckCode::Vulnerable, Exploit::CheckCode::Appears
print_good(checkcode.message)
super
when Exploit::CheckCode::Detected
print_warning(checkcode.message)
super
when Exploit::CheckCode::Safe
if datastore['ForceExploit']
print_warning("#{checkcode.message} #{warning_msg}")
return super
end
fail_with(Module::Failure::NotVulnerable,
"#{checkcode.message} #{error_msg}")
when Exploit::CheckCode::Unsupported
if datastore['ForceExploit']
print_warning("#{checkcode.message} #{warning_msg}")
return super
end
fail_with(Module::Failure::BadConfig, "#{checkcode.message} #{error_msg}")
else
if datastore['ForceExploit']
print_warning("#{checkcode.message} #{warning_msg}")
return super
end
fail_with(Module::Failure::Unknown, "#{checkcode.message} #{error_msg}")
end
end
end
end