Class: Rex::Encoder::Alpha2::UnicodeUpper

Inherits:
Generic
  • Object
show all
Defined in:
lib/rex/encoder/alpha2/unicode_upper.rb

Class Method Summary collapse

Methods inherited from Generic

add_terminator, encode, encode_byte

Class Method Details

.default_accepted_charsObject



10
# File 'lib/rex/encoder/alpha2/unicode_upper.rb', line 10

def self.default_accepted_chars ; ('B' .. 'Z').to_a + ('0' .. '9').to_a ; end

.gen_decoder(reg, offset) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rex/encoder/alpha2/unicode_upper.rb', line 48

def self.gen_decoder(reg, offset)
  decoder =
    gen_decoder_prefix(reg, offset) +
    "QA" +                  # push ecx, NOP
    "TA" +                  # push esp, NOP
    "XA" +                  # pop eax, NOP
    "ZA" +                  # pop edx, NOP
    "PU" +                  # push eax, NOP
    "3" +                   # xor eax, [eax]
    "QA" +                  # push ecx, NOP
    "DA" +                  # inc esp, NOP
    "ZA" +                  # pop edx, NOP
    "BA" +                  # inc edx, NOP
    "RA" +                  # push edx, NOP
    "LA" +                  # dec esp, NOP
    "YA" +                  # pop ecx, NOP
    "IA" +                  # dec ecx, NOP
    "QA" +                  # push ecx, NOP
    "IA" +                  # dec ecx, NOP
    "QA" +                  # push ecx, NOP
    "PA" +                  # push eax, NOP
    "5AAA" +                # xor eax, 41004100 - NOP
    "PA" +                  # push eax, NOP
    "Z" +                   # pop edx
    "1A" +                  # add [ecx], dh - NOP
    "I" +                   # dec ecx
    "1A" +                  # add [ecx], dh - NOP
    "IA" +                  # dec ecx, NOP
    "IA" +                  # dec ecx, NOP
    "J" +                   # dec edx
    "1" +                   # add [ecx], dh
    "1A" +                  # add [ecx], dh - NOP
    "IA" +                  # dec ecx, NOP
    "IA" +                  # dec ecx, NOP
    "XA" +                  # pop eax, NOP
    "58AA" +                # xor eax, 41003800 - NOP
    "PA" +                  # push eax, NOP
    "ZA" +                  # pop edx, NOP
    "BA" +                  # inc edx, NOP
    "B" +                   # inc edx
    "Q" +                   # add [ecx], dl
    "I" +                   # dec ecx
    "1A" +                  # add [ecx], dh - NOP
    "I" +                   # dec ecx
    "Q" +                   # add [ecx], dl
    "IA" +                  # dec ecx, NOP
    "I" +                   # dec ecx
    "Q" +                   # add [ecx], dl
    "I" +                   # dec ecx
    "1" +                   # add [ecx], dh
    "1" +                   # add [ecx], dh
    "1" +                   # add [ecx], dh
    "1A" +                  # add [ecx], dh - NOP
    "IA" +                  # dec ecx, NOP
    "J" +                   # dec edx
    "Q" +                   # add [ecx], dl
    "I" +                   # dec edx
    "1A" +                  # add [ecx], dh - NOP
    "YA" +                  # pop ecx, NOP
    "ZB" +                  # pop edx, NOP
    "AB" +                  # inc ecx, NOP      <-------
    "AB" +                  # inc ecx, NOP              |
    "AB" +                  # inc ecx, NOP              |
    "AB" +                  # inc ecx, NOP              |
    "30" +                  # imul eax, [ecx], 10 *     |
    "A" +                   # add al, [ecx+2] *         |
    "P" +                   # mov [edx], al *           |
    "B" +                   # inc edx                   |
    "9" +                   # cmp [ecx], 41 *           |
    "4" +                   # jnz   --------------------
    "4JB"

  return decoder
end

.gen_decoder_prefix(reg, offset) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rex/encoder/alpha2/unicode_upper.rb', line 17

def self.gen_decoder_prefix(reg, offset)
  if (offset > 6)
    raise "Critical: Offset is greater than 6"
  end

  # offset untested for unicode :(
  if (offset <= 4)
    nop = 'CP' * offset
    mod = 'IA' * (4 - offset) + nop    # dec ecx,,, push ecx, pop edx
  else
    mod = 'AA' * (offset - 4)          # inc ecx
    nop = 'CP' * (4 - mod.length)
    mod += nop
  end

  regprefix = {                      # nops ignored below
    'EAX'   => 'PPYA' + mod,        # push eax, pop ecx
    'ECX'   =>  mod + '4444',       # dec ecx
    'EDX'   => 'RRYA' + mod,        # push edx, pop ecx
    'EBX'   => 'SSYA' + mod,        # push ebx, pop ecx
    'ESP'   => 'TUYA' + mod,        # push esp, pop ecx
    'EBP'   => 'UUYA' + mod,        # push ebp, pop ecx
    'ESI'   => 'VVYA' + mod,        # push esi, pop ecx
    'EDI'   => 'WWYA' + mod,        # push edi, pop edi
    '[ESP]' => 'YA' + mod + '44',   #
    '[ESP+4]' => 'YUYA' + mod,      #
  }

  return regprefix[reg]
end

.gen_second(block, base) ⇒ Object



12
13
14
15
# File 'lib/rex/encoder/alpha2/unicode_upper.rb', line 12

def self.gen_second(block, base)
  # unicode uses additive encoding
  (block - base)
end