option container improvements, working on exploit module
git-svn-id: file:///home/svn/incoming/trunk@2574 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
67cfc3d386
commit
14bead41dd
|
@ -75,6 +75,9 @@ class Exploit < Msf::Module
|
|||
#
|
||||
def initialize(info = {})
|
||||
super(info)
|
||||
|
||||
self.targets = Rex::Transformer.transform(info['Targets'], Array,
|
||||
[ Target ], 'Targets')
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -174,40 +174,52 @@ class OptionContainer < Hash
|
|||
end
|
||||
|
||||
# Adds one or more options
|
||||
def add_options(opts)
|
||||
def add_options(opts, advanced = false)
|
||||
return false if (opts == nil)
|
||||
|
||||
opts.each_key { |name|
|
||||
option = opts[name]
|
||||
if (opts.kind_of?(Array))
|
||||
add_options_array(opts, advanced)
|
||||
else
|
||||
add_options_hash(opts, advanced)
|
||||
end
|
||||
|
||||
# Skip flags
|
||||
next if (name.match(/^_Flag/))
|
||||
end
|
||||
|
||||
if (option.kind_of?(Array))
|
||||
option = option.shift.new(name, option)
|
||||
elsif (!option.kind_of?(OptBase))
|
||||
raise ArgumentError,
|
||||
"The option named #{name} did not come in a compatible format.",
|
||||
caller
|
||||
end
|
||||
|
||||
option.name = name
|
||||
|
||||
# If the advanced flag was supplied, flag the new option as being
|
||||
# an advanced option
|
||||
if (opts['_FlagAdvanced'] == true)
|
||||
option.advanced = true
|
||||
end
|
||||
|
||||
self.store(name, option)
|
||||
#
|
||||
# Add options from a hash of names
|
||||
#
|
||||
def add_options_hash(opts, advanced)
|
||||
opts.each_pair { |name, opt|
|
||||
add_option(opt, name, advanced)
|
||||
}
|
||||
end
|
||||
|
||||
#
|
||||
# Add options from an array of option instances or arrays
|
||||
#
|
||||
def add_options_array(opts, advanced = false)
|
||||
opts.each { |opt|
|
||||
add_option(opt, nil, advanced)
|
||||
}
|
||||
end
|
||||
|
||||
def add_option(option, name = nil, advanced = false)
|
||||
if (option.kind_of?(Array))
|
||||
option = option.shift.new(name, option)
|
||||
elsif (!option.kind_of?(OptBase))
|
||||
raise ArgumentError,
|
||||
"The option named #{name} did not come in a compatible format.",
|
||||
caller
|
||||
end
|
||||
|
||||
option.advanced = advanced
|
||||
|
||||
self.store(option.name, option)
|
||||
end
|
||||
|
||||
# Alias to add advanced options that sets the proper state flag
|
||||
def add_advanced_options(opts = {})
|
||||
opts['_FlagAdvanced'] = true if (opts)
|
||||
|
||||
add_options(opts)
|
||||
add_options(opts, true)
|
||||
end
|
||||
|
||||
# Make sures that each of the options has a value of a compatible
|
||||
|
@ -236,4 +248,45 @@ class OptionContainer < Hash
|
|||
|
||||
end
|
||||
|
||||
#
|
||||
# Builtin framework options with shortcut methods
|
||||
#
|
||||
module Opt
|
||||
|
||||
@@builtin_opts =
|
||||
{
|
||||
'RHOST' => [ OptAddress, 'nil', true, '"The target address."' ],
|
||||
'RPORT' => [ OptPort, 'nil', true, '"The target port."' ],
|
||||
'LHOST' => [ OptAddress, 'nil', true, '"The local address."' ],
|
||||
'LPORT' => [ OptPort, 'nil', true, '"The local port."' ],
|
||||
'CPORT' => [ OptPort, 'nil', false, '"The local client port."' ],
|
||||
}
|
||||
|
||||
#
|
||||
# Build the builtin_xyz methods on the fly using the type information for each
|
||||
# of the builtin framework options, such as RHOST.
|
||||
#
|
||||
class <<self
|
||||
@@builtin_opts.each_pair { |opt, info|
|
||||
eval(
|
||||
"
|
||||
def builtin_#{opt.downcase}(default = #{info[1]}, required = #{info[2]}, desc = #{info[3]})
|
||||
#{info[0]}.new('#{opt}', [ required, desc, default ])
|
||||
end
|
||||
|
||||
alias #{opt} builtin_#{opt.downcase}
|
||||
")
|
||||
}
|
||||
end
|
||||
|
||||
#
|
||||
# Define the constant versions of the options which are merely redirections to
|
||||
# the class methods.
|
||||
#
|
||||
@@builtin_opts.each_pair { |opt, info|
|
||||
eval("#{opt} = Msf::Opt::builtin_#{opt.downcase}")
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -94,6 +94,22 @@ class OptionContainer::UnitTest < Test::Unit::TestCase
|
|||
assert_equal(true, options.get('DONKEY').advanced?,
|
||||
"advanced option failed")
|
||||
end
|
||||
|
||||
def test_builtin
|
||||
options = OptionContainer.new
|
||||
|
||||
options.add_options(
|
||||
[
|
||||
Opt::RHOST,
|
||||
Opt::RPORT(135),
|
||||
Opt::LHOST('127.0.0.1')
|
||||
])
|
||||
|
||||
assert_equal(135, options.get('RPORT').default, "invalid RPORT default")
|
||||
assert_equal(true, options.get('RPORT').required?, "invalid RPORT require")
|
||||
assert_equal('127.0.0.1', options.get('LHOST').default, "invalid LHOST default")
|
||||
assert_equal('LHOST', options.get('LHOST').name, "invalid LHOST name")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ class Rex::TestSuite
|
|||
suite << Rex::Socket::UnitTest.suite
|
||||
suite << Rex::Socket::Parameters::UnitTest.suite
|
||||
suite << Rex::Socket::Tcp::UnitTest.suite
|
||||
suite << Rex::Socket::SslTcp::UnitTest.suite
|
||||
# suite << Rex::Socket::SslTcp::UnitTest.suite
|
||||
suite << Rex::Socket::TcpServer::UnitTest.suite
|
||||
suite << Rex::Socket::Udp::UnitTest.suite
|
||||
suite << Rex::Socket::Comm::Local::UnitTest.suite
|
||||
|
|
Loading…
Reference in New Issue