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/update_payload_cached_sizes.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 updates the CachedSize constants in payload 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
gem 'rex-text'
23
24
require 'rex'
25
26
# Initialize the simplified framework instance.
27
framework = Msf::Simple::Framework.create('DisableDatabase' => true)
28
exceptions = []
29
framework.payloads.each_module do |name, mod|
30
begin
31
next if name =~ /generic/
32
mod_inst = framework.payloads.create(name)
33
#mod_inst.datastore.merge!(framework.datastore)
34
next if mod_inst.is_a?(Msf::Payload::Adapter) || Msf::Util::PayloadCachedSize.is_cached_size_accurate?(mod_inst)
35
$stdout.puts "[*] Updating the CacheSize for #{mod.file_path}..."
36
Msf::Util::PayloadCachedSize.update_module_cached_size(mod_inst)
37
rescue => e
38
$stderr.puts "[!] Caught Error while updating #{name}:\n#{e}\n#{e.backtrace.map { |line| "\t#{line}" }.join("\n")}"
39
exceptions << [ e, name ]
40
end
41
end
42
43
exit(1) unless exceptions.empty?
44
45