Skip to content

Commit

Permalink
Land #4876, @hmoore-r7 give encoders and payloads space available
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Cook committed Mar 9, 2015
2 parents 08df0bf + c3479ba commit 6031791
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/msf/base/simple/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ def self.generate_simple(payload, opts, &block)

# Generate the payload
e = EncodedPayload.create(payload,
'BadChars' => opts['BadChars'],
'MinNops' => opts['NopSledSize'],
'Encoder' => opts['Encoder'],
'BadChars' => opts['BadChars'],
'MinNops' => opts['NopSledSize'],
'Encoder' => opts['Encoder'],
'Iterations' => opts['Iterations'],
'ForceEncode' => opts['ForceEncode'],
'Space' => opts['MaxSize'])
'DisableNops' => opts['DisableNops'],
'Space' => opts['MaxSize'])

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

Expand Down
13 changes: 12 additions & 1 deletion lib/msf/core/encoded_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def initialize(framework, pinst, reqs)
self.framework = framework
self.pinst = pinst
self.reqs = reqs
self.space = reqs['Space']
end

#
Expand Down Expand Up @@ -64,6 +65,9 @@ def generate(raw = nil)
# First, validate
pinst.validate()

# Tell the payload how much space is available
pinst.available_space = self.space

# Generate the raw version of the payload first
generate_raw() if self.raw.nil?

Expand Down Expand Up @@ -191,6 +195,9 @@ def encode
next
end

# Tell the encoder how much space is available
self.encoder.available_space = self.space

eout = self.raw.dup

next_encoder = false
Expand Down Expand Up @@ -456,7 +463,10 @@ def arch
# The number of encoding iterations used
#
attr_reader :iterations

#
# The maximum number of bytes acceptable for the encoded payload
#
attr_reader :space
protected

attr_writer :raw # :nodoc:
Expand All @@ -467,6 +477,7 @@ def arch
attr_writer :encoder # :nodoc:
attr_writer :nop # :nodoc:
attr_writer :iterations # :nodoc:
attr_writer :space # :nodoc

#
# The payload instance used to generate the payload
Expand Down
6 changes: 6 additions & 0 deletions lib/msf/core/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ def preserves_stack?
false
end

#
# The amount of space available to the encoder, which may be nil,
# indicating that the smallest possible encoding should be used.
#
attr_accessor :available_space

protected

#
Expand Down
6 changes: 6 additions & 0 deletions lib/msf/core/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ def on_session(session)
#
attr_accessor :assoc_exploit

#
# The amount of space available to the payload, which may be nil,
# indicating that the smallest possible payload should be used.
#
attr_accessor :available_space

protected

#
Expand Down
9 changes: 6 additions & 3 deletions lib/msf/core/payload_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def encode_payload(shellcode)
encoder_list.each do |encoder_mod|
cli_print "Attempting to encode payload with #{iterations} iterations of #{encoder_mod.refname}"
begin
encoder_mod.available_space = @space
return run_encoder(encoder_mod, shellcode.dup)
rescue ::Msf::EncoderSpaceViolation => e
cli_print "#{encoder_mod.refname} failed with #{e.message}"
Expand Down Expand Up @@ -298,9 +299,11 @@ def generate_raw_payload
end

payload_module.generate_simple(
'Format' => 'raw',
'Options' => datastore,
'Encoder' => nil
'Format' => 'raw',
'Options' => datastore,
'Encoder' => nil,
'MaxSize' => @space,
'DisableNops' => true
)
end
end
Expand Down

0 comments on commit 6031791

Please sign in to comment.