Path: blob/master/tools/modules/update_payload_cached_sizes.rb
19850 views
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67#8# This script updates the CachedSize constants in payload modules9#1011msfbase = __FILE__12while File.symlink?(msfbase)13msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))14end1516$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))17require 'msfenv'1819$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']2021gem 'rex-text'2223require 'rex'2425# Initialize the simplified framework instance.26framework = Msf::Simple::Framework.create('DisableDatabase' => true)27exceptions = []28framework.payloads.each_module do |name, mod|29begin30next if name =~ /generic/31mod_inst = framework.payloads.create(name)32#mod_inst.datastore.merge!(framework.datastore)33next if mod_inst.is_a?(Msf::Payload::Adapter) || Msf::Util::PayloadCachedSize.is_cached_size_accurate?(mod_inst)34$stdout.puts "[*] Updating the CacheSize for #{mod.file_path}..."35Msf::Util::PayloadCachedSize.update_module_cached_size(mod_inst)36rescue => e37$stderr.puts "[!] Caught Error while updating #{name}:\n#{e}\n#{e.backtrace.map { |line| "\t#{line}" }.join("\n")}"38exceptions << [ e, name ]39end40end4142exit(1) unless exceptions.empty?434445