2005-07-14 06:34:58 +00:00
|
|
|
require 'msf/base/simple'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Simple
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class wraps the framework-core supplied Framework class and adds some
|
|
|
|
# helper methods for analyzing statistics as well as other potentially useful
|
|
|
|
# information that is directly necessary to drive the framework-core.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Framework
|
|
|
|
|
2005-11-28 21:38:48 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# Extends the framework.plugins class instance to automatically check in
|
|
|
|
# the framework plugin's directory.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module PluginManager
|
|
|
|
|
|
|
|
#
|
|
|
|
# Loads the supplied plugin by checking to see if it exists in the
|
|
|
|
# framework default plugin path as necessary.
|
|
|
|
#
|
|
|
|
def load(path, opts = {})
|
|
|
|
def_path = Msf::Config.plugin_directory + File::SEPARATOR + path
|
|
|
|
|
|
|
|
if (File.exists?(def_path) or File.exists?(def_path + ".rb"))
|
|
|
|
super(def_path, opts)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2007-02-02 03:45:37 +00:00
|
|
|
#
|
|
|
|
# We extend modules when we're created, and we do it by registering a
|
|
|
|
# general event subscriber.
|
|
|
|
#
|
2005-07-14 06:34:58 +00:00
|
|
|
include GeneralEventSubscriber
|
|
|
|
|
2007-02-02 03:45:37 +00:00
|
|
|
#
|
|
|
|
# Simplifies module instances when they're created.
|
|
|
|
#
|
|
|
|
def on_module_created(instance)
|
|
|
|
Msf::Simple::Framework.simplify_module(instance)
|
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
ModuleSimplifiers =
|
|
|
|
{
|
|
|
|
MODULE_ENCODER => Msf::Simple::Encoder,
|
|
|
|
MODULE_EXPLOIT => Msf::Simple::Exploit,
|
|
|
|
MODULE_NOP => Msf::Simple::Nop,
|
|
|
|
MODULE_PAYLOAD => Msf::Simple::Payload,
|
2006-01-24 03:59:44 +00:00
|
|
|
MODULE_AUX => Msf::Simple::Auxiliary,
|
2010-12-27 17:46:42 +00:00
|
|
|
MODULE_POST => Msf::Simple::Post,
|
2005-07-14 06:34:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2005-10-01 21:51:45 +00:00
|
|
|
# Create a simplified instance of the framework. This routine takes a hash
|
|
|
|
# of parameters as an argument. This hash can contain:
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-10-01 21:51:45 +00:00
|
|
|
# OnCreateProc => A callback procedure that is called once the framework
|
|
|
|
# instance is created.
|
|
|
|
#
|
|
|
|
def self.create(opts = {})
|
2009-01-02 07:29:56 +00:00
|
|
|
framework = Msf::Framework.new(opts)
|
2005-10-01 21:51:45 +00:00
|
|
|
return simplify(framework, opts)
|
2005-07-14 06:34:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Extends a framework object that may already exist.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-10-01 21:51:45 +00:00
|
|
|
def self.simplify(framework, opts)
|
2005-11-28 21:38:48 +00:00
|
|
|
|
|
|
|
# If the framework instance has not already been extended, do it now.
|
|
|
|
if (framework.kind_of?(Msf::Simple::Framework) == false)
|
|
|
|
framework.extend(Msf::Simple::Framework)
|
|
|
|
framework.plugins.extend(Msf::Simple::Framework::PluginManager)
|
|
|
|
end
|
2005-07-14 06:34:58 +00:00
|
|
|
|
|
|
|
# Initialize the simplified framework
|
|
|
|
framework.init_simplified()
|
2010-03-17 18:25:53 +00:00
|
|
|
|
2005-10-01 21:51:45 +00:00
|
|
|
# Call the creation procedure if one was supplied
|
|
|
|
if (opts['OnCreateProc'])
|
|
|
|
opts['OnCreateProc'].call(framework)
|
|
|
|
end
|
|
|
|
|
2010-03-17 18:25:53 +00:00
|
|
|
# Change to a different configuration path if requested
|
|
|
|
if opts['ConfigDirectory']
|
|
|
|
Msf::Config::Defaults['ConfigDirectory'] = opts['ConfigDirectory']
|
|
|
|
end
|
|
|
|
|
2005-10-01 21:26:17 +00:00
|
|
|
# Initialize configuration and logging
|
|
|
|
Msf::Config.init
|
|
|
|
Msf::Logging.init
|
|
|
|
|
2005-07-15 22:30:04 +00:00
|
|
|
# Load the configuration
|
|
|
|
framework.load_config
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
# Register the framework as its own general event subscriber in this
|
|
|
|
# instance
|
|
|
|
framework.events.add_general_subscriber(framework)
|
|
|
|
|
2012-06-16 19:51:09 +00:00
|
|
|
unless opts['DeferModuleLoads']
|
|
|
|
framework.init_module_paths
|
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
return framework
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Simplifies a module instance if the type is supported by extending it
|
|
|
|
# with the simplified module interface.
|
|
|
|
#
|
2012-03-27 03:43:33 +00:00
|
|
|
def self.simplify_module(instance, load_saved_config = true)
|
2005-07-14 06:34:58 +00:00
|
|
|
if ((ModuleSimplifiers[instance.type]) and
|
|
|
|
(instance.class.include?(ModuleSimplifiers[instance.type]) == false))
|
|
|
|
instance.extend(ModuleSimplifiers[instance.type])
|
2005-07-15 22:30:04 +00:00
|
|
|
|
2012-03-27 03:43:33 +00:00
|
|
|
instance.init_simplified(load_saved_config)
|
2005-07-14 06:34:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-16 19:51:09 +00:00
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Simplified interface
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Initializes the simplified interface.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
|
|
|
def init_simplified
|
|
|
|
self.stats = Statistics.new(self)
|
|
|
|
end
|
|
|
|
|
2005-07-15 22:30:04 +00:00
|
|
|
#
|
|
|
|
# Loads configuration, populates the root datastore, etc.
|
|
|
|
#
|
|
|
|
def load_config
|
|
|
|
self.datastore.from_file(Msf::Config.config_file, 'framework/core')
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Saves the module's datastore to the file
|
|
|
|
#
|
|
|
|
def save_config
|
|
|
|
self.datastore.to_file(Msf::Config.config_file, 'framework/core')
|
|
|
|
end
|
|
|
|
|
2012-06-16 19:51:09 +00:00
|
|
|
#
|
|
|
|
# Initialize the module paths
|
|
|
|
#
|
|
|
|
def init_module_paths
|
|
|
|
|
|
|
|
# Ensure the module cache is accurate
|
|
|
|
self.modules.refresh_cache
|
|
|
|
|
|
|
|
# Initialize the default module search paths
|
|
|
|
if (Msf::Config.module_directory)
|
|
|
|
self.modules.add_module_path(Msf::Config.module_directory)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Initialize the user module search path
|
|
|
|
if (Msf::Config.user_module_directory)
|
|
|
|
self.modules.add_module_path(Msf::Config.user_module_directory)
|
|
|
|
end
|
|
|
|
|
|
|
|
# If additional module paths have been defined globally, then load them.
|
|
|
|
# They should be separated by semi-colons.
|
|
|
|
if self.datastore['MsfModulePaths']
|
|
|
|
self.datastore['MsfModulePaths'].split(";").each { |path|
|
|
|
|
self.modules.add_module_path(path)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Statistics.
|
|
|
|
#
|
2005-07-14 06:34:58 +00:00
|
|
|
attr_reader :stats
|
|
|
|
|
2012-06-16 20:41:37 +00:00
|
|
|
#
|
|
|
|
# Boolean indicating whether the cache is initialized yet
|
|
|
|
#
|
|
|
|
attr_reader :cache_initialized
|
|
|
|
|
|
|
|
#
|
|
|
|
# Thread of the running rebuild operation
|
|
|
|
#
|
|
|
|
attr_reader :cache_thread
|
|
|
|
attr_writer :cache_initialized # :nodoc:
|
|
|
|
attr_writer :cache_thread # :nodoc:
|
|
|
|
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
protected
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
attr_writer :stats # :nodoc:
|
2005-07-14 06:34:58 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-01-02 07:29:56 +00:00
|
|
|
end
|
2010-03-17 18:25:53 +00:00
|
|
|
|