|
1 | 1 | #!/usr/bin/env ruby
|
2 | 2 | #
|
3 |
| -# $Id$ |
4 |
| -# |
5 |
| -# This script lists each exploit module by its compatible payloads |
6 |
| -# |
7 |
| -# $Revision$ |
| 3 | +# This script updates the CachedSize constants in payload modules |
8 | 4 | #
|
9 | 5 |
|
10 | 6 | msfbase = __FILE__
|
|
20 | 16 | require 'rex'
|
21 | 17 | require 'msf/ui'
|
22 | 18 | require 'msf/base'
|
23 |
| - |
24 |
| - |
25 |
| -def print_status(msg) |
26 |
| - print_line "[*] #{msg}" |
27 |
| -end |
28 |
| - |
29 |
| -def print_error(msg) |
30 |
| - print_line "[-] #{msg}" |
31 |
| -end |
32 |
| - |
33 |
| -def print_line(msg) |
34 |
| - $stderr.puts msg |
35 |
| -end |
36 |
| - |
37 |
| -def is_dynamic_size?(mod) |
38 |
| - [*(1..5)].map{|x| mod.new.size}.uniq.length != 1 |
39 |
| -end |
40 |
| - |
41 |
| -def update_cache_size(mod, val) |
42 |
| - data = '' |
43 |
| - File.open(mod.file_path, 'rb'){|fd| data = fd.read(fd.stat.size)} |
44 |
| - data = data.gsub(/^\s*CachedSize\s*=\s*(\d+|:dynamic).*/, '') |
45 |
| - data = data.gsub(/^(module Metasploit\d+)\s*\n/) {|m| "#{m.strip}\n\n CachedSize = #{val}\n\n" } |
46 |
| - File.open(mod.file_path, 'wb'){|fd| fd.write(data) } |
47 |
| -end |
| 19 | +require 'msf/util/payload_cached_size' |
48 | 20 |
|
49 | 21 | # Initialize the simplified framework instance.
|
50 |
| -$framework = Msf::Simple::Framework.create('DisableDatabase' => true) |
51 |
| - |
52 |
| -$framework.payloads.each_module do |name, mod| |
53 |
| - gsize = mod.new.size |
54 |
| - |
55 |
| - if is_dynamic_size?(mod) && ! mod.dynamic_size? |
56 |
| - print_status("#{mod.file_path} has a dynamic size, updating cache...") |
57 |
| - update_cache_size(mod, ":dynamic") |
58 |
| - next |
59 |
| - end |
60 |
| - |
61 |
| - next if mod.dynamic_size? |
| 22 | +framework = Msf::Simple::Framework.create('DisableDatabase' => true) |
62 | 23 |
|
63 |
| - if mod.cached_size.nil? |
64 |
| - print_status("#{mod.file_path} has size #{gsize}, updating cache...") |
65 |
| - update_cache_size(mod, gsize) |
66 |
| - else |
67 |
| - next if gsize == mod.cached_size |
68 |
| - print_error("#{mod.file_path} has cached size #{mod.cached_size} but generated #{gsize}, updating cache...") |
69 |
| - update_cache_size(mod, gsize) |
70 |
| - next |
71 |
| - end |
| 24 | +framework.payloads.each_module do |name, mod| |
| 25 | + next if Msf::Util::PayloadCachedSize.is_cached_size_accurate?(mod) |
| 26 | + $stdout.puts "[*] Updating the CacheSize for #{mod.file_path}..." |
| 27 | + Msf::Util::PayloadCachedSize.update_module_cached_size(mod) |
72 | 28 | end
|
73 | 29 |
|
0 commit comments