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 =
{
  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,
  Msf::MODULE_EVASION => Msf::Simple::Evasion
}

Instance Attribute Summary collapse

Attributes included from ModulePaths

#configured_module_paths, #module_paths_inited

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



178
179
180
# File 'lib/msf/base/simple/framework.rb', line 178

def cache_initialized
  @cache_initialized
end

#cache_threadObject

Thread of the running rebuild operation



183
184
185
# File 'lib/msf/base/simple/framework.rb', line 183

def cache_thread
  @cache_thread
end

#statsObject

Statistics.



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

def stats
  @stats
end

Class Method Details

.create(opts = {}) ⇒ Msf::Simple::Framework

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

Parameters:

  • opts (Hash{String => Object}) (defaults to: {})

Options Hash (opts):

  • 'OnCreateProc' (#call)

    Proc to call after #init_simplified. Will be passed 'framework`.

  • 'ConfigDirectory' (String)

    Directory where configuration is saved. The '~/.msf4` directory.

  • 'DisableLogging' (Boolean) — default: false

    'true` to disable `Msf::Logging.init`

  • 'Logger' (String) — default: Flatfile

    Will default to logging to '~/.msf4`.

  • 'DeferModuleLoads' (Boolean) — default: false

    'true` to disable `framework.init_module_paths`.

Returns:



70
71
72
73
# File 'lib/msf/base/simple/framework.rb', line 70

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

.simplify(framework, opts) ⇒ Msf::Simple::Framework

Note:

If 'opts` is set, then `Msf::Config::Defaults` will be updated to `opts`.

Extends a framework object that may already exist.

Parameters:

Options Hash (opts):

  • 'OnCreateProc' (#call)

    Proc to call after #init_simplified. Will be passed 'framework`.

  • 'ConfigDirectory' (String)

    Directory where configuration is saved. The '~/.msf4` directory.

  • 'DisableLogging' (Boolean) — default: false

    'true` to disable `Msf::Logging.init`

  • 'Logger' (String) — default: Flatfile

    Will default to logging to '~/.msf4`.

  • 'DeferModuleLoads' (Boolean) — default: false

    'true` to disable `framework.init_module_paths`.

Returns:



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
118
119
120
121
122
123
124
125
126
# File 'lib/msf/base/simple/framework.rb', line 88

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
  unless opts['DisableLogging']
    log_sink_name = opts['Logger']
    Msf::Logging.init(log_sink_name)
  end

  # Load the configuration
  framework.load_config

  # Register the framework as its own general event subscriber in this
  # instance
  framework.events.add_general_subscriber(framework)

  framework.init_module_paths(defer_module_loads: opts['DeferModuleLoads'])

  return framework
end

.simplify_module(instance, load_saved_config: false) ⇒ Object

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



132
133
134
135
136
137
138
139
# File 'lib/msf/base/simple/framework.rb', line 132

def self.simplify_module(instance, load_saved_config: false)
  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.



151
152
153
# File 'lib/msf/base/simple/framework.rb', line 151

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

#load_configObject

Loads configuration, populates the root datastore, etc.



158
159
160
# File 'lib/msf/base/simple/framework.rb', line 158

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.



49
50
51
# File 'lib/msf/base/simple/framework.rb', line 49

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

#save_configObject

Saves the module’s datastore to the file



165
166
167
# File 'lib/msf/base/simple/framework.rb', line 165

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