2005-06-09 20:20:08 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-07-09 21:57:37 +00:00
|
|
|
require 'rex/encoder/xor/dword_additive'
|
2005-06-09 20:20:08 +00:00
|
|
|
|
|
|
|
#
|
2005-07-09 22:02:57 +00:00
|
|
|
# Jmp/Call Dword Additive Feedback Encoder
|
2005-06-09 20:20:08 +00:00
|
|
|
# Author: skape
|
|
|
|
# Arch: x86
|
|
|
|
#
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Encoders
|
|
|
|
|
2005-07-09 21:57:37 +00:00
|
|
|
class XorDwordAdditive < Rex::Encoder::Xor::DwordAdditive
|
2005-06-09 20:20:08 +00:00
|
|
|
module Backend
|
|
|
|
|
|
|
|
def _unencoded_transform(data)
|
2005-06-09 20:56:15 +00:00
|
|
|
# check for any dword aligned zeros that would falsely terminate the decoder
|
|
|
|
idx = 0
|
|
|
|
while true
|
|
|
|
idx = data.index("\x00\x00\x00\x00", idx)
|
|
|
|
break if !idx
|
|
|
|
if idx & 3 == 0
|
|
|
|
raise RuntimeError, "Unencoded data cannot have a dword aligned 0 dword!", caller()
|
|
|
|
end
|
|
|
|
idx += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# pad to a dword boundary and append null dword for termination
|
2005-06-09 20:20:08 +00:00
|
|
|
data = data + ("\x00" * ((4 - data.length & 3) & 3)) + "\x00\x00\x00\x00"
|
|
|
|
end
|
|
|
|
|
|
|
|
def _prepend
|
|
|
|
"\xfc" + # cld
|
|
|
|
"\xbb" + key + # mov ebx, key
|
|
|
|
"\xeb\x0c" + # jmp short 0x14
|
|
|
|
"\x5e" + # pop esi
|
|
|
|
"\x56" + # push esi
|
|
|
|
"\x31\x1e" + # xor [esi], ebx
|
|
|
|
"\xad" + # lodsd
|
|
|
|
"\x01\xc3" + # add ebx, eax
|
|
|
|
"\x85\xc0" + # test eax, eax
|
|
|
|
"\x75\xf7" + # jnz 0xa
|
|
|
|
"\xc3" + # ret
|
|
|
|
"\xe8\xef\xff\xff\xff" # call 0x8
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
include Backend
|
|
|
|
end
|
|
|
|
|
|
|
|
end end
|