forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_license.rb
executable file
·133 lines (106 loc) · 2.62 KB
/
module_license.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env ruby
#
# $Id$
#
# This script lists each module by its licensing terms
#
# $Revision$
#
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', 'lib')))
require 'fastlib'
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
require 'rex'
require 'msf/ui'
require 'msf/base'
def lic_short(l)
if (l.class == Array)
l = l[0]
end
case l
when MSF_LICENSE
'MSF'
when GPL_LICENSE
'GPL'
when BSD_LICENSE
'BSD'
when ARTISTIC_LICENSE
'ART'
else
'UNK'
end
end
sort=0
filter= 'All'
filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
reg=0
regex= ''
opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help menu." ],
"-s" => [ false, "Sort by License instead of Module Type."],
"-r" => [ false, "Reverse Sort"],
"-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],
"-x" => [ true, "String or RegEx to try and match against the License Field"]
)
opts.parse(ARGV) { |opt, idx, val|
case opt
when "-h"
puts "\nMetasploit Script for Displaying Module License information."
puts "=========================================================="
puts opts.usage
exit
when "-s"
puts "Sorting by License"
sort = 1
when "-r"
puts "Reverse Sorting"
sort = 2
when "-f"
unless filters.include?(val.downcase)
puts "Invalid Filter Supplied: #{val}"
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
exit
end
puts "Module Filter: #{val}"
filter = val
when "-x"
puts "Regex: #{val}"
reg=1
regex = val
end
}
Indent = ' '
# Always disable the database (we never need it just to list module
# information).
framework_opts = { 'DisableDatabase' => true }
# If the user only wants a particular module type, no need to load the others
if filter.downcase != 'all'
framework_opts[:module_types] = [ filter.downcase ]
end
# Initialize the simplified framework instance.
$framework = Msf::Simple::Framework.create(framework_opts)
tbl = Rex::Ui::Text::Table.new(
'Header' => 'Licensed Modules',
'Indent' => Indent.length,
'Columns' => [ 'License','Type', 'Name' ]
)
licenses = {}
$framework.modules.each { |name, mod|
x = mod.new
lictype = lic_short(x.license)
if reg==0 or lictype=~/#{regex}/
tbl << [ lictype, mod.type.capitalize, name ]
end
}
if sort == 1
tbl.sort_rows(0)
end
if sort == 2
tbl.sort_rows(1)
tbl.rows.reverse
end
puts tbl.to_s