CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/module_disclodate.rb
Views: 1904
1
#!/usr/bin/env ruby
2
3
##
4
# This module requires Metasploit: https://metasploit.com/download
5
# Current source: https://github.com/rapid7/metasploit-framework
6
##
7
8
#
9
# This script lists each module by its disclosure date
10
#
11
12
msfbase = __FILE__
13
while File.symlink?(msfbase)
14
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
15
end
16
17
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
18
require 'msfenv'
19
20
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
21
22
require 'rex'
23
24
nilc = false
25
sort = 0
26
filter = 'All'
27
filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
28
startdate = Date.new
29
enddate = Date.new(2525,01,01)
30
match = nil
31
32
opts = Rex::Parser::Arguments.new(
33
"-h" => [ false, "Help menu." ],
34
"-s" => [ false, "Sort by Disclosure Date instead of Module Type."],
35
"-r" => [ false, "Reverse Sort"],
36
"-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],
37
"-n" => [ false, "Filter out modules that have no Disclosure Date listed."],
38
"-d" => [ true, "Start of Date Range YYYY-MM-DD."],
39
"-D" => [ true, "End of Date Range YYYY-MM-DD."]
40
)
41
42
opts.parse(ARGV) { |opt, idx, val|
43
case opt
44
when "-h"
45
puts "\nMetasploit Script for Displaying Module Disclosure Date Information."
46
puts "=========================================================="
47
puts opts.usage
48
exit
49
when "-s"
50
puts "Sorting by Disclosure Date"
51
sort = 1
52
when "-r"
53
puts "Reverse Sorting"
54
sort = 2
55
when "-f"
56
unless filters.include?(val.downcase)
57
puts "Invalid Filter Supplied: #{val}"
58
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
59
exit
60
end
61
puts "Module Filter: #{val}"
62
filter = val
63
when "-n"
64
puts "Excluding Null dates"
65
nilc=1
66
when "-d"
67
(year,month,day) = val.split('-')
68
if Date.valid_civil?(year.to_i,month.to_i,day.to_i)
69
startdate= Date.new(year.to_i,month.to_i,day.to_i)
70
puts "Start Date: #{startdate}"
71
else
72
puts "Invalid Start Date: #{val}"
73
exit
74
end
75
when "-D"
76
(year,month,day) = val.split('-')
77
if Date.valid_civil?(year.to_i,month.to_i,day.to_i)
78
enddate= Date.new(year.to_i,month.to_i,day.to_i)
79
puts "End Date: #{enddate}"
80
else
81
puts "Invalid Start Date: #{val}"
82
exit
83
end
84
else
85
if opt
86
puts "Unknown option"
87
exit
88
end
89
match = Regexp.new(val)
90
end
91
92
}
93
94
Indent = ' '
95
96
# Always disable the database (we never need it just to list module
97
# information).
98
framework_opts = { 'DisableDatabase' => true }
99
100
# If the user only wants a particular module type, no need to load the others
101
if filter.downcase != 'all'
102
framework_opts[:module_types] = [ filter.downcase ]
103
end
104
105
# Initialize the simplified framework instance.
106
$framework = Msf::Simple::Framework.create(framework_opts)
107
108
109
tbl = Rex::Text::Table.new(
110
'Header' => 'Module References',
111
'Indent' => Indent.length,
112
'Columns' => [ 'Module', 'Disclosure Date' ]
113
)
114
115
$framework.modules.each { |name, mod|
116
next if match and not name =~ match
117
x = mod.new
118
if x.disclosure_date.nil?
119
if nilc==1
120
tbl << [ x.fullname, '' ]
121
end
122
else
123
if x.disclosure_date >= startdate and x.disclosure_date <= enddate
124
tbl << [ x.fullname, x.disclosure_date ]
125
end
126
end
127
}
128
129
130
if sort == 1
131
tbl.sort_rows(1)
132
end
133
134
135
if sort == 2
136
tbl.sort_rows(1)
137
tbl.rows.reverse
138
end
139
140
puts tbl.to_s
141
142