Land #10471, Import target DefaultOptions into the datastore

4.x
Brent Cook 2018-08-20 17:30:27 -05:00 committed by Metasploit
parent f3b9901c9f
commit 8c29a3b5da
No known key found for this signature in database
GPG Key ID: CDFB5FA52007B954
4 changed files with 60 additions and 30 deletions

View File

@ -321,6 +321,9 @@ class Exploit < Msf::Module
self.active_timeout = info['Payload']['ActiveTimeout'].to_i
end
# Initialize exploit datastore with target information
import_target_datastore
# All exploits can increase the delay when waiting for a session.
# However, this only applies to aggressive exploits.
if aggressive?
@ -693,6 +696,14 @@ class Exploit < Msf::Module
return (target_idx) ? target_idx.to_i : nil
end
#
# Import the target's DefaultOptions hash into the datastore.
#
def import_target_datastore
return unless target && target.default_options
datastore.import_options_from_hash(target.default_options)
end
#
# Returns the target's platform, or the one assigned to the module itself.
#

View File

@ -129,22 +129,29 @@ class Msf::Module::Target
# Payload-specific options, such as append, prepend, and other values that
# can be set on a per-exploit or per-target basis.
#
# DefaultOptions
#
# DefaultOptions hash to be imported into the datastore.
#
def initialize(name, opts)
opts = {} if (!opts)
opts = {} unless opts
self.name = name
self.platform = opts['Platform'] ? Msf::Module::PlatformList.transform(opts['Platform']) : nil
self.save_registers = opts['SaveRegisters']
self.ret = opts['Ret']
self.opts = opts
self.save_registers = opts['SaveRegisters']
self.ret = opts['Ret'],
self.default_options = opts['DefaultOptions']
if (opts['Arch'])
self.arch = Rex::Transformer.transform(opts['Arch'], Array,
[ String ], 'Arch')
if opts['Platform']
self.platform = Msf::Module::PlatformList.transform(opts['Platform'])
end
if opts['Arch']
self.arch = Rex::Transformer.transform(opts['Arch'], Array, [String], 'Arch')
end
# Does this target have brute force information?
if (opts['Bruteforce'])
if opts['Bruteforce']
self.bruteforce = Bruteforce.new(opts['Bruteforce'])
end
end
@ -305,10 +312,15 @@ class Msf::Module::Target
# option is passed to the constructor of the class.
#
attr_reader :bruteforce
#
# DefaultOptions hash to be imported into the datastore.
#
attr_reader :default_options
protected
attr_writer :name, :platform, :arch, :opts, :ret, :save_registers # :nodoc:
attr_writer :bruteforce # :nodoc:
attr_writer :default_options # :nodoc:
end

View File

@ -1575,7 +1575,7 @@ class Core
# If the driver indicates that the value is not valid, bust out.
if (driver.on_variable_set(global, name, value) == false)
print_error("The value specified for #{name} is not valid.")
return true
return false
end
begin
@ -1589,6 +1589,11 @@ class Core
elog(e.message)
end
# Set PAYLOAD from TARGET
if name.upcase == 'TARGET' && active_module && active_module.exploit?
active_module.import_target_datastore
end
print_line("#{name} => #{datastore[name]}")
end

View File

@ -45,12 +45,14 @@ class MetasploitModule < Msf::Exploit::Remote
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Type' => :unix_memory,
'Payload' => {'BadChars' => ' '}
'Payload' => {'BadChars' => ' '},
'DefaultOptions' => {'PAYLOAD' => 'cmd/unix/reverse_netcat_gaping'}
],
['Linux Dropper',
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'Type' => :linux_dropper
'Type' => :linux_dropper,
'DefaultOptions' => {'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp'}
]
],
'DefaultTarget' => 0,