Files
metasploit-gs/modules/post/multi/recon/local_exploit_suggester.rb
T

179 lines
5.0 KiB
Ruby
Raw Normal View History

2015-07-29 13:19:51 -05:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2015-07-29 13:19:51 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2015-07-29 13:19:51 -05:00
2018-05-05 04:41:58 +00:00
include Msf::Auxiliary::Report
def initialize(info = {})
2015-07-29 13:19:51 -05:00
super(update_info(info,
2018-05-05 04:41:58 +00:00
'Name' => 'Multi Recon Local Exploit Suggester',
'Description' => %q{
This module suggests local meterpreter exploits that can be used.
The exploits are suggested based on the architecture and platform
that the user has a shell opened as well as the available exploits
in meterpreter.
It's important to note that not all local exploits will be fired.
Exploits are chosen based on these conditions: session type,
platform, architecture, and required default options.
},
'License' => MSF_LICENSE,
'Author' => [ 'sinn3r', 'Mo' ],
'Platform' => all_platforms,
'SessionTypes' => [ 'meterpreter', 'shell' ]))
register_options [
Msf::OptInt.new('SESSION', [ true, 'The session to run this module on' ]),
Msf::OptBool.new('SHOWDESCRIPTION', [true, 'Displays a detailed description for the available exploits', false])
]
2015-07-29 13:19:51 -05:00
end
2015-07-29 13:19:51 -05:00
def all_platforms
2018-05-05 04:41:58 +00:00
Msf::Module::Platform.subclasses.collect { |c| c.realname.downcase }
2015-07-29 13:19:51 -05:00
end
def is_module_arch?(mod)
mod_arch = mod.target.arch || mod.arch
2018-05-05 04:41:58 +00:00
mod_arch.include? session.arch
2015-07-29 13:19:51 -05:00
end
def is_module_options_ready?(mod)
mod.options.each_pair do |option_name, option|
2018-05-05 04:41:58 +00:00
return false if option.required && option.default.nil? && mod.datastore[option_name].blank?
2015-07-29 13:19:51 -05:00
end
2015-07-29 13:19:51 -05:00
true
end
def is_module_platform?(mod)
2018-05-05 04:41:58 +00:00
platform_obj = Msf::Module::Platform.find_platform session.platform
2015-07-29 13:19:51 -05:00
module_platforms = mod.target.platform ? mod.target.platform.platforms : mod.platform.platforms
2018-05-05 04:41:58 +00:00
module_platforms.include? platform_obj
rescue ArgumentError => e
# When not found, find_platform raises an ArgumentError
elog "#{e.class} #{e.message}\n#{e.backtrace * "\n"}"
return false
2015-07-29 13:19:51 -05:00
end
2015-07-30 18:26:41 -05:00
def is_session_type_compat?(mod)
2018-05-05 04:41:58 +00:00
mod.session_compatible? session.sid
2015-07-30 18:26:41 -05:00
end
def set_module_options(mod)
2018-05-05 04:41:58 +00:00
datastore.each_pair do |k, v|
mod.datastore[k] = v
end
2015-07-30 10:10:42 -05:00
if !mod.datastore['SESSION'] && session.present?
mod.datastore['SESSION'] = session.sid
end
end
2015-07-30 18:26:41 -05:00
def is_module_wanted?(mod)
(
mod.kind_of?(Msf::Exploit::Local) &&
2019-12-13 10:51:58 +00:00
mod.has_check? &&
2015-07-30 18:26:41 -05:00
is_session_type_compat?(mod) &&
is_module_platform?(mod) &&
is_module_arch?(mod) &&
is_module_options_ready?(mod)
)
end
2015-07-29 13:19:51 -05:00
def setup
print_status "Collecting local exploits for #{session.session_type}..."
2015-07-30 18:26:41 -05:00
# Initializes an array
2015-07-29 13:19:51 -05:00
@local_exploits = []
# Collects exploits into an array
2018-05-05 04:41:58 +00:00
framework.exploits.each do |name, _obj|
mod = framework.exploits.create name
next unless mod
2018-05-05 04:41:58 +00:00
set_module_options mod
next unless is_module_wanted? mod
@local_exploits << mod
2015-07-30 18:26:41 -05:00
end
end
def show_found_exploits
2018-05-05 04:41:58 +00:00
unless datastore['VERBOSE']
print_status "#{@local_exploits.length} exploit checks are being tried..."
return
2015-07-30 18:40:41 -05:00
end
2018-05-05 04:41:58 +00:00
vprint_status "The following #{@local_exploits.length} exploit checks are being tried:"
2015-07-30 18:26:41 -05:00
@local_exploits.each do |x|
2018-05-05 04:41:58 +00:00
vprint_status x.fullname
2015-07-30 18:26:41 -05:00
end
2015-07-29 13:19:51 -05:00
end
def run
2018-05-05 04:41:58 +00:00
if @local_exploits.empty?
print_error 'No suggestions available.'
2015-07-30 18:26:41 -05:00
return
end
show_found_exploits
2015-08-20 13:57:16 -05:00
results = []
2015-07-29 13:19:51 -05:00
@local_exploits.each do |m|
2015-07-30 18:26:41 -05:00
begin
checkcode = m.check
2018-05-05 04:41:58 +00:00
if checkcode.nil?
vprint_error "#{m.fullname}: Check failed"
next
end
2015-07-29 13:19:51 -05:00
# See def is_check_interesting?
2018-05-05 04:41:58 +00:00
unless is_check_interesting? checkcode
2019-10-28 03:24:20 +00:00
vprint_status "#{m.fullname}: #{checkcode.message}"
2018-05-05 04:41:58 +00:00
next
end
# Prints the full name and the checkcode message for the exploit
2019-10-28 03:24:20 +00:00
print_good "#{m.fullname}: #{checkcode.message}"
results << [m.fullname, checkcode.message]
2018-05-05 04:41:58 +00:00
# If the datastore option is true, a detailed description will show
next unless datastore['SHOWDESCRIPTION']
# Formatting for the description text
Rex::Text.wordwrap(Rex::Text.compress(m.description), 2, 70).split(/\n/).each do |line|
print_line line
2015-07-30 18:26:41 -05:00
end
rescue Rex::Post::Meterpreter::RequestError => e
# Creates a log record in framework.log
2018-05-05 04:41:58 +00:00
elog "#{e.class} #{e.message}\n#{e.backtrace * "\n"}"
vprint_error "#{e.class} #{m.shortname} failed to run: #{e.message}"
2015-07-30 18:26:41 -05:00
end
end
2018-05-05 04:41:58 +00:00
2015-08-20 13:57:16 -05:00
report_note(
:host => rhost,
2018-05-05 04:41:58 +00:00
:type => 'local.suggested_exploits',
:data => results
)
2015-07-29 13:19:51 -05:00
end
def is_check_interesting?(checkcode)
[
Msf::Exploit::CheckCode::Vulnerable,
Msf::Exploit::CheckCode::Appears,
Msf::Exploit::CheckCode::Detected
2018-05-05 04:41:58 +00:00
].include? checkcode
2015-07-29 13:19:51 -05:00
end
def print_status(msg='')
super("#{session.session_host} - #{msg}")
end
def print_good(msg='')
super("#{session.session_host} - #{msg}")
end
def print_error(msg='')
super("#{session.session_host} - #{msg}")
end
2015-07-29 13:19:51 -05:00
end