Module: Msf::Simple::Framework

Includes:
GeneralEventSubscriber, ModulePaths
Defined in:
lib/msf/base/simple/framework.rb,
lib/msf/base/simple/framework/module_paths.rb

Overview

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.

Defined Under Namespace

Modules: ModulePaths, PluginManager

Constant Summary collapse

ModuleSimplifiers =
{
  MODULE_ENCODER => Msf::Simple::Encoder,
  MODULE_EXPLOIT => Msf::Simple::Exploit,
  MODULE_NOP     => Msf::Simple::Nop,
  MODULE_PAYLOAD => Msf::Simple::Payload,
  MODULE_AUX     => Msf::Simple::Auxiliary,
  MODULE_POST    => Msf::Simple::Post,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GeneralEventSubscriber

#on_module_complete, #on_module_error, #on_module_load, #on_module_run

Methods included from ModulePaths

#init_module_paths

Instance Attribute Details

#cache_initializedObject

Boolean indicating whether the cache is initialized yet


168
169
170
# File 'lib/msf/base/simple/framework.rb', line 168

def cache_initialized
  @cache_initialized
end

#cache_threadObject

Thread of the running rebuild operation


173
174
175
# File 'lib/msf/base/simple/framework.rb', line 173

def cache_thread
  @cache_thread
end

#statsObject

Statistics.


163
164
165
# File 'lib/msf/base/simple/framework.rb', line 163

def stats
  @stats
end

Class Method Details

.create(opts = {}) ⇒ Object

Create a simplified instance of the framework. This routine takes a hash of parameters as an argument. This hash can contain:

OnCreateProc => A callback procedure that is called once the framework
instance is created.

72
73
74
75
# File 'lib/msf/base/simple/framework.rb', line 72

def self.create(opts = {})
  framework = Msf::Framework.new(opts)
  return simplify(framework, opts)
end

.simplify(framework, opts) ⇒ Object

Extends a framework object that may already exist.


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/msf/base/simple/framework.rb', line 80

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
  Msf::Logging.init unless opts['DisableLogging']

  # 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

.simplify_module(instance, load_saved_config = true) ⇒ Object

Simplifies a module instance if the type is supported by extending it with the simplified module interface.


123
124
125
126
127
128
129
130
# File 'lib/msf/base/simple/framework.rb', line 123

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

Instance Method Details

#init_simplifiedObject

Initializes the simplified interface.


142
143
144
# File 'lib/msf/base/simple/framework.rb', line 142

def init_simplified
  self.stats = Statistics.new(self)
end

#load_configObject

Loads configuration, populates the root datastore, etc.


149
150
151
# File 'lib/msf/base/simple/framework.rb', line 149

def load_config
  self.datastore.from_file(Msf::Config.config_file, 'framework/core')
end

#on_module_created(instance) ⇒ Object

Simplifies module instances when they're created.


51
52
53
# File 'lib/msf/base/simple/framework.rb', line 51

def on_module_created(instance)
  Msf::Simple::Framework.simplify_module(instance)
end

#save_configObject

Saves the module's datastore to the file


156
157
158
# File 'lib/msf/base/simple/framework.rb', line 156

def save_config
  self.datastore.to_file(Msf::Config.config_file, 'framework/core')
end