2009-08-23 23:47:33 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2009-08-23 23:47:33 +00:00
|
|
|
##
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Encoder::Xor
|
2009-08-23 23:47:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'XOR Encoder',
|
|
|
|
'Description' => 'An x64 XOR encoder. Uses an 8 byte key and takes advantage of x64 relative addressing.',
|
|
|
|
'Author' => [ 'sf' ],
|
2016-10-27 21:16:05 +00:00
|
|
|
'Arch' => ARCH_X64,
|
2013-08-30 21:28:54 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Decoder' =>
|
|
|
|
{
|
|
|
|
'KeySize' => 8,
|
|
|
|
'KeyPack' => 'Q',
|
|
|
|
'BlockSize' => 8,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2016-08-30 01:59:39 +00:00
|
|
|
# Indicate that this module can preserve some registers
|
|
|
|
# ...which is currently not true. This is a temp fix
|
|
|
|
# until the full preserve_registers functionality is
|
2016-09-30 19:30:31 +00:00
|
|
|
# implemented.
|
2016-08-30 01:59:39 +00:00
|
|
|
def can_preserve_registers?
|
|
|
|
true
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
def decoder_stub( state )
|
|
|
|
|
|
|
|
# calculate the (negative) block count . We should check this against state.badchars.
|
|
|
|
block_count = [-( ( (state.buf.length - 1) / state.decoder_key_size) + 1)].pack( "V" )
|
|
|
|
|
|
|
|
decoder = "\x48\x31\xC9" + # xor rcx, rcx
|
|
|
|
"\x48\x81\xE9" + block_count + # sub ecx, block_count
|
|
|
|
"\x48\x8D\x05\xEF\xFF\xFF\xFF" + # lea rax, [rel 0x0]
|
|
|
|
"\x48\xBBXXXXXXXX" + # mov rbx, 0x????????????????
|
|
|
|
"\x48\x31\x58\x27" + # xor [rax+0x27], rbx
|
|
|
|
"\x48\x2D\xF8\xFF\xFF\xFF" + # sub rax, -8
|
|
|
|
"\xE2\xF4" # loop 0x1B
|
|
|
|
|
|
|
|
state.decoder_key_offset = decoder.index( 'XXXXXXXX' )
|
|
|
|
|
|
|
|
return decoder
|
|
|
|
end
|
2009-09-27 21:30:45 +00:00
|
|
|
end
|