msfconsole --defer-module-loads
MSP-11671 Add command line option --defer-module-loads to msfconsole. It will stop `Msf::Ui::Console::Driver` from calling `framework.modules.init_module_paths` AND `framework.modules.refresh_cache_from_database`. This flag is only meant to speed up msfconsole boot when modules do not need to accessed, such as during cucumber testing of command help or command line options.bug/bundler_fix
parent
35ff82c9d8
commit
f696a5ab0e
|
@ -61,6 +61,7 @@ class Metasploit::Framework::Command::Console < Metasploit::Framework::Command::
|
|||
driver_options['DatabaseEnv'] = options.environment
|
||||
driver_options['DatabaseMigrationPaths'] = options.database.migrations_paths
|
||||
driver_options['DatabaseYAML'] = options.database.config
|
||||
driver_options['DeferModuleLoads'] = options.modules.defer_loads
|
||||
driver_options['Defanged'] = options.console.defanged
|
||||
driver_options['DisableBanner'] = options.console.quiet
|
||||
driver_options['DisableDatabase'] = options.database.disable
|
||||
|
|
|
@ -85,6 +85,7 @@ class Metasploit::Framework::ParsedOptions::Base
|
|||
options.framework.config = nil
|
||||
|
||||
options.modules = ActiveSupport::OrderedOptions.new
|
||||
options.modules.defer_loads = false
|
||||
options.modules.path = nil
|
||||
|
||||
@options = options
|
||||
|
@ -155,6 +156,13 @@ class Metasploit::Framework::ParsedOptions::Base
|
|||
option_parser.separator ''
|
||||
option_parser.separator 'Module options'
|
||||
|
||||
option_parser.on(
|
||||
'--defer-module-loads',
|
||||
'Defer module loading unless explicitly asked.'
|
||||
) do
|
||||
options.modules.defer_loads = true
|
||||
end
|
||||
|
||||
option_parser.on(
|
||||
'-m',
|
||||
'--module-path DIRECTORY',
|
||||
|
|
|
@ -61,7 +61,7 @@ class Driver < Msf::Ui::Driver
|
|||
# Initialize attributes
|
||||
|
||||
# Defer loading of modules until paths from opts can be added below
|
||||
framework_create_options = {'DeferModuleLoads' => true}.merge(opts)
|
||||
framework_create_options = opts.merge('DeferModuleLoads' => true)
|
||||
self.framework = opts['Framework'] || Msf::Simple::Framework.create(framework_create_options)
|
||||
|
||||
if self.framework.datastore['Prompt']
|
||||
|
@ -187,10 +187,12 @@ class Driver < Msf::Ui::Driver
|
|||
# framework.db.active will be true if after_establish_connection ran directly when connection_established? was
|
||||
# already true or if framework.db.connect called after_establish_connection.
|
||||
if framework.db.active
|
||||
self.framework.modules.refresh_cache_from_database
|
||||
unless opts['DeferModuleLoads']
|
||||
self.framework.modules.refresh_cache_from_database
|
||||
|
||||
if self.framework.modules.cache_empty?
|
||||
print_status("The initial module cache will be built in the background, this can take 2-5 minutes...")
|
||||
if self.framework.modules.cache_empty?
|
||||
print_status("The initial module cache will be built in the background, this can take 2-5 minutes...")
|
||||
end
|
||||
end
|
||||
elsif !framework.db.error.nil?
|
||||
if framework.db.error.to_s =~ /RubyGem version.*pg.*0\.11/i
|
||||
|
@ -212,8 +214,8 @@ class Driver < Msf::Ui::Driver
|
|||
end
|
||||
end
|
||||
|
||||
# Initialize the module paths only if we didn't get passed a Framework instance
|
||||
unless opts['Framework']
|
||||
# Initialize the module paths only if we didn't get passed a Framework instance and 'DeferModuleLoads' is false
|
||||
unless opts['Framework'] || opts['DeferModuleLoads']
|
||||
# Configure the framework module paths
|
||||
self.framework.init_module_paths
|
||||
self.framework.modules.add_module_path(opts['ModulePath']) if opts['ModulePath']
|
||||
|
|
Loading…
Reference in New Issue