Browse Source

show load warnings to the user

Christian Mehlmauer 4 years ago
parent
commit
8f4752d11e

+ 1
- 0
lib/msf/core/module_manager.rb View File

@@ -120,6 +120,7 @@ module Msf
120 120
       self.module_info_by_path = {}
121 121
       self.enablement_by_type = {}
122 122
       self.module_load_error_by_path = {}
123
+      self.module_load_warnings = {}
123 124
       self.module_paths = []
124 125
       self.module_set_by_type = {}
125 126
 

+ 1
- 1
lib/msf/core/module_manager/loading.rb View File

@@ -50,7 +50,7 @@ module Msf::ModuleManager::Loading
50 50
     changed
51 51
   end
52 52
 
53
-  attr_accessor :module_load_error_by_path
53
+  attr_accessor :module_load_error_by_path, :module_load_warnings
54 54
 
55 55
   # Called when a module is initially loaded such that it can be categorized
56 56
   # accordingly.

+ 19
- 10
lib/msf/core/modules/loader/base.rb View File

@@ -150,18 +150,10 @@ class Msf::Modules::Loader::Base
150 150
 
151 151
       if namespace_module.const_defined?('Metasploit3')
152 152
         klass = namespace_module.const_get('Metasploit3')
153
-        load_error(module_path, Msf::Modules::Error.new({
154
-          :module_path => module_path,
155
-          :module_reference_name => module_reference_name,
156
-          :causal_message => 'Please change the module class name to Metasploit'
157
-        }))
153
+        load_warning(module_path, 'Please change the modules class name from Metasploit3 to Metasploit')
158 154
       elsif namespace_module.const_defined?('Metasploit4')
159 155
         klass = namespace_module.const_get('Metasploit4')
160
-        load_error(module_path, Msf::Modules::Error.new({
161
-          :module_path => module_path,
162
-          :module_reference_name => module_reference_name,
163
-          :causal_message => 'Please change the module class name to Metasploit'
164
-        }))
156
+        load_warning(module_path, 'Please change the modules class name from Metasploit4 to Metasploit')
165 157
       elsif namespace_module.const_defined?('Metasploit')
166 158
         klass = namespace_module.const_get('Metasploit')
167 159
       else
@@ -426,6 +418,23 @@ class Msf::Modules::Loader::Base
426 418
     elog(log_message)
427 419
   end
428 420
 
421
+  # Records the load warning to {Msf::ModuleManager::Loading#module_load_warnings} and the log.
422
+  #
423
+  # @param [String] module_path Path to the module as returned by {#module_path}.
424
+  # @param [String] Error message that caused the warning.
425
+  # @return [void]
426
+  #
427
+  # @see #module_path
428
+  def load_warning(module_path, error)
429
+    module_manager.module_load_warnings[module_path] = error.to_s
430
+
431
+    log_lines = []
432
+    log_lines << "#{module_path} generated a warning during load:"
433
+    log_lines << error.to_s
434
+    log_message = log_lines.join("\n")
435
+    wlog(log_message)
436
+  end
437
+
429 438
   # @return [Msf::ModuleManager] The module manager for which this loader is loading modules.
430 439
   attr_reader :module_manager
431 440
 

+ 7
- 0
lib/msf/ui/console/command_dispatcher/core.rb View File

@@ -223,6 +223,13 @@ class Core
223 223
       end
224 224
     end
225 225
 
226
+    if framework.modules.module_load_warnings.length > 0
227
+      print_warning("The following modules were loaded with warnings:")
228
+      framework.modules.module_load_warnings.each do |path, error|
229
+        print_warning("\t#{path}: #{error}")
230
+      end
231
+    end
232
+
226 233
     cmd_banner()
227 234
   end
228 235
 

+ 7
- 0
lib/msf/ui/console/driver.rb View File

@@ -535,6 +535,13 @@ class Driver < Msf::Ui::Driver
535 535
       end
536 536
     end
537 537
 
538
+    if framework.modules.module_load_warnings.length > 0
539
+      print_warning("The following modules were loaded with warnings:")
540
+      framework.modules.module_load_warnings.each do |path, error|
541
+        print_warning("\t#{path}: #{error}")
542
+      end
543
+    end
544
+
538 545
     framework.events.on_ui_start(Msf::Framework::Revision)
539 546
 
540 547
     if $msf_spinner_thread

Loading…
Cancel
Save