2007-02-18 00:10:39 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2005-10-31 18:50:58 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Encoder::Xor
|
2005-10-31 18:50:58 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'Single-byte XOR Countdown Encoder',
|
|
|
|
'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,
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Decoder' =>
|
|
|
|
{
|
|
|
|
'BlockSize' => 1,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the decoder stub that is adjusted for the size of the buffer
|
|
|
|
# being encoded.
|
|
|
|
#
|
|
|
|
def decoder_stub(state)
|
2014-09-11 01:21:35 +00:00
|
|
|
|
|
|
|
# Sanity check that saved_registers doesn't overlap with modified_registers
|
|
|
|
if (modified_registers & saved_registers).length > 0
|
|
|
|
raise BadGenerateError
|
|
|
|
end
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
decoder =
|
|
|
|
Rex::Arch::X86.set(
|
|
|
|
Rex::Arch::X86::ECX,
|
|
|
|
state.buf.length - 1,
|
|
|
|
state.badchars) +
|
2014-09-11 01:21:35 +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
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
# Initialize the state context to 1
|
|
|
|
state.context = 1
|
|
|
|
|
|
|
|
return decoder
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Encodes a one byte block with the current index of the length of the
|
|
|
|
# payload.
|
|
|
|
#
|
|
|
|
def encode_block(state, block)
|
|
|
|
state.context += 1
|
|
|
|
|
|
|
|
[ block.unpack('C')[0] ^ (state.context - 1) ].pack('C')
|
|
|
|
end
|
2005-10-31 18:50:58 +00:00
|
|
|
|
2014-09-11 01:21:35 +00:00
|
|
|
# Indicate that this module can preserve some registers
|
2014-10-06 21:33:21 +00:00
|
|
|
def can_preserve_registers?
|
2014-09-11 01:21:35 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# A list of registers always touched by this encoder
|
|
|
|
def modified_registers
|
|
|
|
[ Rex::Arch::X86::ECX, Rex::Arch::X86::ESI ]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Convert the SaveRegisters to an array of x86 register constants
|
|
|
|
def saved_registers
|
|
|
|
Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters'])
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|