2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-07-14 06:34:58 +00:00
|
|
|
require 'msf/base/simple'
|
2013-05-24 17:33:42 +00:00
|
|
|
require 'msf/base/simple/framework/module_paths'
|
2005-07-14 06:34:58 +00:00
|
|
|
|
|
|
|
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
|
2013-08-30 21:28:33 +00:00
|
|
|
include Msf::Simple::Framework::ModulePaths
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#
|
|
|
|
# We extend modules when we're created, and we do it by registering a
|
|
|
|
# general event subscriber.
|
|
|
|
#
|
|
|
|
include GeneralEventSubscriber
|
|
|
|
|
|
|
|
#
|
|
|
|
# Simplifies module instances when they're created.
|
|
|
|
#
|
|
|
|
def on_module_created(instance)
|
|
|
|
Msf::Simple::Framework.simplify_module(instance)
|
|
|
|
end
|
|
|
|
|
|
|
|
ModuleSimplifiers =
|
|
|
|
{
|
2014-10-17 17:43:40 +00:00
|
|
|
Msf::MODULE_ENCODER => Msf::Simple::Encoder,
|
|
|
|
Msf::MODULE_EXPLOIT => Msf::Simple::Exploit,
|
|
|
|
Msf::MODULE_NOP => Msf::Simple::Nop,
|
|
|
|
Msf::MODULE_PAYLOAD => Msf::Simple::Payload,
|
|
|
|
Msf::MODULE_AUX => Msf::Simple::Auxiliary,
|
|
|
|
Msf::MODULE_POST => Msf::Simple::Post,
|
2013-08-30 21:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create a simplified instance of the framework. This routine takes a hash
|
|
|
|
# of parameters as an argument. This hash can contain:
|
|
|
|
#
|
2014-12-01 21:38:48 +00:00
|
|
|
# @param opts [Hash{String => Object}]
|
|
|
|
# @option opts (see simplify)
|
|
|
|
# @return [Msf::Simple::Frameworkt s]
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.create(opts = {})
|
|
|
|
framework = Msf::Framework.new(opts)
|
|
|
|
return simplify(framework, opts)
|
|
|
|
end
|
|
|
|
|
2014-12-01 21:36:38 +00:00
|
|
|
# @note If `opts['ConfigDirectory']` is set, then `Msf::Config::Defaults['ConfigDirectory']` will be updated to
|
|
|
|
# `opts['ConfigDirectory']`.
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
|
|
|
# Extends a framework object that may already exist.
|
|
|
|
#
|
2014-12-01 21:36:38 +00:00
|
|
|
# @param framework [Msf::Framework, Msf::Simple::Framework] framework to simplify
|
|
|
|
# @param opts [Hash{String => Object}]
|
|
|
|
# @option opts [#call] 'OnCreateProc' Proc to call after {#init_simplified}. Will be passed `framework`.
|
|
|
|
# @option opts [String] 'ConfigDirectory' Directory where configuration is saved. The `~/.msf4` directory.
|
|
|
|
# @option opts [Boolean] 'DisableLogging' (false) `true` to disable `Msf::Logging.init`
|
|
|
|
# @option opts [Boolean] 'DeferModuleLoads' (false) `true` to disable `framework.init_module_paths`.
|
|
|
|
# @return [Msf::Simple::Framework] `framework`
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.simplify(framework, opts)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Initialize the simplified framework
|
|
|
|
framework.init_simplified()
|
|
|
|
|
|
|
|
# Call the creation procedure if one was supplied
|
|
|
|
if (opts['OnCreateProc'])
|
|
|
|
opts['OnCreateProc'].call(framework)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Change to a different configuration path if requested
|
|
|
|
if opts['ConfigDirectory']
|
|
|
|
Msf::Config::Defaults['ConfigDirectory'] = opts['ConfigDirectory']
|
|
|
|
end
|
|
|
|
|
|
|
|
# Initialize configuration and logging
|
|
|
|
Msf::Config.init
|
2014-02-02 20:35:16 +00:00
|
|
|
Msf::Logging.init unless opts['DisableLogging']
|
2013-08-30 21:28:33 +00:00
|
|
|
|
|
|
|
# Load the configuration
|
|
|
|
framework.load_config
|
|
|
|
|
|
|
|
# Register the framework as its own general event subscriber in this
|
|
|
|
# instance
|
|
|
|
framework.events.add_general_subscriber(framework)
|
|
|
|
|
|
|
|
unless opts['DeferModuleLoads']
|
|
|
|
framework.init_module_paths
|
|
|
|
end
|
|
|
|
|
|
|
|
return framework
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Simplifies a module instance if the type is supported by extending it
|
|
|
|
# with the simplified module interface.
|
|
|
|
#
|
|
|
|
def self.simplify_module(instance, load_saved_config = true)
|
|
|
|
if ((ModuleSimplifiers[instance.type]) and
|
|
|
|
(instance.class.include?(ModuleSimplifiers[instance.type]) == false))
|
|
|
|
instance.extend(ModuleSimplifiers[instance.type])
|
|
|
|
|
|
|
|
instance.init_simplified(load_saved_config)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Simplified interface
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes the simplified interface.
|
|
|
|
#
|
|
|
|
def init_simplified
|
|
|
|
self.stats = Statistics.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#
|
|
|
|
# Statistics.
|
|
|
|
#
|
|
|
|
attr_reader :stats
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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:
|
2012-06-16 20:41:37 +00:00
|
|
|
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
protected
|
|
|
|
|
2013-08-30 21:28:33 +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
|
|
|
|