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_targets.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 all modules with their targets
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
sort=0
25
fil = 0
26
filter = ""
27
28
opts = Rex::Parser::Arguments.new(
29
"-h" => [ false, "Help menu." ],
30
"-s" => [ false, "Sort by Target instead of Module Type."],
31
"-r" => [ false, "Reverse Sort"],
32
"-x" => [ true, "String or RegEx to try and match against the Targets field"]
33
)
34
35
opts.parse(ARGV) { |opt, idx, val|
36
case opt
37
when "-h"
38
puts "\nMetasploit Script for Displaying Module Target information."
39
puts "=========================================================="
40
puts opts.usage
41
exit
42
when "-s"
43
puts "Sorting by Target"
44
sort = 1
45
when "-r"
46
puts "Reverse Sorting"
47
sort = 2
48
when "-x"
49
puts "Filter: #{val}"
50
filter = val
51
fil=1
52
end
53
}
54
55
Indent = ' '
56
57
# Initialize the simplified framework instance.
58
$framework = Msf::Simple::Framework.create('DisableDatabase' => true)
59
60
tbl = Rex::Text::Table.new(
61
'Header' => 'Module Targets',
62
'Indent' => Indent.length,
63
'Columns' => [ 'Module name','Target' ]
64
)
65
66
all_modules = $framework.exploits
67
68
all_modules.each_module { |name, mod|
69
x = mod.new
70
x.targets.each do |targ|
71
if fil==0 or targ.name=~/#{filter}/
72
tbl << [ x.fullname, targ.name ]
73
end
74
end
75
}
76
77
if sort == 1
78
tbl.sort_rows(1)
79
end
80
81
82
if sort == 2
83
tbl.sort_rows(1)
84
tbl.rows.reverse
85
end
86
87
puts tbl.to_s
88
89