Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/module_missing_reference.rb
56920 views
1
#!/usr/bin/env ruby
2
3
msfbase = __FILE__
4
while File.symlink?(msfbase)
5
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
6
end
7
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
8
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
9
10
require 'msfenv'
11
require 'rex'
12
13
# See lib/msf/core/module/reference.rb
14
# We gsub '#{in_ctx_val}' with the actual value
15
def types
16
[
17
'ALL',
18
'CVE',
19
'CWE',
20
'BID',
21
'MSB',
22
'EDB',
23
'US-CERT-VU',
24
'ZDI',
25
'WPVDB',
26
'PACKETSTORM',
27
'GHSA',
28
'OSV',
29
'URL'
30
]
31
end
32
33
filter = 'All'
34
filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
35
type = 'CVE'
36
save = nil
37
38
opts = Rex::Parser::Arguments.new(
39
"-h" => [ false, "Help menu." ],
40
"-f" => [ true, "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = ALL)."],
41
"-t" => [ true, "Type of Reference to sort by #{types * ', '}"],
42
"-o" => [ true, "Save the results to a file"]
43
)
44
45
flags = []
46
47
opts.parse(ARGV) { |opt, idx, val|
48
case opt
49
when "-h"
50
puts "\nMetasploit Script for Displaying Missing References."
51
puts "=========================================================="
52
puts opts.usage
53
exit
54
when "-f"
55
unless filters.include?(val.downcase)
56
puts "Invalid Filter Supplied: #{val}"
57
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
58
exit
59
end
60
flags << "Module Filter: #{val}"
61
filter = val
62
when "-t"
63
val = (val || '').upcase
64
unless types.include?(val)
65
puts "Invalid Type Supplied: #{val}"
66
puts "Please use one of these: #{types.keys.inspect}"
67
exit
68
end
69
type = val
70
when "-o"
71
flags << "Output to file: Yes"
72
save = val
73
end
74
}
75
76
flags << "Type: #{type}"
77
78
puts flags * " | "
79
80
framework_opts = { 'DisableDatabase' => true }
81
if filter.downcase != 'all'
82
framework_opts[:module_types] = [ filter.downcase ]
83
end
84
85
$framework = Msf::Simple::Framework.create(framework_opts)
86
87
puts "[*] Going through Metasploit modules for missing #{type}..."
88
89
table = Rex::Text::Table.new(
90
'Header' => 'Missing Module References',
91
'Indent' => 2,
92
'Columns' => ['Module', 'Missing Reference']
93
)
94
95
$framework.modules.each { |name, mod|
96
if mod.nil?
97
elog("Unable to load #{name}")
98
next
99
end
100
101
m = mod.new
102
ref_ids = m.references.collect { |r| r.ctx_id }
103
104
unless ref_ids.include?(type)
105
puts "[*] Missing #{type} : #{m.fullname}"
106
if save
107
table << [m.fullname, type]
108
end
109
end
110
}
111
112
if save
113
begin
114
File.write(save, table.to_s)
115
puts "[*] Results saved to: #{save}"
116
rescue ::Exception
117
puts "[*] Failed to save the results"
118
end
119
end
120
121
122