Class: Msf::Config
- Inherits:
-
Hash
- Object
- Hash
- Msf::Config
- 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.(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
-
.config_directory ⇒ String
Returns the configuration directory default.
-
.config_file ⇒ String
Returns the full path to the configuration file.
-
.data_directory ⇒ String
Returns the data directory.
-
.delete_group(group) ⇒ void
Deletes the specified config group from the ini file.
-
.fav_modules_file ⇒ String
Returns the full path to the fav_modules file.
-
.get_config_root ⇒ String
Determines the base configuration directory.
-
.history_file ⇒ String
Returns the full path to the history file.
-
.init ⇒ void
Initializes configuration, creating directories as necessary.
-
.install_root ⇒ String
Returns the framework installation root.
-
.load(path = nil) ⇒ Rex::Parser::Ini
Loads configuration from the supplied file path, or the default one if none is specified.
-
.local_directory ⇒ String
Returns the directory in which locally-generated data will reside.
-
.log_directory ⇒ String
Returns the directory that log files should be stored in.
-
.logos_directory ⇒ String
Return the directory that logo files should be loaded from.
-
.loot_directory ⇒ String
Returns the directory in which captured data will reside.
-
.meterpreter_history ⇒ String
Returns the full path to the meterpreter history file.
-
.module_directory ⇒ String
Returns the global module directory.
-
.mssql_session_history ⇒ String
Returns the full path to the MSSQL session history file.
-
.mysql_session_history ⇒ String
Returns the full path to the MySQL session history file.
-
.persist_file ⇒ String
Returns the full path to the handler file.
-
.plugin_directory ⇒ String
Returns the directory that plugins are stored in.
-
.postgresql_session_history ⇒ String
Returns the full path to the PostgreSQL session history file.
- .pry_history ⇒ Object
-
.save(opts) ⇒ void
Saves configuration to the path specified in the ConfigFile hash key or the default path if one isn't specified.
-
.script_directory ⇒ String
Returns the path that scripts can be loaded from.
-
.session_log_directory ⇒ String
Returns the directory in which session log files are to reside.
-
.smb_session_history ⇒ String
Returns the full path to the smb session history file.
-
.user_data_directory ⇒ String
Path to user-specific data directory.
-
.user_logos_directory ⇒ String
Return the user-specific directory that logo files should be loaded from.
-
.user_module_directory ⇒ String
Returns the user-specific module base path.
-
.user_plugin_directory ⇒ String
Returns the user-specific plugin base path.
-
.user_script_directory ⇒ String
Returns the user-specific script base path.
Instance Method Summary collapse
-
#config_directory ⇒ String
Returns the configuration directory default.
-
#config_file ⇒ String
Returns the full path to the configuration file.
-
#data_directory ⇒ String
Returns the data directory.
-
#delete_group(group) ⇒ void
Deletes the specified config group from the ini file.
-
#fav_modules_file ⇒ String
Returns the full path to the fav_modules file.
-
#history_file ⇒ String
Returns the full path to the history file.
-
#init ⇒ void
Initializes configuration, creating directories as necessary.
-
#initialize ⇒ Hash
constructor
Updates the config class' self with the default hash.
-
#install_root ⇒ String
Returns the installation root directory.
-
#load(path = nil) ⇒ Rex::Parser::Ini
Loads configuration from the supplied file path, or the default one if none is specified.
-
#local_directory ⇒ String
Returns the directory in which locally-generated data will reside.
-
#log_directory ⇒ String
Returns the directory that log files should be stored in.
-
#logos_directory ⇒ String
Return the directory that logo files should be loaded from.
-
#loot_directory ⇒ String
Returns the directory in which captured data will reside.
- #meterpreter_history ⇒ Object
-
#module_directory ⇒ String
Returns the global module directory.
- #mssql_session_history ⇒ Object
- #mysql_session_history ⇒ Object
-
#persist_file ⇒ String
Returns the full path to the handler file.
-
#plugin_directory ⇒ String
Returns the directory that plugins are stored in.
- #postgresql_session_history ⇒ Object
- #pry_history ⇒ Object
-
#save(opts) ⇒ void
Saves configuration to the path specified in the ConfigFile hash key or the default path if one isn't specified.
-
#script_directory ⇒ String
Returns the path that scripts can be loaded from.
-
#session_log_directory ⇒ String
Returns the directory in which session log files are to reside.
- #smb_session_history ⇒ Object
-
#user_data_directory ⇒ String
Path to user-specific data directory.
-
#user_logos_directory ⇒ String
Return the user-specific directory that logo files should be loaded from.
-
#user_module_directory ⇒ String
Returns the user-specific module base path.
-
#user_plugin_directory ⇒ String
Returns the user-specific plugin base path.
-
#user_script_directory ⇒ String
Returns the user-specific script base path.
Constructor Details
#initialize ⇒ Hash
Updates the config class' self with the default hash.
307 308 309 |
# File 'lib/msf/base/config.rb', line 307 def initialize update(Defaults) end |
Class Method Details
.config_directory ⇒ String
Returns the configuration directory default.
96 97 98 |
# File 'lib/msf/base/config.rb', line 96 def self.config_directory self.new.config_directory end |
.config_file ⇒ String
Returns the full path to the configuration file.
199 200 201 |
# File 'lib/msf/base/config.rb', line 199 def self.config_file self.new.config_file end |
.data_directory ⇒ String
Returns the data directory
192 193 194 |
# File 'lib/msf/base/config.rb', line 192 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
300 301 302 |
# File 'lib/msf/base/config.rb', line 300 def self.delete_group(group) self.new.delete_group(group) end |
.fav_modules_file ⇒ String
Returns the full path to the fav_modules file.
251 252 253 |
# File 'lib/msf/base/config.rb', line 251 def self.fav_modules_file self.new.fav_modules_file end |
.get_config_root ⇒ String
Determines the base configuration directory. This method should be considered `private`.
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.("~#{FileSep}#{config_dir}") rescue ::ArgumentError # Give up and install root + ".msfx" InstallRoot + config_dir end end |
.history_file ⇒ String
Returns the full path to the history file.
206 207 208 |
# File 'lib/msf/base/config.rb', line 206 def self.history_file self.new.history_file end |
.init ⇒ void
This method returns an undefined value.
Initializes configuration, creating directories as necessary.
265 266 267 |
# File 'lib/msf/base/config.rb', line 265 def self.init self.new.init end |
.install_root ⇒ String
Returns the framework installation root.
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.
274 275 276 |
# File 'lib/msf/base/config.rb', line 274 def self.load(path = nil) self.new.load(path) end |
.local_directory ⇒ String
Returns the directory in which locally-generated data will reside.
159 160 161 |
# File 'lib/msf/base/config.rb', line 159 def self.local_directory self.new.local_directory end |
.log_directory ⇒ String
Returns the directory that log files should be stored in.
124 125 126 |
# File 'lib/msf/base/config.rb', line 124 def self.log_directory self.new.log_directory end |
.logos_directory ⇒ String
Return the directory that logo files should be loaded from.
103 104 105 |
# File 'lib/msf/base/config.rb', line 103 def self.logos_directory self.new.logos_directory end |
.loot_directory ⇒ String
Returns the directory in which captured data will reside.
152 153 154 |
# File 'lib/msf/base/config.rb', line 152 def self.loot_directory self.new.loot_directory end |
.meterpreter_history ⇒ String
Returns the full path to the meterpreter history file.
213 214 215 |
# File 'lib/msf/base/config.rb', line 213 def self.meterpreter_history self.new.meterpreter_history end |
.module_directory ⇒ String
Returns the global module directory.
110 111 112 |
# File 'lib/msf/base/config.rb', line 110 def self.module_directory self.new.module_directory end |
.mssql_session_history ⇒ String
Returns the full path to the MSSQL session history file.
234 235 236 |
# File 'lib/msf/base/config.rb', line 234 def self.mssql_session_history self.new.mssql_session_history end |
.mysql_session_history ⇒ String
Returns the full path to the MySQL session history file.
241 242 243 |
# File 'lib/msf/base/config.rb', line 241 def self.mysql_session_history self.new.mysql_session_history end |
.persist_file ⇒ String
Returns the full path to the handler file.
258 259 260 |
# File 'lib/msf/base/config.rb', line 258 def self.persist_file self.new.persist_file end |
.plugin_directory ⇒ String
Returns the directory that plugins are stored in.
131 132 133 |
# File 'lib/msf/base/config.rb', line 131 def self.plugin_directory self.new.plugin_directory end |
.postgresql_session_history ⇒ String
Returns the full path to the PostgreSQL session history file.
227 228 229 |
# File 'lib/msf/base/config.rb', line 227 def self.postgresql_session_history self.new.postgresql_session_history end |
.pry_history ⇒ Object
245 246 247 |
# File 'lib/msf/base/config.rb', line 245 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.
292 293 294 |
# File 'lib/msf/base/config.rb', line 292 def self.save(opts) self.new.save(opts) end |
.script_directory ⇒ String
Returns the path that scripts can be loaded from.
117 118 119 |
# File 'lib/msf/base/config.rb', line 117 def self.script_directory self.new.script_directory end |
.session_log_directory ⇒ String
Returns the directory in which session log files are to reside.
145 146 147 |
# File 'lib/msf/base/config.rb', line 145 def self.session_log_directory self.new.session_log_directory end |
.smb_session_history ⇒ String
Returns the full path to the smb session history file.
220 221 222 |
# File 'lib/msf/base/config.rb', line 220 def self.smb_session_history self.new.smb_session_history end |
.user_data_directory ⇒ String
Returns path to user-specific data directory.
185 186 187 |
# File 'lib/msf/base/config.rb', line 185 def self.user_data_directory self.new.user_data_directory end |
.user_logos_directory ⇒ String
Return the user-specific directory that logo files should be loaded from.
166 167 168 |
# File 'lib/msf/base/config.rb', line 166 def self.user_logos_directory self.new.user_logos_directory end |
.user_module_directory ⇒ String
Returns the user-specific module base path
173 174 175 |
# File 'lib/msf/base/config.rb', line 173 def self.user_module_directory self.new.user_module_directory end |
.user_plugin_directory ⇒ String
Returns the user-specific plugin base path
138 139 140 |
# File 'lib/msf/base/config.rb', line 138 def self.user_plugin_directory self.new.user_plugin_directory end |
.user_script_directory ⇒ String
Returns the user-specific script base path
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_directory ⇒ String
Returns the configuration directory default.
328 329 330 |
# File 'lib/msf/base/config.rb', line 328 def config_directory self['ConfigDirectory'] end |
#config_file ⇒ String
Returns the full path to the configuration file.
335 336 337 |
# File 'lib/msf/base/config.rb', line 335 def config_file config_directory + FileSep + self['ConfigFile'] end |
#data_directory ⇒ String
Returns the data directory
469 470 471 |
# File 'lib/msf/base/config.rb', line 469 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
526 527 528 529 530 531 532 |
# File 'lib/msf/base/config.rb', line 526 def delete_group(group) ini = Rex::Parser::Ini.new(config_file) ini.delete(group) ini.to_file end |
#fav_modules_file ⇒ String
Returns the full path to the fav_modules file.
373 374 375 |
# File 'lib/msf/base/config.rb', line 373 def fav_modules_file config_directory + FileSep + "fav_modules" end |
#history_file ⇒ String
Returns the full path to the history file.
342 343 344 |
# File 'lib/msf/base/config.rb', line 342 def history_file config_directory + FileSep + "history" end |
#init ⇒ void
This method returns an undefined value.
Initializes configuration, creating directories as necessary.
476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/msf/base/config.rb', line 476 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) FileUtils.mkdir_p(user_data_directory) end |
#install_root ⇒ String
Returns the installation root directory
314 315 316 |
# File 'lib/msf/base/config.rb', line 314 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.
494 495 496 497 498 |
# File 'lib/msf/base/config.rb', line 494 def load(path = nil) path = config_file if (!path) return Rex::Parser::Ini.new(path) end |
#local_directory ⇒ String
Returns the directory in which locally-generated data will reside.
429 430 431 |
# File 'lib/msf/base/config.rb', line 429 def local_directory config_directory + FileSep + self['LocalDirectory'] end |
#log_directory ⇒ String
Returns the directory that log files should be stored in.
401 402 403 |
# File 'lib/msf/base/config.rb', line 401 def log_directory config_directory + FileSep + self['LogDirectory'] end |
#logos_directory ⇒ String
Return the directory that logo files should be loaded from.
321 322 323 |
# File 'lib/msf/base/config.rb', line 321 def logos_directory data_directory + FileSep + self['LogosDirectory'] end |
#loot_directory ⇒ String
Returns the directory in which captured data will reside.
422 423 424 |
# File 'lib/msf/base/config.rb', line 422 def loot_directory config_directory + FileSep + self['LootDirectory'] end |
#meterpreter_history ⇒ Object
346 347 348 |
# File 'lib/msf/base/config.rb', line 346 def meterpreter_history config_directory + FileSep + "meterpreter_history" end |
#module_directory ⇒ String
Returns the global module directory.
387 388 389 |
# File 'lib/msf/base/config.rb', line 387 def module_directory install_root + FileSep + self['ModuleDirectory'] end |
#mssql_session_history ⇒ Object
362 363 364 |
# File 'lib/msf/base/config.rb', line 362 def mssql_session_history config_directory + FileSep + "mssql_session_history" end |
#mysql_session_history ⇒ Object
358 359 360 |
# File 'lib/msf/base/config.rb', line 358 def mysql_session_history config_directory + FileSep + "mysql_session_history" end |
#persist_file ⇒ String
Returns the full path to the handler file.
380 381 382 |
# File 'lib/msf/base/config.rb', line 380 def persist_file config_directory + FileSep + "persist" end |
#plugin_directory ⇒ String
Returns the directory that plugins are stored in.
408 409 410 |
# File 'lib/msf/base/config.rb', line 408 def plugin_directory install_root + FileSep + self['PluginDirectory'] end |
#postgresql_session_history ⇒ Object
354 355 356 |
# File 'lib/msf/base/config.rb', line 354 def postgresql_session_history config_directory + FileSep + "postgresql_session_history" end |
#pry_history ⇒ Object
366 367 368 |
# File 'lib/msf/base/config.rb', line 366 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.
514 515 516 517 518 519 520 |
# File 'lib/msf/base/config.rb', line 514 def save(opts) ini = Rex::Parser::Ini.new(opts['ConfigFile'] || config_file) ini.update(opts) ini.to_file end |
#script_directory ⇒ String
Returns the path that scripts can be loaded from.
394 395 396 |
# File 'lib/msf/base/config.rb', line 394 def script_directory install_root + FileSep + self['ScriptDirectory'] end |
#session_log_directory ⇒ String
Returns the directory in which session log files are to reside.
415 416 417 |
# File 'lib/msf/base/config.rb', line 415 def session_log_directory config_directory + FileSep + self['SessionLogDirectory'] end |
#smb_session_history ⇒ Object
350 351 352 |
# File 'lib/msf/base/config.rb', line 350 def smb_session_history config_directory + FileSep + "smb_session_history" end |
#user_data_directory ⇒ String
Returns path to user-specific data directory.
462 463 464 |
# File 'lib/msf/base/config.rb', line 462 def user_data_directory config_directory + FileSep + self['DataDirectory'] end |
#user_logos_directory ⇒ String
Return the user-specific directory that logo files should be loaded from.
436 437 438 |
# File 'lib/msf/base/config.rb', line 436 def user_logos_directory config_directory + FileSep + self['LogosDirectory'] end |
#user_module_directory ⇒ String
Returns the user-specific module base path
443 444 445 |
# File 'lib/msf/base/config.rb', line 443 def user_module_directory config_directory + FileSep + "modules" end |
#user_plugin_directory ⇒ String
Returns the user-specific plugin base path
450 451 452 |
# File 'lib/msf/base/config.rb', line 450 def user_plugin_directory config_directory + FileSep + "plugins" end |
#user_script_directory ⇒ String
Returns the user-specific script base path
457 458 459 |
# File 'lib/msf/base/config.rb', line 457 def user_script_directory config_directory + FileSep + "scripts" end |