2005-10-31 18:50:58 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Encoders
|
|
|
|
module X86
|
|
|
|
|
|
|
|
class Countdown < Msf::Encoder::Xor
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
2005-10-31 19:16:10 +00:00
|
|
|
'Name' => 'Single-byte XOR Countdown Encoder',
|
2005-10-31 18:50:58 +00:00
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => %q{
|
|
|
|
This encoder uses the length of the payload as a position-dependent
|
|
|
|
encoder key to produce a small decoder stub.
|
|
|
|
},
|
|
|
|
'Author' => 'vlad902',
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Decoder' =>
|
|
|
|
{
|
|
|
|
'BlockSize' => 1,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the decoder stub that is adjusted for the size of the buffer
|
|
|
|
# being encoded.
|
|
|
|
#
|
|
|
|
def decoder_stub(state)
|
|
|
|
decoder =
|
2005-11-01 00:48:40 +00:00
|
|
|
Rex::Arch::X86.set(
|
2005-10-31 18:50:58 +00:00
|
|
|
Rex::Arch::X86::ECX,
|
2005-11-01 00:48:40 +00:00
|
|
|
state.buf.length - 1,
|
2005-10-31 18:50:58 +00:00
|
|
|
state.badchars) +
|
2005-12-30 20:38:13 +00:00
|
|
|
"\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
|
2005-10-31 18:50:58 +00:00
|
|
|
|
|
|
|
# Initialize the state context to 1
|
|
|
|
state.context = 1
|
|
|
|
|
|
|
|
return decoder
|
|
|
|
end
|
|
|
|
|
2005-10-31 19:15:21 +00:00
|
|
|
#
|
|
|
|
# Encodes a one byte block with the current index of the length of the
|
|
|
|
# payload.
|
|
|
|
#
|
2005-10-31 18:50:58 +00:00
|
|
|
def encode_block(state, block)
|
|
|
|
state.context += 1
|
|
|
|
|
|
|
|
[ block.unpack('C')[0] ^ (state.context - 1) ].pack('C')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end end end
|