Path: blob/master/tools/modules/module_missing_reference.rb
56920 views
#!/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'GHSA',27'OSV',28'URL'29]30end3132filter = 'All'33filters = ['all','exploit','payload','post','nop','encoder','auxiliary']34type = 'CVE'35save = nil3637opts = Rex::Parser::Arguments.new(38"-h" => [ false, "Help menu." ],39"-f" => [ true, "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = ALL)."],40"-t" => [ true, "Type of Reference to sort by #{types * ', '}"],41"-o" => [ true, "Save the results to a file"]42)4344flags = []4546opts.parse(ARGV) { |opt, idx, val|47case opt48when "-h"49puts "\nMetasploit Script for Displaying Missing References."50puts "=========================================================="51puts opts.usage52exit53when "-f"54unless filters.include?(val.downcase)55puts "Invalid Filter Supplied: #{val}"56puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"57exit58end59flags << "Module Filter: #{val}"60filter = val61when "-t"62val = (val || '').upcase63unless types.include?(val)64puts "Invalid Type Supplied: #{val}"65puts "Please use one of these: #{types.keys.inspect}"66exit67end68type = val69when "-o"70flags << "Output to file: Yes"71save = val72end73}7475flags << "Type: #{type}"7677puts flags * " | "7879framework_opts = { 'DisableDatabase' => true }80if filter.downcase != 'all'81framework_opts[:module_types] = [ filter.downcase ]82end8384$framework = Msf::Simple::Framework.create(framework_opts)8586puts "[*] Going through Metasploit modules for missing #{type}..."8788table = Rex::Text::Table.new(89'Header' => 'Missing Module References',90'Indent' => 2,91'Columns' => ['Module', 'Missing Reference']92)9394$framework.modules.each { |name, mod|95if mod.nil?96elog("Unable to load #{name}")97next98end99100m = mod.new101ref_ids = m.references.collect { |r| r.ctx_id }102103unless ref_ids.include?(type)104puts "[*] Missing #{type} : #{m.fullname}"105if save106table << [m.fullname, type]107end108end109}110111if save112begin113File.write(save, table.to_s)114puts "[*] Results saved to: #{save}"115rescue ::Exception116puts "[*] Failed to save the results"117end118end119120121122