2006-01-06 00:57:14 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'rex/encoder/alpha2/generic'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Encoder
|
|
|
|
module Alpha2
|
|
|
|
|
|
|
|
class AlphaMixed < Generic
|
|
|
|
|
|
|
|
def self.gen_decoder_prefix(reg, offset)
|
2009-11-08 19:42:58 +00:00
|
|
|
if (offset > 32)
|
|
|
|
raise "Critical: Offset is greater than 32"
|
2006-01-06 00:57:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# use inc ebx as a nop here so we still pad correctly
|
2006-01-24 23:08:20 +00:00
|
|
|
if (offset <= 16)
|
|
|
|
nop = 'C' * offset
|
|
|
|
mod = 'I' * (16 - offset) + nop + '7QZ' # dec ecx,,, push ecx, pop edx
|
|
|
|
edxmod = 'J' * (17 - offset)
|
|
|
|
else
|
|
|
|
mod = 'A' * (offset - 16)
|
|
|
|
nop = 'C' * (16 - mod.length)
|
2009-03-08 07:55:47 +00:00
|
|
|
mod << nop + '7QZ'
|
2006-01-24 23:08:20 +00:00
|
|
|
edxmod = 'B' * (17 - (offset - 16))
|
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
regprefix = {
|
2006-01-24 23:08:20 +00:00
|
|
|
'EAX' => 'PY' + mod, # push eax, pop ecx
|
|
|
|
'ECX' => 'I' + mod, # dec ecx
|
|
|
|
'EDX' => edxmod + nop + '7RY', # dec edx,,, push edx, pop ecx
|
|
|
|
'EBX' => 'SY' + mod, # push ebx, pop ecx
|
|
|
|
'ESP' => 'TY' + mod, # push esp, pop ecx
|
|
|
|
'EBP' => 'UY' + mod, # push ebp, pop ecx
|
|
|
|
'ESI' => 'VY' + mod, # push esi, pop ecx
|
|
|
|
'EDI' => 'WY' + mod, # push edi, pop ecx
|
2006-01-06 00:57:14 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 19:42:58 +00:00
|
|
|
reg.upcase!
|
|
|
|
if (not regprefix.keys.include? reg)
|
|
|
|
raise ArgumentError.new("Invalid register name")
|
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
return regprefix[reg]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.gen_decoder(reg, offset)
|
|
|
|
decoder =
|
|
|
|
gen_decoder_prefix(reg, offset) +
|
|
|
|
"jA" + # push 0x41
|
|
|
|
"X" + # pop eax
|
|
|
|
"P" + # push eax
|
2006-04-20 15:07:10 +00:00
|
|
|
"0A0" + # xor byte [ecx+30], al
|
2006-01-06 00:57:14 +00:00
|
|
|
"A" + # inc ecx <---
|
|
|
|
"kAAQ" + # imul eax, [ecx+42], 51 -> 10 |
|
|
|
|
"2AB" + # xor al, [ecx + 42] |
|
|
|
|
"2BB" + # xor al, [edx + 42] |
|
|
|
|
"0BB" + # xor [edx + 42], al |
|
|
|
|
"A" + # inc ecx |
|
|
|
|
"B" + # inc edx |
|
|
|
|
"X" + # pop eax |
|
|
|
|
"P" + # push eax |
|
|
|
|
"8AB" + # cmp [ecx + 42], al |
|
|
|
|
"uJ" + # jnz short -------------------------
|
|
|
|
"I" # first encoded char, fixes the above J
|
|
|
|
|
|
|
|
return decoder
|
|
|
|
end
|
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
end end end end
|