Skip to content

Commit 6031791

Browse files
author
Brent Cook
committed
Land rapid7#4876, @hmoore-r7 give encoders and payloads space available
2 parents 08df0bf + c3479ba commit 6031791

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

lib/msf/base/simple/payload.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ def self.generate_simple(payload, opts, &block)
5151

5252
# Generate the payload
5353
e = EncodedPayload.create(payload,
54-
'BadChars' => opts['BadChars'],
55-
'MinNops' => opts['NopSledSize'],
56-
'Encoder' => opts['Encoder'],
54+
'BadChars' => opts['BadChars'],
55+
'MinNops' => opts['NopSledSize'],
56+
'Encoder' => opts['Encoder'],
5757
'Iterations' => opts['Iterations'],
5858
'ForceEncode' => opts['ForceEncode'],
59-
'Space' => opts['MaxSize'])
59+
'DisableNops' => opts['DisableNops'],
60+
'Space' => opts['MaxSize'])
6061

6162
fmt = opts['Format'] || 'raw'
6263

lib/msf/core/encoded_payload.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def initialize(framework, pinst, reqs)
3434
self.framework = framework
3535
self.pinst = pinst
3636
self.reqs = reqs
37+
self.space = reqs['Space']
3738
end
3839

3940
#
@@ -64,6 +65,9 @@ def generate(raw = nil)
6465
# First, validate
6566
pinst.validate()
6667

68+
# Tell the payload how much space is available
69+
pinst.available_space = self.space
70+
6771
# Generate the raw version of the payload first
6872
generate_raw() if self.raw.nil?
6973

@@ -191,6 +195,9 @@ def encode
191195
next
192196
end
193197

198+
# Tell the encoder how much space is available
199+
self.encoder.available_space = self.space
200+
194201
eout = self.raw.dup
195202

196203
next_encoder = false
@@ -456,7 +463,10 @@ def arch
456463
# The number of encoding iterations used
457464
#
458465
attr_reader :iterations
459-
466+
#
467+
# The maximum number of bytes acceptable for the encoded payload
468+
#
469+
attr_reader :space
460470
protected
461471

462472
attr_writer :raw # :nodoc:
@@ -467,6 +477,7 @@ def arch
467477
attr_writer :encoder # :nodoc:
468478
attr_writer :nop # :nodoc:
469479
attr_writer :iterations # :nodoc:
480+
attr_writer :space # :nodoc
470481

471482
#
472483
# The payload instance used to generate the payload

lib/msf/core/encoder.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ def preserves_stack?
434434
false
435435
end
436436

437+
#
438+
# The amount of space available to the encoder, which may be nil,
439+
# indicating that the smallest possible encoding should be used.
440+
#
441+
attr_accessor :available_space
442+
437443
protected
438444

439445
#

lib/msf/core/payload.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@ def on_session(session)
500500
#
501501
attr_accessor :assoc_exploit
502502

503+
#
504+
# The amount of space available to the payload, which may be nil,
505+
# indicating that the smallest possible payload should be used.
506+
#
507+
attr_accessor :available_space
508+
503509
protected
504510

505511
#

lib/msf/core/payload_generator.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def encode_payload(shellcode)
184184
encoder_list.each do |encoder_mod|
185185
cli_print "Attempting to encode payload with #{iterations} iterations of #{encoder_mod.refname}"
186186
begin
187+
encoder_mod.available_space = @space
187188
return run_encoder(encoder_mod, shellcode.dup)
188189
rescue ::Msf::EncoderSpaceViolation => e
189190
cli_print "#{encoder_mod.refname} failed with #{e.message}"
@@ -298,9 +299,11 @@ def generate_raw_payload
298299
end
299300

300301
payload_module.generate_simple(
301-
'Format' => 'raw',
302-
'Options' => datastore,
303-
'Encoder' => nil
302+
'Format' => 'raw',
303+
'Options' => datastore,
304+
'Encoder' => nil,
305+
'MaxSize' => @space,
306+
'DisableNops' => true
304307
)
305308
end
306309
end

0 commit comments

Comments
 (0)