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_rank.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 with its rank
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
ranks= Hash.new
25
26
ranks['Manual'] = 0
27
ranks['Low'] = 100
28
ranks['Average'] = 200
29
ranks['Normal'] = 300
30
ranks['Good'] = 400
31
ranks['Great'] = 500
32
ranks['Excellent'] = 600
33
34
minrank= 0
35
maxrank= 600
36
sort = 0
37
filter= 'All'
38
filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
39
40
opts = Rex::Parser::Arguments.new(
41
"-h" => [ false, "Help menu." ],
42
"-M" => [ true, "Set Maximum Rank [Manual,Low,Average,Normal,Good,Great,Excellent] (Default = Excellent)." ],
43
"-m" => [ true, "Set Minimum Rank [Manual,Low,Average,Normal,Good,Great,Excellent] (Default = Manual)."],
44
"-s" => [ false, "Sort by Rank instead of Module Type."],
45
"-r" => [ false, "Reverse Sort by Rank"],
46
"-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],
47
)
48
49
opts.parse(ARGV) { |opt, idx, val|
50
case opt
51
when "-h"
52
puts "\nMetasploit Script for Displaying Module Rank information."
53
puts "=========================================================="
54
puts opts.usage
55
exit
56
when "-M"
57
unless ranks.include?(val)
58
puts "Invalid Rank Supplied: #{val}"
59
puts "Please use one of these: [Manual,Low,Average,Normal,Good,Great,Excellent]"
60
exit
61
end
62
puts "Maximum Rank: #{val}"
63
maxrank = ranks[val]
64
when "-m"
65
unless ranks.include?(val)
66
puts "Invalid Rank Supplied: #{val}"
67
puts "Please use one of these: [Manual,Low,Average,Normal,Good,Great,Excellent]"
68
exit
69
end
70
puts "Minimum Rank: #{val}"
71
minrank = ranks[val]
72
when "-s"
73
puts "Sorting by Rank"
74
sort = 1
75
when "-r"
76
puts "Reverse Sorting by Rank"
77
sort = 2
78
when "-f"
79
unless filters.include?(val.downcase)
80
puts "Invalid Filter Supplied: #{val}"
81
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
82
exit
83
end
84
puts "Module Filter: #{val}"
85
filter = val
86
87
end
88
89
}
90
91
92
Indent = ' '
93
94
# Always disable the database (we never need it just to list module
95
# information).
96
framework_opts = { 'DisableDatabase' => true }
97
98
# If the user only wants a particular module type, no need to load the others
99
if filter.downcase != 'all'
100
framework_opts[:module_types] = [ filter.downcase ]
101
end
102
103
# Initialize the simplified framework instance.
104
$framework = Msf::Simple::Framework.create(framework_opts)
105
106
107
tbl = Rex::Text::Table.new(
108
'Header' => 'Module Ranks',
109
'Indent' => Indent.length,
110
'Columns' => [ 'Module', 'Rank' ]
111
)
112
113
$framework.modules.each { |name, mod|
114
x = mod.new
115
modrank = x.rank
116
if modrank >= minrank and modrank<= maxrank
117
tbl << [ x.fullname, modrank ]
118
end
119
120
}
121
122
if sort == 1
123
tbl.sort_rows(1)
124
end
125
126
if sort == 2
127
tbl.sort_rows(1)
128
tbl.rows.reverse
129
end
130
131
puts tbl.to_s
132
133