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_mixins.rb
Views: 11619
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 all modules with their mixins. Handy for finding different "kinds" of modules.
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 do_want(klass)
25
return false if klass.class != Module
26
return false if [ Kernel, ERB::Util, SNMP::BER].include?(klass)
27
return false if klass.to_s.match(/^Rex::Ui::Subscriber/)
28
29
return true
30
end
31
32
# Initialize the simplified framework instance.
33
$framework = Msf::Simple::Framework.create('DisableDatabase' => true)
34
35
all_modules = $framework.exploits
36
37
# If you give an argument (any argument will do), you really want a sorted
38
# list of mixins, regardless of the module they're in.
39
if ARGV[0]
40
mod_hash = {}
41
longest_name = 0
42
all_modules.each_module do |name, mod|
43
x = mod.new
44
mixins = x.class.ancestors.select {|y| do_want(y) }
45
mixins.each do |m|
46
mod_hash[m] ||= 0
47
mod_hash[m] += 1
48
longest_name = m.to_s.size unless m.to_s.size < longest_name
49
end
50
end
51
mod_hash.sort_by {|a| a[1]}.reverse.each do |arr|
52
puts "%-#{longest_name}s | %d" % arr
53
end
54
else
55
# Tables kind of suck for this.
56
results = []
57
longest_name = 0
58
all_modules.each_module do |name, mod|
59
x = mod.new
60
mixins = x.class.ancestors.select {|y| do_want(y) }
61
results << [x.fullname, mixins.sort {|a,b| a.to_s <=> b.to_s}.join(", ")]
62
longest_name = x.fullname.size if longest_name < x.fullname.size
63
end
64
# name | module1, module1, etc.
65
results.each do |r|
66
puts "%-#{longest_name}s | %s" % r
67
end
68
end
69
70