2006-01-06 00:57:14 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'rex/encoder/alpha2/generic'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Encoder
|
|
|
|
module Alpha2
|
|
|
|
|
|
|
|
class AlphaUpper < Generic
|
2009-10-25 16:40:19 +00:00
|
|
|
def self.default_accepted_chars ; ('B' .. 'Z').to_a + ('0' .. '9').to_a ; end
|
2006-01-27 05:33:08 +00:00
|
|
|
|
2006-01-06 00:57:14 +00:00
|
|
|
def self.gen_decoder_prefix(reg, offset)
|
2006-01-24 23:08:20 +00:00
|
|
|
if (offset > 20)
|
2009-11-08 19:42:58 +00:00
|
|
|
raise "Critical: Offset is greater than 20"
|
2006-01-06 00:57:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# use inc ebx as a nop here so we still pad correctly
|
2006-01-27 05:33:08 +00:00
|
|
|
if (offset <= 10)
|
|
|
|
nop = 'C' * offset
|
2006-04-20 14:35:18 +00:00
|
|
|
mod = 'I' * (10 - offset) + nop + 'QZ' # dec ecx,,, push ecx, pop edx
|
2006-01-27 05:33:08 +00:00
|
|
|
edxmod = 'J' * (11 - offset)
|
|
|
|
else
|
|
|
|
mod = 'A' * (offset - 10)
|
|
|
|
nop = 'C' * (10 - mod.length)
|
2009-03-08 07:55:47 +00:00
|
|
|
mod << nop + 'QZ'
|
2006-01-27 05:33:08 +00:00
|
|
|
edxmod = 'B' * (11 - (offset - 10))
|
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
regprefix = {
|
2006-04-20 14:35:18 +00:00
|
|
|
'EAX' => 'PY' + mod, # push eax, pop ecx
|
|
|
|
'ECX' => 'I' + mod, # dec ecx
|
|
|
|
'EDX' => edxmod + nop + 'RY', # mod 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 edi
|
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]
|
|
|
|
|
2006-01-27 05:33:08 +00:00
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
|
|
|
|
def self.gen_decoder(reg, offset)
|
|
|
|
decoder =
|
|
|
|
gen_decoder_prefix(reg, offset) +
|
|
|
|
"V" + # push esi
|
|
|
|
"T" + # push esp
|
|
|
|
"X" + # pop eax
|
|
|
|
"30" + # xor esi, [eax]
|
|
|
|
"V" + # push esi
|
|
|
|
"X" + # pop eax
|
|
|
|
"4A" + # xor al, 41
|
|
|
|
"P" + # push eax
|
|
|
|
"0A3" + # xor [ecx+33], al
|
|
|
|
"H" + # dec eax
|
|
|
|
"H" + # dec eax
|
|
|
|
"0A0" + # xor [ecx+30], al
|
|
|
|
"0AB" + # xor [ecx+42], al
|
|
|
|
"A" + # inc ecx <---------------
|
|
|
|
"A" + # inc ecx |
|
|
|
|
"B" + # inc edx |
|
|
|
|
"TAAQ" + # imul eax, [ecx+41], 10 * |
|
|
|
|
"2AB" + # xor al [ecx+42] |
|
|
|
|
"2BB" + # xor al, [edx+42] |
|
|
|
|
"0BB" + # xor [edx+42], al |
|
|
|
|
"X" + # pop eax |
|
|
|
|
"P" + # push eax |
|
|
|
|
"8AC" + # cmp [ecx+43], al |
|
|
|
|
"JJ" + # jnz * --------------------
|
|
|
|
"I" # first encoded char, fixes the above J
|
|
|
|
|
|
|
|
return decoder
|
|
|
|
end
|
|
|
|
|
2009-03-08 07:55:47 +00:00
|
|
|
end end end end
|