2005-05-21 18:27:24 +00:00
|
|
|
require 'Msf/Core'
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Module
|
|
|
|
# ------
|
|
|
|
#
|
|
|
|
# The module base class is responsible for providing the common interface
|
|
|
|
# that is used to interact with modules at the most basic levels, such as
|
|
|
|
# by inspecting a given module's attributes (name, dsecription, version,
|
|
|
|
# authors, etc) and by managing the module's data store.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Module
|
|
|
|
|
2005-06-05 00:03:23 +00:00
|
|
|
require 'Msf/Core/Module/Author'
|
|
|
|
require 'Msf/Core/Module/PlatformList'
|
|
|
|
require 'Msf/Core/Module/Reference'
|
|
|
|
require 'Msf/Core/Module/Target'
|
|
|
|
|
2005-06-04 22:26:42 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
self.module_info = info
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
set_defaults
|
|
|
|
|
|
|
|
# Transform some of the fields to arrays as necessary
|
2005-06-05 00:03:23 +00:00
|
|
|
self.author = Author.transform(module_info['Author'])
|
2005-06-04 08:23:16 +00:00
|
|
|
self.arch = Rex::Transformer.transform(module_info['Arch'], Array,
|
2005-05-21 17:57:00 +00:00
|
|
|
[ String ], 'Arch')
|
2005-06-05 00:03:23 +00:00
|
|
|
self.platform = PlatformList.from_a(module_info['Platform'])
|
2005-06-04 08:23:16 +00:00
|
|
|
self.refs = Rex::Transformer.transform(module_info['Ref'], Array,
|
2005-05-21 17:57:00 +00:00
|
|
|
[ SiteReference, Reference ], 'Ref')
|
|
|
|
|
2005-05-21 18:27:24 +00:00
|
|
|
# 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'])
|
|
|
|
|
|
|
|
# Create and initialize the data store for this module
|
2005-05-21 17:57:00 +00:00
|
|
|
self.datastore = DataStore.new
|
2005-05-21 18:27:24 +00:00
|
|
|
self.datastore.import_options(self.options)
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return the module's name
|
|
|
|
def name
|
|
|
|
return module_info['Name']
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return the module's description
|
|
|
|
def description
|
|
|
|
return module_info['Description']
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return the module's version information
|
|
|
|
def version
|
|
|
|
return module_info['Version']
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return the module's abstract type
|
|
|
|
def type
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return a comma separated list of author for this module
|
|
|
|
def author_to_s
|
|
|
|
return author.collect { |author| author.to_s }.join(", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enumerate each author
|
|
|
|
def each_author(&block)
|
|
|
|
author.each(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return a comma separated list of supported architectures, if any
|
|
|
|
def arch_to_s
|
|
|
|
return arch.join(", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enumerate each architecture
|
|
|
|
def each_arch(&block)
|
|
|
|
arch.each(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return whether or not the module supports the supplied architecture
|
|
|
|
def arch?(what)
|
2005-05-22 07:14:16 +00:00
|
|
|
return true if (what == ARCH_ANY)
|
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
return arch.index(what) != nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return a comma separated list of supported platforms, if any
|
|
|
|
def platform_to_s
|
|
|
|
return platform.join(", ")
|
|
|
|
end
|
|
|
|
|
2005-05-21 18:27:24 +00:00
|
|
|
attr_reader :author, :arch, :platform, :refs, :datastore, :options
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# Sets the modules unsupplied info fields to their default values
|
|
|
|
def set_defaults
|
2005-05-22 07:46:41 +00:00
|
|
|
self.module_info = {
|
2005-05-21 17:57:00 +00:00
|
|
|
'Name' => 'No module name',
|
|
|
|
'Description' => 'No module description',
|
|
|
|
'Version' => '0',
|
|
|
|
'Author' => nil,
|
|
|
|
'Arch' => nil,
|
|
|
|
'Platform' => nil,
|
|
|
|
'Ref' => nil
|
2005-05-22 07:46:41 +00:00
|
|
|
}.update(self.module_info)
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
2005-06-04 22:26:42 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# way of doing it, but I couldn't find a better one, so meh.
|
|
|
|
#
|
|
|
|
def derived_implementor?(parent, method_name)
|
|
|
|
(self.method(method_name).to_s.match(/#{parent.to_s}[^:]/)) ? false : true
|
|
|
|
end
|
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
attr_accessor :module_info
|
2005-05-21 18:27:24 +00:00
|
|
|
attr_writer :author, :arch, :platform, :refs, :datastore, :options
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-06-05 00:03:23 +00:00
|
|
|
#
|
|
|
|
# Alias the data types so people can reference them just by Msf:: and not
|
|
|
|
# Msf::Module::
|
|
|
|
#
|
|
|
|
Author = Msf::Module::Author
|
|
|
|
Reference = Msf::Module::Reference
|
|
|
|
SiteReference = Msf::Module::SiteReference
|
|
|
|
Platform = Msf::Module::Platform
|
|
|
|
Target = Msf::Module::Target
|
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|