forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayload_lengths.rb
executable file
·82 lines (63 loc) · 1.7 KB
/
payload_lengths.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby
#
# $Id$
# $Revision$
#
# This script lists each payload module along with its length
# NOTE: No encoding or BadChar handling is performed
#
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', 'lib')))
require 'fastlib'
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
require 'rex'
require 'msf/ui'
require 'msf/base'
Indent = ' '
# Initialize the simplified framework instance.
$framework = Msf::Simple::Framework.create(
:module_types => [ Msf::MODULE_PAYLOAD ],
'DisableDatabase' => true
)
# Process special var/val pairs...
Msf::Ui::Common.process_cli_arguments($framework, ARGV)
options = ARGV.join(',')
tbl = Rex::Ui::Text::Table.new(
'Header' => 'Payload Lengths',
'Indent' => Indent.length,
'Columns' => [ 'Payload', 'Length' ]
)
enc = nil
$framework.payloads.each_module { |payload_name, mod|
len = 'Error: Unknown error!'
begin
# Create the payload instance
payload = mod.new
raise "Invalid payload" if not payload
# Set the variables from the cmd line
payload.datastore.import_options_from_s(options)
# Skip non-specified architectures
if (ds_arch = payload.datastore['ARCH'])
next if not payload.arch?(ds_arch)
end
# Skip non-specified platforms
if (ds_plat = payload.datastore['PLATFORM'])
ds_plat = Msf::Module::PlatformList.transform(ds_plat)
next if not payload.platform.supports?(ds_plat)
end
len = payload.size
if len > 0
len = len.to_s
else
len = "Error: Empty payload"
end
rescue
len = "Error: #{$!}"
end
tbl << [ payload_name, len ]
}
puts tbl.to_s