CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/module_license.rb
Views: 11766
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 licensing terms
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
def lic_short(l)
25
if (l.class == Array)
26
l = l[0]
27
end
28
29
case l
30
when MSF_LICENSE
31
'MSF'
32
when GPL_LICENSE
33
'GPL'
34
when BSD_LICENSE
35
'BSD'
36
when ARTISTIC_LICENSE
37
'ART'
38
else
39
'UNK'
40
end
41
end
42
43
44
sort=0
45
filter= 'All'
46
filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
47
reg=0
48
regex= ''
49
50
opts = Rex::Parser::Arguments.new(
51
"-h" => [ false, "Help menu." ],
52
"-s" => [ false, "Sort by License instead of Module Type."],
53
"-r" => [ false, "Reverse Sort"],
54
"-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],
55
"-x" => [ true, "String or RegEx to try and match against the License Field"]
56
)
57
58
opts.parse(ARGV) { |opt, idx, val|
59
case opt
60
when "-h"
61
puts "\nMetasploit Script for Displaying Module License information."
62
puts "=========================================================="
63
puts opts.usage
64
exit
65
when "-s"
66
puts "Sorting by License"
67
sort = 1
68
when "-r"
69
puts "Reverse Sorting"
70
sort = 2
71
when "-f"
72
unless filters.include?(val.downcase)
73
puts "Invalid Filter Supplied: #{val}"
74
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
75
exit
76
end
77
puts "Module Filter: #{val}"
78
filter = val
79
when "-x"
80
puts "Regex: #{val}"
81
reg=1
82
regex = val
83
end
84
85
}
86
87
88
89
90
Indent = ' '
91
92
# Always disable the database (we never need it just to list module
93
# information).
94
framework_opts = { 'DisableDatabase' => true }
95
96
# If the user only wants a particular module type, no need to load the others
97
if filter.downcase != 'all'
98
framework_opts[:module_types] = [ filter.downcase ]
99
end
100
101
# Initialize the simplified framework instance.
102
$framework = Msf::Simple::Framework.create(framework_opts)
103
104
105
tbl = Rex::Text::Table.new(
106
'Header' => 'Licensed Modules',
107
'Indent' => Indent.length,
108
'Columns' => [ 'License','Type', 'Name' ]
109
)
110
111
licenses = {}
112
113
$framework.modules.each { |name, mod|
114
x = mod.new
115
lictype = lic_short(x.license)
116
if reg==0 or lictype=~/#{regex}/
117
tbl << [ lictype, mod.type.capitalize, name ]
118
end
119
}
120
121
122
if sort == 1
123
tbl.sort_rows(0)
124
end
125
126
127
if sort == 2
128
tbl.sort_rows(1)
129
tbl.rows.reverse
130
end
131
132
puts tbl.to_s
133
134