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_ports.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 the default ports it uses
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
# Initialize the simplified framework instance.
25
$framework = Msf::Simple::Framework.create('DisableDatabase' => true)
26
# XXX: this is weird, merging module sets together for different module types could lead to unforseen issues
27
all_modules = $framework.exploits.merge($framework.auxiliary)
28
all_ports = {}
29
30
all_modules.each_module { |name, mod|
31
x = mod.new
32
ports = []
33
34
if x.datastore['RPORT']
35
ports << x.datastore['RPORT']
36
end
37
38
if(x.respond_to?('autofilter_ports'))
39
x.autofilter_ports.each do |rport|
40
ports << rport
41
end
42
end
43
ports = ports.map{|p| p.to_i}
44
ports.uniq!
45
ports.sort{|a,b| a <=> b}.each do |rport|
46
# Just record the first occurrence.
47
all_ports[rport] = x.fullname unless all_ports[rport]
48
end
49
}
50
51
all_ports.sort.each { |k,v|
52
puts "%5s # %s" % [k,v]
53
}
54
55