Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/modules/module_missing_reference.rb
Views: 11767
#!/usr/bin/env ruby12msfbase = __FILE__3while File.symlink?(msfbase)4msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))5end6$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))7$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']89require 'msfenv'10require 'rex'1112# See lib/msf/core/module/reference.rb13# We gsub '#{in_ctx_val}' with the actual value14def types15[16'ALL',17'CVE',18'CWE',19'BID',20'MSB',21'EDB',22'US-CERT-VU',23'ZDI',24'WPVDB',25'PACKETSTORM',26'URL'27]28end2930filter = 'All'31filters = ['all','exploit','payload','post','nop','encoder','auxiliary']32type = 'CVE'33save = nil3435opts = Rex::Parser::Arguments.new(36"-h" => [ false, "Help menu." ],37"-f" => [ true, "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = ALL)."],38"-t" => [ true, "Type of Reference to sort by #{types * ', '}"],39"-o" => [ true, "Save the results to a file"]40)4142flags = []4344opts.parse(ARGV) { |opt, idx, val|45case opt46when "-h"47puts "\nMetasploit Script for Displaying Missing References."48puts "=========================================================="49puts opts.usage50exit51when "-f"52unless filters.include?(val.downcase)53puts "Invalid Filter Supplied: #{val}"54puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"55exit56end57flags << "Module Filter: #{val}"58filter = val59when "-t"60val = (val || '').upcase61unless types.include?(val)62puts "Invalid Type Supplied: #{val}"63puts "Please use one of these: #{types.keys.inspect}"64exit65end66type = val67when "-o"68flags << "Output to file: Yes"69save = val70end71}7273flags << "Type: #{type}"7475puts flags * " | "7677framework_opts = { 'DisableDatabase' => true }78if filter.downcase != 'all'79framework_opts[:module_types] = [ filter.downcase ]80end8182$framework = Msf::Simple::Framework.create(framework_opts)8384puts "[*] Going through Metasploit modules for missing #{type}..."8586table = Rex::Text::Table.new(87'Header' => 'Missing Module References',88'Indent' => 2,89'Columns' => ['Module', 'Missing Reference']90)9192$framework.modules.each { |name, mod|93if mod.nil?94elog("Unable to load #{name}")95next96end9798m = mod.new99ref_ids = m.references.collect { |r| r.ctx_id }100101unless ref_ids.include?(type)102puts "[*] Missing #{type} : #{m.fullname}"103if save104table << [m.fullname, type]105end106end107}108109if save110begin111File.write(save, table.to_s)112puts "[*] Results saved to: #{save}"113rescue ::Exception114puts "[*] Failed to save the results"115end116end117118119120