Skip to content

Commit a82168d

Browse files
author
HD Moore
committed
Fixes rapid7#5361 by adding --encoder-space to msfvenom
1 parent 8bd41a3 commit a82168d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/msf/core/payload_generator.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class PayloadGenerator
6464
# @!attribute space
6565
# @return [Fixnum] The maximum size in bytes of the payload
6666
attr_accessor :space
67+
# @!attribute encoder_space
68+
# @return [Fixnum] The maximum size in bytes of the encoded payload
69+
attr_accessor :encoder_space
6770
# @!attribute stdin
6871
# @return [String] The raw bytes of a payload taken from STDIN
6972
attr_accessor :stdin
@@ -85,6 +88,7 @@ class PayloadGenerator
8588
# @option opts [String] :badchars (see #badchars)
8689
# @option opts [String] :template (see #template)
8790
# @option opts [Fixnum] :space (see #space)
91+
# @option opts [Fixnum] :encoder_space (see #encoder_space)
8892
# @option opts [Fixnum] :nops (see #nops)
8993
# @option opts [String] :add_code (see #add_code)
9094
# @option opts [Boolean] :keep (see #keep)
@@ -109,6 +113,7 @@ def initialize(opts={})
109113
@stdin = opts.fetch(:stdin, nil)
110114
@template = opts.fetch(:template, '')
111115
@var_name = opts.fetch(:var_name, 'buf')
116+
@encoder_space = opts.fetch(:encoder_space, @space)
112117

113118
@framework = opts.fetch(:framework)
114119

@@ -200,7 +205,7 @@ def encode_payload(shellcode)
200205
encoder_list.each do |encoder_mod|
201206
cli_print "Attempting to encode payload with #{iterations} iterations of #{encoder_mod.refname}"
202207
begin
203-
encoder_mod.available_space = @space
208+
encoder_mod.available_space = @encoder_space
204209
return run_encoder(encoder_mod, shellcode.dup)
205210
rescue ::Msf::EncoderSpaceViolation => e
206211
cli_print "#{encoder_mod.refname} failed with #{e.message}"
@@ -395,7 +400,7 @@ def run_encoder(encoder_module, shellcode)
395400
iterations.times do |x|
396401
shellcode = encoder_module.encode(shellcode.dup, badchars, nil, platform_list)
397402
cli_print "#{encoder_module.refname} succeeded with size #{shellcode.length} (iteration=#{x})"
398-
if shellcode.length > space
403+
if shellcode.length > encoder_space
399404
raise EncoderSpaceViolation, "encoder has made a buffer that is too big"
400405
end
401406
end

msfvenom

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ require 'msf/core/payload_generator'
9797
opts[:space] = s
9898
end
9999

100+
opt.on('--encoder-space <length>', Integer, 'The maximum size of the encoded payload (defaults to the -s value)') do |s|
101+
opts[:encoder_space] = s
102+
end
103+
100104
opt.on('-b', '--bad-chars <list>', String, 'The list of characters to avoid example: \'\x00\xff\'') do |b|
101105
opts[:badchars] = Rex::Text.hex_to_raw(b)
102106
end

0 commit comments

Comments
 (0)