Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/base/simple/framework.rb
Views: 11784
# -*- coding: binary -*-1require 'msf/core/constants'2module Msf3module Simple45###6#7# This class wraps the framework-core supplied Framework class and adds some8# helper methods for analyzing statistics as well as other potentially useful9# information that is directly necessary to drive the framework-core.10#11###12module Framework13include Msf::Simple::Framework::ModulePaths1415###16#17# Extends the framework.plugins class instance to automatically check in18# the framework plugin's directory.19#20###21module PluginManager2223#24# Loads the supplied plugin by checking to see if it exists in the25# framework default plugin path as necessary.26#27def load(path, opts = {})28def_path = Msf::Config.plugin_directory + File::SEPARATOR + path2930if (File.exist?(def_path) or File.exist?(def_path + ".rb"))31super(def_path, opts)32else33super34end35end3637end3839#40# We extend modules when we're created, and we do it by registering a41# general event subscriber.42#43include GeneralEventSubscriber4445#46# Simplifies module instances when they're created.47#48def on_module_created(instance)49Msf::Simple::Framework.simplify_module(instance, load_saved_config: true)50end5152ModuleSimplifiers =53{54Msf::MODULE_ENCODER => Msf::Simple::Encoder,55Msf::MODULE_EXPLOIT => Msf::Simple::Exploit,56Msf::MODULE_NOP => Msf::Simple::Nop,57Msf::MODULE_PAYLOAD => Msf::Simple::Payload,58Msf::MODULE_AUX => Msf::Simple::Auxiliary,59Msf::MODULE_POST => Msf::Simple::Post,60Msf::MODULE_EVASION => Msf::Simple::Evasion61}6263# Create a simplified instance of the framework. This routine takes a hash64# of parameters as an argument. This hash can contain:65#66# @param opts [Hash{String => Object}]67# @option opts (see simplify)68# @return [Msf::Simple::Framework]69def self.create(opts = {})70framework = Msf::Framework.new(opts)71return simplify(framework, opts)72end7374# @note If `opts['ConfigDirectory']` is set, then `Msf::Config::Defaults['ConfigDirectory']` will be updated to75# `opts['ConfigDirectory']`.76#77# Extends a framework object that may already exist.78#79# @param framework [Msf::Framework, Msf::Simple::Framework] framework to simplify80# @param opts [Hash{String => Object}]81# @option opts [#call] 'OnCreateProc' Proc to call after {#init_simplified}. Will be passed `framework`.82# @option opts [String] 'ConfigDirectory' Directory where configuration is saved. The `~/.msf4` directory.83# @option opts [Boolean] 'DisableLogging' (false) `true` to disable `Msf::Logging.init`84# @option opts [String] 'Logger' (Flatfile) Will default to logging to `~/.msf4`.85# @option opts [Boolean] 'DeferModuleLoads' (false) `true` to disable `framework.init_module_paths`.86# @return [Msf::Simple::Framework] `framework`87def self.simplify(framework, opts)8889# If the framework instance has not already been extended, do it now.90if (framework.kind_of?(Msf::Simple::Framework) == false)91framework.extend(Msf::Simple::Framework)92framework.plugins.extend(Msf::Simple::Framework::PluginManager)93end9495# Initialize the simplified framework96framework.init_simplified()9798# Call the creation procedure if one was supplied99if (opts['OnCreateProc'])100opts['OnCreateProc'].call(framework)101end102103# Change to a different configuration path if requested104if opts['ConfigDirectory']105Msf::Config::Defaults['ConfigDirectory'] = opts['ConfigDirectory']106end107108# Initialize configuration and logging109Msf::Config.init110unless opts['DisableLogging']111log_sink_name = opts['Logger']112Msf::Logging.init(log_sink_name)113end114115# Load the configuration116framework.load_config117118# Register the framework as its own general event subscriber in this119# instance120framework.events.add_general_subscriber(framework)121122framework.init_module_paths(defer_module_loads: opts['DeferModuleLoads'])123124return framework125end126127#128# Simplifies a module instance if the type is supported by extending it129# with the simplified module interface.130#131def self.simplify_module(instance, load_saved_config: false)132if ((ModuleSimplifiers[instance.type]) and133(instance.class.include?(ModuleSimplifiers[instance.type]) == false))134instance.extend(ModuleSimplifiers[instance.type])135136instance.init_simplified(load_saved_config)137end138end139140141##142#143# Simplified interface144#145##146147#148# Initializes the simplified interface.149#150def init_simplified151self.stats = Statistics.new(self)152end153154#155# Loads configuration, populates the root datastore, etc.156#157def load_config158self.datastore.from_file(Msf::Config.config_file, 'framework/core')159end160161#162# Saves the module's datastore to the file163#164def save_config165self.datastore.to_file(Msf::Config.config_file, 'framework/core')166end167168#169# Statistics.170#171attr_reader :stats172173174#175# Boolean indicating whether the cache is initialized yet176#177attr_reader :cache_initialized178179#180# Thread of the running rebuild operation181#182attr_reader :cache_thread183attr_writer :cache_initialized # :nodoc:184attr_writer :cache_thread # :nodoc:185186187protected188189attr_writer :stats # :nodoc:190191end192193end194end195196197