options now have explicit class owners

git-svn-id: file:///home/svn/incoming/trunk@2587 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-06-05 23:45:58 +00:00
parent 2f257cc384
commit a0b6980813
4 changed files with 46 additions and 26 deletions

View File

@ -14,12 +14,13 @@ module Exploit::Remote::DCERPC
include Exploit::Remote::Tcp
def initialize(info = {})
super(merge_info(info,
'Options' =>
super
register_options(
[
Opt::RHOST,
Opt::RPORT(135)
]))
], Msf::Exploit::Remote::DCERPC)
end
end

View File

@ -12,14 +12,15 @@ module Msf
module Exploit::Remote::Tcp
def initialize(info = {})
super(merge_info(info,
'Options' =>
super
register_options(
[
Opt::RHOST,
Opt::RPORT,
Opt::LHOST(nil, false),
Opt::LPORT(nil, false)
]))
], Msf::Exploit::Remote::Tcp)
end
#

View File

@ -35,8 +35,8 @@ class Module
# Create and initialize the option container for this module
self.options = OptionContainer.new
self.options.add_options(info['Options'])
self.options.add_advanced_options(info['AdvancedOptions'])
self.options.add_options(info['Options'], self.class)
self.options.add_advanced_options(info['AdvancedOptions'], self.class)
# Create and initialize the data store for this module
self.datastore = DataStore.new
@ -143,6 +143,20 @@ protected
}.update(self.module_info)
end
#
# Register options with a specific owning class
#
def register_options(options, owner = self.class)
self.options.add_options(options, owner)
end
#
# Register advanced options with a specific owning class
#
def register_advanced_options(options, owner = self.class)
self.options.add_advanced_options(options, owner)
end
#
# Checks to see if a derived instance of a given module implements a method
# beyond the one that is provided by a base class. This is a pretty lame

View File

@ -41,6 +41,7 @@ class OptBase
attr_reader :name, :required, :desc, :default
attr_writer :name
attr_accessor :advanced
attr_accessor :owner
protected
@ -177,13 +178,13 @@ class OptionContainer < Hash
end
# Adds one or more options
def add_options(opts, advanced = false)
def add_options(opts, owner = nil, advanced = false)
return false if (opts == nil)
if (opts.kind_of?(Array))
add_options_array(opts, advanced)
add_options_array(opts, owner, advanced)
else
add_options_hash(opts, advanced)
add_options_hash(opts, owner, advanced)
end
end
@ -191,22 +192,22 @@ class OptionContainer < Hash
#
# Add options from a hash of names
#
def add_options_hash(opts, advanced)
def add_options_hash(opts, owner = nil, advanced = false)
opts.each_pair { |name, opt|
add_option(opt, name, advanced)
add_option(opt, name, owner, advanced)
}
end
#
# Add options from an array of option instances or arrays
#
def add_options_array(opts, advanced = false)
def add_options_array(opts, owner = nil, advanced = false)
opts.each { |opt|
add_option(opt, nil, advanced)
add_option(opt, nil, owner, advanced)
}
end
def add_option(option, name = nil, advanced = false)
def add_option(option, name = nil, owner = nil, advanced = false)
if (option.kind_of?(Array))
option = option.shift.new(name, option)
elsif (!option.kind_of?(OptBase))
@ -216,13 +217,16 @@ class OptionContainer < Hash
end
option.advanced = advanced
option.owner = owner
self.store(option.name, option)
end
# Alias to add advanced options that sets the proper state flag
def add_advanced_options(opts = {})
add_options(opts, true)
def add_advanced_options(opts, owner = nil)
return false if (opts == nil)
add_options(opts, owner, true)
end
# Make sures that each of the options has a value of a compatible