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", 'HistoriesDirectory' => "histories" }
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.
-
.histories_directory ⇒ String
Returns the histories directory default.
-
.history_file ⇒ String
Returns the full path to the history file.
-
.history_file_for_session_type(opts) ⇒ String
Returns the full path to the MySQL interactive query history file.
-
.init ⇒ void
Initializes configuration, creating directories as necessary.
-
.install_root ⇒ String
Returns the framework installation root.
-
.ldap_session_history ⇒ String
Returns the full path to the ldap session history file.
-
.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.
-
.persist_file ⇒ String
Returns the full path to the handler file.
-
.plugin_directory ⇒ String
Returns the directory that plugins are stored in.
- .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.
-
#histories_directory ⇒ String
Returns the histories directory default.
-
#history_file ⇒ String
Returns the full path to the history file.
- #history_file_for_session_type(opts) ⇒ Object
- #history_options_valid?(opts) ⇒ Boolean
-
#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.
- #interactive_to_string_map(interactive) ⇒ Object
- #ldap_session_history ⇒ Object
-
#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.
-
#persist_file ⇒ String
Returns the full path to the handler file.
-
#plugin_directory ⇒ String
Returns the directory that plugins are stored in.
- #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.
308 309 310 |
# File 'lib/msf/base/config.rb', line 308 def initialize update(Defaults) end |
Class Method Details
.config_directory ⇒ String
Returns the configuration directory default.
97 98 99 |
# File 'lib/msf/base/config.rb', line 97 def self.config_directory self.new.config_directory end |
.config_file ⇒ String
Returns the full path to the configuration file.
207 208 209 |
# File 'lib/msf/base/config.rb', line 207 def self.config_file self.new.config_file end |
.data_directory ⇒ String
Returns the data directory
200 201 202 |
# File 'lib/msf/base/config.rb', line 200 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
301 302 303 |
# File 'lib/msf/base/config.rb', line 301 def self.delete_group(group) self.new.delete_group(group) end |
.fav_modules_file ⇒ String
Returns the full path to the fav_modules file.
252 253 254 |
# File 'lib/msf/base/config.rb', line 252 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 |
.histories_directory ⇒ String
Returns the histories directory default.
104 105 106 |
# File 'lib/msf/base/config.rb', line 104 def self.histories_directory self.new.histories_directory end |
.history_file ⇒ String
Returns the full path to the history file.
214 215 216 |
# File 'lib/msf/base/config.rb', line 214 def self.history_file self.new.history_file end |
.history_file_for_session_type(opts) ⇒ String
Returns the full path to the MySQL interactive query history file
242 243 244 |
# File 'lib/msf/base/config.rb', line 242 def self.history_file_for_session_type(opts) self.new.history_file_for_session_type(opts) end |
.init ⇒ void
This method returns an undefined value.
Initializes configuration, creating directories as necessary.
266 267 268 |
# File 'lib/msf/base/config.rb', line 266 def self.init self.new.init end |
.install_root ⇒ String
Returns the framework installation root.
90 91 92 |
# File 'lib/msf/base/config.rb', line 90 def self.install_root InstallRoot end |
.ldap_session_history ⇒ String
Returns the full path to the ldap session history file.
235 236 237 |
# File 'lib/msf/base/config.rb', line 235 def self.ldap_session_history self.new.ldap_session_history end |
.load(path = nil) ⇒ Rex::Parser::Ini
Loads configuration from the supplied file path, or the default one if none is specified.
275 276 277 |
# File 'lib/msf/base/config.rb', line 275 def self.load(path = nil) self.new.load(path) end |
.local_directory ⇒ String
Returns the directory in which locally-generated data will reside.
167 168 169 |
# File 'lib/msf/base/config.rb', line 167 def self.local_directory self.new.local_directory end |
.log_directory ⇒ String
Returns the directory that log files should be stored in.
132 133 134 |
# File 'lib/msf/base/config.rb', line 132 def self.log_directory self.new.log_directory end |
.logos_directory ⇒ String
Return the directory that logo files should be loaded from.
111 112 113 |
# File 'lib/msf/base/config.rb', line 111 def self.logos_directory self.new.logos_directory end |
.loot_directory ⇒ String
Returns the directory in which captured data will reside.
160 161 162 |
# File 'lib/msf/base/config.rb', line 160 def self.loot_directory self.new.loot_directory end |
.meterpreter_history ⇒ String
Returns the full path to the meterpreter history file.
221 222 223 |
# File 'lib/msf/base/config.rb', line 221 def self.meterpreter_history self.new.meterpreter_history end |
.module_directory ⇒ String
Returns the global module directory.
118 119 120 |
# File 'lib/msf/base/config.rb', line 118 def self.module_directory self.new.module_directory end |
.persist_file ⇒ String
Returns the full path to the handler file.
259 260 261 |
# File 'lib/msf/base/config.rb', line 259 def self.persist_file self.new.persist_file end |
.plugin_directory ⇒ String
Returns the directory that plugins are stored in.
139 140 141 |
# File 'lib/msf/base/config.rb', line 139 def self.plugin_directory self.new.plugin_directory end |
.pry_history ⇒ Object
246 247 248 |
# File 'lib/msf/base/config.rb', line 246 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.
293 294 295 |
# File 'lib/msf/base/config.rb', line 293 def self.save(opts) self.new.save(opts) end |
.script_directory ⇒ String
Returns the path that scripts can be loaded from.
125 126 127 |
# File 'lib/msf/base/config.rb', line 125 def self.script_directory self.new.script_directory end |
.session_log_directory ⇒ String
Returns the directory in which session log files are to reside.
153 154 155 |
# File 'lib/msf/base/config.rb', line 153 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.
228 229 230 |
# File 'lib/msf/base/config.rb', line 228 def self.smb_session_history self.new.smb_session_history end |
.user_data_directory ⇒ String
Returns path to user-specific data directory.
193 194 195 |
# File 'lib/msf/base/config.rb', line 193 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.
174 175 176 |
# File 'lib/msf/base/config.rb', line 174 def self.user_logos_directory self.new.user_logos_directory end |
.user_module_directory ⇒ String
Returns the user-specific module base path
181 182 183 |
# File 'lib/msf/base/config.rb', line 181 def self.user_module_directory self.new.user_module_directory end |
.user_plugin_directory ⇒ String
Returns the user-specific plugin base path
146 147 148 |
# File 'lib/msf/base/config.rb', line 146 def self.user_plugin_directory self.new.user_plugin_directory end |
.user_script_directory ⇒ String
Returns the user-specific script base path
188 189 190 |
# File 'lib/msf/base/config.rb', line 188 def self.user_script_directory self.new.user_script_directory end |
Instance Method Details
#config_directory ⇒ String
Returns the configuration directory default.
329 330 331 |
# File 'lib/msf/base/config.rb', line 329 def config_directory self['ConfigDirectory'] end |
#config_file ⇒ String
Returns the full path to the configuration file.
343 344 345 |
# File 'lib/msf/base/config.rb', line 343 def config_file config_directory + FileSep + self['ConfigFile'] end |
#data_directory ⇒ String
Returns the data directory
489 490 491 |
# File 'lib/msf/base/config.rb', line 489 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
547 548 549 550 551 552 553 |
# File 'lib/msf/base/config.rb', line 547 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.
393 394 395 |
# File 'lib/msf/base/config.rb', line 393 def fav_modules_file config_directory + FileSep + "fav_modules" end |
#histories_directory ⇒ String
Returns the histories directory default.
336 337 338 |
# File 'lib/msf/base/config.rb', line 336 def histories_directory config_directory + FileSep + self['HistoriesDirectory'] end |
#history_file ⇒ String
Returns the full path to the history file.
350 351 352 |
# File 'lib/msf/base/config.rb', line 350 def history_file config_directory + FileSep + "history" end |
#history_file_for_session_type(opts) ⇒ Object
377 378 379 380 381 382 383 384 |
# File 'lib/msf/base/config.rb', line 377 def history_file_for_session_type(opts) return nil unless (opts) session_type_name = opts[:session_type] interactive = interactive_to_string_map(opts[:interactive]) histories_directory + FileSep + "#{session_type_name}_session#{interactive}_history" end |
#history_options_valid?(opts) ⇒ Boolean
366 367 368 369 370 |
# File 'lib/msf/base/config.rb', line 366 def (opts) return false if (opts[:session_type].nil? || opts[:interactive].nil?) true end |
#init ⇒ void
This method returns an undefined value.
Initializes configuration, creating directories as necessary.
496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/msf/base/config.rb', line 496 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) FileUtils.mkdir_p(histories_directory) end |
#install_root ⇒ String
Returns the installation root directory
315 316 317 |
# File 'lib/msf/base/config.rb', line 315 def install_root InstallRoot end |
#interactive_to_string_map(interactive) ⇒ Object
372 373 374 375 |
# File 'lib/msf/base/config.rb', line 372 def interactive_to_string_map(interactive) # Check for true explicitly rather than just a value that is truthy. interactive == true ? '_interactive' : '' end |
#ldap_session_history ⇒ Object
362 363 364 |
# File 'lib/msf/base/config.rb', line 362 def ldap_session_history config_directory + FileSep + "ldap_session_history" end |
#load(path = nil) ⇒ Rex::Parser::Ini
Loads configuration from the supplied file path, or the default one if none is specified.
515 516 517 518 519 |
# File 'lib/msf/base/config.rb', line 515 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.
449 450 451 |
# File 'lib/msf/base/config.rb', line 449 def local_directory config_directory + FileSep + self['LocalDirectory'] end |
#log_directory ⇒ String
Returns the directory that log files should be stored in.
421 422 423 |
# File 'lib/msf/base/config.rb', line 421 def log_directory config_directory + FileSep + self['LogDirectory'] end |
#logos_directory ⇒ String
Return the directory that logo files should be loaded from.
322 323 324 |
# File 'lib/msf/base/config.rb', line 322 def logos_directory data_directory + FileSep + self['LogosDirectory'] end |
#loot_directory ⇒ String
Returns the directory in which captured data will reside.
442 443 444 |
# File 'lib/msf/base/config.rb', line 442 def loot_directory config_directory + FileSep + self['LootDirectory'] end |
#meterpreter_history ⇒ Object
354 355 356 |
# File 'lib/msf/base/config.rb', line 354 def meterpreter_history config_directory + FileSep + "meterpreter_history" end |
#module_directory ⇒ String
Returns the global module directory.
407 408 409 |
# File 'lib/msf/base/config.rb', line 407 def module_directory install_root + FileSep + self['ModuleDirectory'] end |
#persist_file ⇒ String
Returns the full path to the handler file.
400 401 402 |
# File 'lib/msf/base/config.rb', line 400 def persist_file config_directory + FileSep + "persist" end |
#plugin_directory ⇒ String
Returns the directory that plugins are stored in.
428 429 430 |
# File 'lib/msf/base/config.rb', line 428 def plugin_directory install_root + FileSep + self['PluginDirectory'] end |
#pry_history ⇒ Object
386 387 388 |
# File 'lib/msf/base/config.rb', line 386 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.
535 536 537 538 539 540 541 |
# File 'lib/msf/base/config.rb', line 535 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.
414 415 416 |
# File 'lib/msf/base/config.rb', line 414 def script_directory install_root + FileSep + self['ScriptDirectory'] end |
#session_log_directory ⇒ String
Returns the directory in which session log files are to reside.
435 436 437 |
# File 'lib/msf/base/config.rb', line 435 def session_log_directory config_directory + FileSep + self['SessionLogDirectory'] end |
#smb_session_history ⇒ Object
358 359 360 |
# File 'lib/msf/base/config.rb', line 358 def smb_session_history config_directory + FileSep + "smb_session_history" end |
#user_data_directory ⇒ String
Returns path to user-specific data directory.
482 483 484 |
# File 'lib/msf/base/config.rb', line 482 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.
456 457 458 |
# File 'lib/msf/base/config.rb', line 456 def user_logos_directory config_directory + FileSep + self['LogosDirectory'] end |
#user_module_directory ⇒ String
Returns the user-specific module base path
463 464 465 |
# File 'lib/msf/base/config.rb', line 463 def user_module_directory config_directory + FileSep + "modules" end |
#user_plugin_directory ⇒ String
Returns the user-specific plugin base path
470 471 472 |
# File 'lib/msf/base/config.rb', line 470 def user_plugin_directory config_directory + FileSep + "plugins" end |
#user_script_directory ⇒ String
Returns the user-specific script base path
477 478 479 |
# File 'lib/msf/base/config.rb', line 477 def user_script_directory config_directory + FileSep + "scripts" end |