Browse Source

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.
Luke Imhoff 5 years ago
parent
commit
f696a5ab0e
No account linked to committer's email address

+ 1
- 0
lib/metasploit/framework/command/console.rb View File

@@ -61,6 +61,7 @@ class Metasploit::Framework::Command::Console < Metasploit::Framework::Command::
61 61
       driver_options['DatabaseEnv'] = options.environment
62 62
       driver_options['DatabaseMigrationPaths'] = options.database.migrations_paths
63 63
       driver_options['DatabaseYAML'] = options.database.config
64
+      driver_options['DeferModuleLoads'] = options.modules.defer_loads
64 65
       driver_options['Defanged'] = options.console.defanged
65 66
       driver_options['DisableBanner'] = options.console.quiet
66 67
       driver_options['DisableDatabase'] = options.database.disable

+ 8
- 0
lib/metasploit/framework/parsed_options/base.rb View File

@@ -85,6 +85,7 @@ class Metasploit::Framework::ParsedOptions::Base
85 85
       options.framework.config = nil
86 86
 
87 87
       options.modules = ActiveSupport::OrderedOptions.new
88
+      options.modules.defer_loads = false
88 89
       options.modules.path = nil
89 90
 
90 91
       @options = options
@@ -155,6 +156,13 @@ class Metasploit::Framework::ParsedOptions::Base
155 156
       option_parser.separator ''
156 157
       option_parser.separator 'Module options'
157 158
 
159
+      option_parser.on(
160
+          '--defer-module-loads',
161
+          'Defer module loading unless explicitly asked.'
162
+      ) do
163
+        options.modules.defer_loads = true
164
+      end
165
+
158 166
       option_parser.on(
159 167
           '-m',
160 168
           '--module-path DIRECTORY',

+ 8
- 6
lib/msf/ui/console/driver.rb View File

@@ -61,7 +61,7 @@ class Driver < Msf::Ui::Driver
61 61
     # Initialize attributes
62 62
 
63 63
     # Defer loading of modules until paths from opts can be added below
64
-    framework_create_options = {'DeferModuleLoads' => true}.merge(opts)
64
+    framework_create_options = opts.merge('DeferModuleLoads' => true)
65 65
     self.framework = opts['Framework'] || Msf::Simple::Framework.create(framework_create_options)
66 66
 
67 67
     if self.framework.datastore['Prompt']
@@ -187,10 +187,12 @@ class Driver < Msf::Ui::Driver
187 187
       # framework.db.active will be true if after_establish_connection ran directly when connection_established? was
188 188
       # already true or if framework.db.connect called after_establish_connection.
189 189
       if framework.db.active
190
-        self.framework.modules.refresh_cache_from_database
190
+        unless opts['DeferModuleLoads']
191
+          self.framework.modules.refresh_cache_from_database
191 192
 
192
-        if self.framework.modules.cache_empty?
193
-          print_status("The initial module cache will be built in the background, this can take 2-5 minutes...")
193
+          if self.framework.modules.cache_empty?
194
+            print_status("The initial module cache will be built in the background, this can take 2-5 minutes...")
195
+          end
194 196
         end
195 197
       elsif !framework.db.error.nil?
196 198
         if framework.db.error.to_s =~ /RubyGem version.*pg.*0\.11/i
@@ -212,8 +214,8 @@ class Driver < Msf::Ui::Driver
212 214
       end
213 215
     end
214 216
 
215
-    # Initialize the module paths only if we didn't get passed a Framework instance
216
-    unless opts['Framework']
217
+    # Initialize the module paths only if we didn't get passed a Framework instance and 'DeferModuleLoads' is false
218
+    unless opts['Framework'] || opts['DeferModuleLoads']
217 219
       # Configure the framework module paths
218 220
       self.framework.init_module_paths
219 221
       self.framework.modules.add_module_path(opts['ModulePath']) if opts['ModulePath']

Loading…
Cancel
Save