Class: Msf::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/msf/base/config.rb

Overview

This class wraps interaction with global configuration that can be used as a persistent storage point for configuration, logs, and other such fun things.

Constant Summary collapse

InstallRoot =

The installation's root directory for the distribution

File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
FileSep =

Default system file separator.

File::SEPARATOR
Defaults =

Default configuration locations.

{
  'ConfigDirectory'     => get_config_root,
  'ConfigFile'          => "config",
  'ModuleDirectory'     => "modules",
  'ScriptDirectory'     => "scripts",
  'LogDirectory'        => "logs",
  'LogosDirectory'      => "logos",
  'SessionLogDirectory' => "logs/sessions",
  'PluginDirectory'     => "plugins",
  'DataDirectory'       => "data",
  'LootDirectory'       => "loot",
  'LocalDirectory'      => "local"
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHash

Updates the config class' self with the default hash.


271
272
273
# File 'lib/msf/base/config.rb', line 271

def initialize
  update(Defaults)
end

Class Method Details

.config_directoryString

Returns the configuration directory default.

Returns:

  • (String)

    the root configuration directory.


96
97
98
# File 'lib/msf/base/config.rb', line 96

def self.config_directory
  self.new.config_directory
end

.config_fileString

Returns the full path to the configuration file.

Returns:

  • (String)

    path to the configuration file.


194
195
196
# File 'lib/msf/base/config.rb', line 194

def self.config_file
  self.new.config_file
end

.data_directoryString

Returns the data directory

Returns:

  • (String)

    path to data directory.


187
188
189
# File 'lib/msf/base/config.rb', line 187

def self.data_directory
  self.new.data_directory
end

.delete_group(group) ⇒ void

This method returns an undefined value.

Deletes the specified config group from the ini file

Parameters:

  • group (String)

    The name of the group to remove


264
265
266
# File 'lib/msf/base/config.rb', line 264

def self.delete_group(group)
  self.new.delete_group(group)
end

.fav_modules_fileString

Returns the full path to the fav_modules file.

Returns:

  • (String)

    path the fav_modules file.


215
216
217
# File 'lib/msf/base/config.rb', line 215

def self.fav_modules_file
  self.new.fav_modules_file
end

.get_config_rootString

Determines the base configuration directory.

Returns:

  • (String)

    the base configuration directory


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/msf/base/config.rb', line 28

def self.get_config_root

  # Use MSF_CFGROOT_CONFIG environment variable first.
  val = Rex::Compat.getenv('MSF_CFGROOT_CONFIG')
  if (val and File.directory?(val))
    return val
  end

  # XXX Update this when there is a need to break compatibility
  config_dir_major = 4
  config_dir = ".msf#{config_dir_major}"

  # Windows-specific environment variables
  ['HOME', 'LOCALAPPDATA', 'APPDATA', 'USERPROFILE'].each do |dir|
    val = Rex::Compat.getenv(dir)
    if (val and File.directory?(val))
      return File.join(val, config_dir)
    end
  end

  begin
    # First we try $HOME/.msfx
    File.expand_path("~#{FileSep}#{config_dir}")
  rescue ::ArgumentError
    # Give up and install root + ".msfx"
    InstallRoot + config_dir
  end
end

.history_fileString

Returns the full path to the history file.

Returns:

  • (String)

    path the history file.


201
202
203
# File 'lib/msf/base/config.rb', line 201

def self.history_file
  self.new.history_file
end

.initvoid

This method returns an undefined value.

Initializes configuration, creating directories as necessary.


229
230
231
# File 'lib/msf/base/config.rb', line 229

def self.init
  self.new.init
end

.install_rootString

Returns the framework installation root.

Returns:

  • (String)

    the framework installation root InstallRoot.


89
90
91
# File 'lib/msf/base/config.rb', line 89

def self.install_root
  InstallRoot
end

.load(path = nil) ⇒ Rex::Parser::Ini

Loads configuration from the supplied file path, or the default one if none is specified.

Parameters:

  • path (String) (defaults to: nil)

    the path to the configuration file.

Returns:


238
239
240
# File 'lib/msf/base/config.rb', line 238

def self.load(path = nil)
  self.new.load(path)
end

.local_directoryString

Returns the directory in which locally-generated data will reside.

Returns:

  • (String)

    path to locally-generated data directory.


159
160
161
# File 'lib/msf/base/config.rb', line 159

def self.local_directory
  self.new.local_directory
end

.log_directoryString

Returns the directory that log files should be stored in.

Returns:

  • (String)

    path to log directory.


124
125
126
# File 'lib/msf/base/config.rb', line 124

def self.log_directory
  self.new.log_directory
end

.logos_directoryString

Return the directory that logo files should be loaded from.

Returns:

  • (String)

    path to the logos directory.


103
104
105
# File 'lib/msf/base/config.rb', line 103

def self.logos_directory
  self.new.logos_directory
end

.loot_directoryString

Returns the directory in which captured data will reside.

Returns:

  • (String)

    path to loot directory.


152
153
154
# File 'lib/msf/base/config.rb', line 152

def self.loot_directory
  self.new.loot_directory
end

.meterpreter_historyObject


205
206
207
# File 'lib/msf/base/config.rb', line 205

def self.meterpreter_history
  self.new.meterpreter_history
end

.module_directoryString

Returns the global module directory.

Returns:

  • (String)

    path to global module directory.


110
111
112
# File 'lib/msf/base/config.rb', line 110

def self.module_directory
  self.new.module_directory
end

.persist_fileString

Returns the full path to the handler file.

Returns:

  • (String)

    path the handler file.


222
223
224
# File 'lib/msf/base/config.rb', line 222

def self.persist_file
  self.new.persist_file
end

.plugin_directoryString

Returns the directory that plugins are stored in.

Returns:

  • (String)

    path to plugin directory.


131
132
133
# File 'lib/msf/base/config.rb', line 131

def self.plugin_directory
  self.new.plugin_directory
end

.pry_historyObject


209
210
211
# File 'lib/msf/base/config.rb', line 209

def self.pry_history
  self.new.pry_history
end

.save(opts) ⇒ void

This method returns an undefined value.

Saves configuration to the path specified in the ConfigFile hash key or the default path if one isn't specified. The options should be group references that have named value pairs.

Examples:

Save 'Cat' => 'Foo' in group 'ExampleGroup'

save(
  'ExampleGroup' =>
     {
        'Foo' => 'Cat'
     })

Parameters:

  • opts (Hash)

    Hash containing configuration options.

Options Hash (opts):

  • configuration ('ConfigFile'Hash)

    file these options apply to.


256
257
258
# File 'lib/msf/base/config.rb', line 256

def self.save(opts)
  self.new.save(opts)
end

.script_directoryString

Returns the path that scripts can be loaded from.

Returns:

  • (String)

    path to script directory.


117
118
119
# File 'lib/msf/base/config.rb', line 117

def self.script_directory
  self.new.script_directory
end

.session_log_directoryString

Returns the directory in which session log files are to reside.

Returns:

  • (String)

    path to session log directory.


145
146
147
# File 'lib/msf/base/config.rb', line 145

def self.session_log_directory
  self.new.session_log_directory
end

.user_logos_directoryString

Return the user-specific directory that logo files should be loaded from.

Returns:

  • (String)

    path to the logos directory.


166
167
168
# File 'lib/msf/base/config.rb', line 166

def self.user_logos_directory
  self.new.user_logos_directory
end

.user_module_directoryString

Returns the user-specific module base path

Returns:

  • (String)

    path to user-specific modules directory.


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

def self.user_module_directory
  self.new.user_module_directory
end

.user_plugin_directoryString

Returns the user-specific plugin base path

Returns:

  • (String)

    path to user-specific plugin directory.


138
139
140
# File 'lib/msf/base/config.rb', line 138

def self.user_plugin_directory
  self.new.user_plugin_directory
end

.user_script_directoryString

Returns the user-specific script base path

Returns:

  • (String)

    path to user-specific script directory.


180
181
182
# File 'lib/msf/base/config.rb', line 180

def self.user_script_directory
  self.new.user_script_directory
end

Instance Method Details

#config_directoryString

Returns the configuration directory default.

Returns:

  • (String)

    the root configuration directory.


292
293
294
# File 'lib/msf/base/config.rb', line 292

def config_directory
  self['ConfigDirectory']
end

#config_fileString

Returns the full path to the configuration file.

Returns:

  • (String)

    path to the configuration file.


299
300
301
# File 'lib/msf/base/config.rb', line 299

def config_file
  config_directory + FileSep + self['ConfigFile']
end

#data_directoryString

Returns the data directory

Returns:

  • (String)

    path to data directory.


412
413
414
# File 'lib/msf/base/config.rb', line 412

def data_directory
  install_root + FileSep + self['DataDirectory']
end

#delete_group(group) ⇒ void

This method returns an undefined value.

Deletes the specified config group from the ini file

Parameters:

  • group (String)

    The name of the group to remove


468
469
470
471
472
473
474
# File 'lib/msf/base/config.rb', line 468

def delete_group(group)
  ini = Rex::Parser::Ini.new(config_file)

  ini.delete(group)

  ini.to_file
end

#fav_modules_fileString

Returns the full path to the fav_modules file.

Returns:

  • (String)

    path the fav_modules file.


321
322
323
# File 'lib/msf/base/config.rb', line 321

def fav_modules_file
  config_directory + FileSep + "fav_modules"
end

#history_fileString

Returns the full path to the history file.

Returns:

  • (String)

    path the history file.


306
307
308
# File 'lib/msf/base/config.rb', line 306

def history_file
  config_directory + FileSep + "history"
end

#initvoid

This method returns an undefined value.

Initializes configuration, creating directories as necessary.


419
420
421
422
423
424
425
426
427
428
429
# File 'lib/msf/base/config.rb', line 419

def init
  FileUtils.mkdir_p(module_directory)
  FileUtils.mkdir_p(config_directory)
  FileUtils.mkdir_p(log_directory)
  FileUtils.mkdir_p(session_log_directory)
  FileUtils.mkdir_p(loot_directory)
  FileUtils.mkdir_p(local_directory)
  FileUtils.mkdir_p(user_logos_directory)
  FileUtils.mkdir_p(user_module_directory)
  FileUtils.mkdir_p(user_plugin_directory)
end

#install_rootString

Returns the installation root directory

Returns:

  • (String)

    the installation root directory InstallRoot.


278
279
280
# File 'lib/msf/base/config.rb', line 278

def install_root
  InstallRoot
end

#load(path = nil) ⇒ Rex::Parser::Ini

Loads configuration from the supplied file path, or the default one if none is specified.

Parameters:

  • path (String) (defaults to: nil)

    the path to the configuration file.

Returns:


436
437
438
439
440
# File 'lib/msf/base/config.rb', line 436

def load(path = nil)
  path = config_file if (!path)

  return Rex::Parser::Ini.new(path)
end

#local_directoryString

Returns the directory in which locally-generated data will reside.

Returns:

  • (String)

    path to locally-generated data directory.


377
378
379
# File 'lib/msf/base/config.rb', line 377

def local_directory
  config_directory + FileSep + self['LocalDirectory']
end

#log_directoryString

Returns the directory that log files should be stored in.

Returns:

  • (String)

    path to log directory.


349
350
351
# File 'lib/msf/base/config.rb', line 349

def log_directory
  config_directory + FileSep + self['LogDirectory']
end

#logos_directoryString

Return the directory that logo files should be loaded from.

Returns:

  • (String)

    path to the logos directory.


285
286
287
# File 'lib/msf/base/config.rb', line 285

def logos_directory
  data_directory + FileSep + self['LogosDirectory']
end

#loot_directoryString

Returns the directory in which captured data will reside.

Returns:

  • (String)

    path to loot directory.


370
371
372
# File 'lib/msf/base/config.rb', line 370

def loot_directory
  config_directory + FileSep + self['LootDirectory']
end

#meterpreter_historyObject


310
311
312
# File 'lib/msf/base/config.rb', line 310

def meterpreter_history
  config_directory + FileSep + "meterpreter_history"
end

#module_directoryString

Returns the global module directory.

Returns:

  • (String)

    path to global module directory.


335
336
337
# File 'lib/msf/base/config.rb', line 335

def module_directory
  install_root + FileSep + self['ModuleDirectory']
end

#persist_fileString

Returns the full path to the handler file.

Returns:

  • (String)

    path the handler file.


328
329
330
# File 'lib/msf/base/config.rb', line 328

def persist_file
  config_directory + FileSep + "persist"
end

#plugin_directoryString

Returns the directory that plugins are stored in.

Returns:

  • (String)

    path to plugin directory.


356
357
358
# File 'lib/msf/base/config.rb', line 356

def plugin_directory
  install_root + FileSep + self['PluginDirectory']
end

#pry_historyObject


314
315
316
# File 'lib/msf/base/config.rb', line 314

def pry_history
  config_directory + FileSep + "pry_history"
end

#save(opts) ⇒ void

This method returns an undefined value.

Saves configuration to the path specified in the ConfigFile hash key or the default path if one isn't specified. The options should be group references that have named value pairs.

Examples:

Save 'Cat' => 'Foo' in group 'ExampleGroup'

save(
  'ExampleGroup' =>
     {
        'Foo' => 'Cat'
     })

Parameters:

  • opts (Hash)

    Hash containing configuration options.

Options Hash (opts):

  • configuration ('ConfigFile'Hash)

    file these options apply to.


456
457
458
459
460
461
462
# File 'lib/msf/base/config.rb', line 456

def save(opts)
  ini = Rex::Parser::Ini.new(opts['ConfigFile'] || config_file)

  ini.update(opts)

  ini.to_file
end

#script_directoryString

Returns the path that scripts can be loaded from.

Returns:

  • (String)

    path to script directory.


342
343
344
# File 'lib/msf/base/config.rb', line 342

def script_directory
  install_root + FileSep + self['ScriptDirectory']
end

#session_log_directoryString

Returns the directory in which session log files are to reside.

Returns:

  • (String)

    path to session log directory.


363
364
365
# File 'lib/msf/base/config.rb', line 363

def session_log_directory
  config_directory + FileSep + self['SessionLogDirectory']
end

#user_logos_directoryString

Return the user-specific directory that logo files should be loaded from.

Returns:

  • (String)

    path to the logos directory.


384
385
386
# File 'lib/msf/base/config.rb', line 384

def user_logos_directory
  config_directory + FileSep + self['LogosDirectory']
end

#user_module_directoryString

Returns the user-specific module base path

Returns:

  • (String)

    path to user-specific modules directory.


391
392
393
# File 'lib/msf/base/config.rb', line 391

def user_module_directory
  config_directory + FileSep + "modules"
end

#user_plugin_directoryString

Returns the user-specific plugin base path

Returns:

  • (String)

    path to user-specific plugin directory.


398
399
400
# File 'lib/msf/base/config.rb', line 398

def user_plugin_directory
  config_directory + FileSep + "plugins"
end

#user_script_directoryString

Returns the user-specific script base path

Returns:

  • (String)

    path to user-specific script directory.


405
406
407
# File 'lib/msf/base/config.rb', line 405

def user_script_directory
  config_directory + FileSep + "scripts"
end