Files
metasploit-gs/lib/msf/core/exploit/check_scanner.rb
T
2019-05-22 17:40:39 -05:00

64 lines
1.5 KiB
Ruby

# -*- coding: binary -*-
#
# This mixin implements an exploit's check method by invoking a scanner
#
# NOTE: The scanner's run_host method MUST return an Msf::Exploit::CheckCode
#
module Msf
module Exploit::Remote::CheckScanner
def initialize(info = {})
super
register_advanced_options([
OptString.new('CheckScanner', [true, 'Scanner to check with'])
])
end
# When this mixin is included, this method becomes the exploit's check method
#
# @return [Msf::Exploit::CheckCode] Whether or not the target is vulnerable
def check
# Instantiate the scanner
mod = framework.modules.create(scanner)
# Bail if we couldn't
unless mod
print_error("Could not instantiate #{scanner}")
return CheckCode::Unsupported
end
# Bail if run_host isn't defined
unless mod.respond_to?(:run_host)
print_error("#{scanner} does not define a run_host method")
return CheckCode::Unsupported
end
# Merge the exploit's datastore into the scanner's
mod.datastore.merge!(datastore)
# Use the exploit's input and output as the scanner's
mod.user_input, mod.user_output = user_input, user_output
# Use the scanner's CheckCode
checkcode = mod.run_host(rhost)
# Bail if scanner doesn't return a CheckCode
unless Exploit::CheckCode::Codes.value?(checkcode)
print_error("#{scanner} does not return a CheckCode")
return Exploit::CheckCode::Unsupported
end
# Return the CheckCode
checkcode
end
def scanner
datastore['CheckScanner']
end
end
end