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_author.rb
Views: 11768
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 author(s) and
10
# the number of modules per author
11
#
12
13
msfbase = __FILE__
14
while File.symlink?(msfbase)
15
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
16
end
17
18
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
19
20
require 'msfenv'
21
require 'rex'
22
require 'json'
23
24
FILENAME = 'db/modules_metadata_base.json'
25
26
sort = 0
27
filter = 'All'
28
filters = ['all','exploit','payload','post','nop','encoder','auxiliary', 'evasion']
29
reg = 0
30
regex = nil
31
32
opts = Rex::Parser::Arguments.new(
33
"-h" => [ false, "Help menu." ],
34
"-s" => [ false, "Sort by Author 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
"-x" => [ true, "String or RegEx to try and match against the Author Field"]
38
)
39
40
opts.parse(ARGV) { |opt, idx, val|
41
case opt
42
when "-h"
43
puts "\nMetasploit Script for Displaying Module Author information."
44
puts "=========================================================="
45
puts opts.usage
46
exit
47
when "-s"
48
puts "Sorting by Author"
49
sort = 1
50
when "-r"
51
puts "Reverse Sorting"
52
sort = 2
53
when "-f"
54
unless filters.include?(val.downcase)
55
puts "Invalid Filter Supplied: #{val}"
56
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
57
exit
58
end
59
puts "Module Filter: #{val}"
60
filter = val
61
when "-x"
62
puts "Regex: #{val}"
63
regex = Regexp.new(val)
64
end
65
66
}
67
68
69
Indent = ' '
70
71
tbl = Rex::Text::Table.new(
72
'Header' => 'Module References',
73
'Indent' => Indent.length,
74
'Columns' => [ 'Module', 'Reference' ]
75
)
76
77
names = {}
78
79
local_modules = JSON.parse(File.read(FILENAME)) # get cache file location from framework?
80
81
local_modules.each do |_module_key, local_module|
82
local_module['author'].each do |r|
83
next if filter.downcase != 'all' && local_module['type'] != filter.downcase
84
if regex.nil? or r =~ regex
85
tbl << [ local_module['fullname'], r ]
86
names[r] ||= 0
87
names[r] += 1
88
end
89
end
90
end
91
92
if sort == 1
93
tbl.sort_rows(1)
94
end
95
96
97
if sort == 2
98
tbl.sort_rows(1)
99
tbl.rows.reverse
100
end
101
102
puts tbl.to_s
103
104
tbl = Rex::Text::Table.new(
105
'Header' => 'Module Count by Author',
106
'Indent' => Indent.length,
107
'Columns' => [ 'Count', 'Name' ]
108
)
109
names.keys.sort {|a,b| names[b] <=> names[a] }.each do |name|
110
tbl << [ names[name].to_s, name ]
111
end
112
113
puts
114
puts tbl.to_s
115
116