Permalink
Browse files

Land #10554, Rescue REX runtime errors in x86 encoders

  • Loading branch information...
jmartin-r7 committed Oct 10, 2018
2 parents 7f2aa8c + 93e9253 commit 6cdfbdd2817e28569b290110e02a9d6c31059043
Showing with 21 additions and 15 deletions.
  1. +16 −14 modules/encoders/x86/countdown.rb
  2. +5 −1 modules/encoders/x86/nonalpha.rb
@@ -31,21 +31,23 @@ def decoder_stub(state)
if (modified_registers & saved_registers).length > 0
raise BadGenerateError
end
begin
decoder =
Rex::Arch::X86.set(
Rex::Arch::X86::ECX,
state.buf.length - 1,
state.badchars) +
"\xe8\xff\xff\xff" + # call $+4
"\xff\xc1" + # inc ecx
"\x5e" + # pop esi
"\x30\x4c\x0e\x07" + # xor_loop: xor [esi + ecx + 0x07], cl
"\xe2\xfa" # loop xor_loop
decoder =
Rex::Arch::X86.set(
Rex::Arch::X86::ECX,
state.buf.length - 1,
state.badchars) +
"\xe8\xff\xff\xff" + # call $+4
"\xff\xc1" + # inc ecx
"\x5e" + # pop esi
"\x30\x4c\x0e\x07" + # xor_loop: xor [esi + ecx + 0x07], cl
"\xe2\xfa" # loop xor_loop
# Initialize the state context to 1
state.context = 1
# Initialize the state context to 1
state.context = 1
rescue RuntimeError => e
raise BadcharError if e.message == "No valid set instruction could be created!"
end
return decoder
end
@@ -42,7 +42,11 @@ def decoder_stub(state)
# payload.
#
def encode_block(state, block)
newchar, state.key, state.decoder_key_size = Rex::Encoder::NonAlpha::encode_byte(block.unpack('C')[0], state.key, state.decoder_key_size)
begin
newchar, state.key, state.decoder_key_size = Rex::Encoder::NonAlpha::encode_byte(block.unpack('C')[0], state.key, state.decoder_key_size)
rescue RuntimeError => e
raise BadcharError if e.message == "BadChar"
end
return newchar
end

0 comments on commit 6cdfbdd

Please sign in to comment.