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/payload_lengths.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
# This script lists each payload module along with its length
9
# NOTE: No encoding or BadChar handling is performed
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
Indent = ' '
25
26
# Initialize the simplified framework instance.
27
$framework = Msf::Simple::Framework.create(
28
:module_types => [ Msf::MODULE_PAYLOAD ],
29
'DisableDatabase' => true
30
)
31
32
# Process special var/val pairs...
33
Msf::Ui::Common.process_cli_arguments($framework, ARGV)
34
35
options = ARGV.join(',')
36
37
tbl = Rex::Text::Table.new(
38
'Header' => 'Payload Lengths',
39
'Indent' => Indent.length,
40
'Columns' => [ 'Payload', 'Length' ]
41
)
42
43
enc = nil
44
45
$framework.payloads.each_module { |payload_name, mod|
46
47
len = 'Error: Unknown error!'
48
49
begin
50
# Create the payload instance
51
payload = mod.new
52
raise "Invalid payload" if not payload
53
54
# Set the variables from the cmd line
55
payload.datastore.import_options_from_s(options)
56
57
# Skip non-specified architectures
58
if (ds_arch = payload.datastore['ARCH'])
59
next if not payload.arch?(ds_arch)
60
end
61
62
# Skip non-specified platforms
63
if (ds_plat = payload.datastore['PLATFORM'])
64
ds_plat = Msf::Module::PlatformList.transform(ds_plat)
65
next if not payload.platform.supports?(ds_plat)
66
end
67
68
len = payload.size
69
if len > 0
70
len = len.to_s
71
else
72
len = "Error: Empty payload"
73
end
74
rescue
75
len = "Error: #{$!}"
76
end
77
78
tbl << [ payload_name, len ]
79
}
80
81
puts tbl.to_s
82
83