Class: Rex::Encoder::Alpha2::UnicodeMixed

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

Class Method Summary collapse

Methods inherited from Generic

add_terminator, default_accepted_chars, encode, encode_byte

Class Method Details

.gen_decoder(reg, offset) ⇒ Object


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
# File 'lib/rex/encoder/alpha2/unicode_mixed.rb', line 49

def self.gen_decoder(reg, offset)
  decoder =
    gen_decoder_prefix(reg, offset) +
    "j" +               # push 0
    "XA" +              # pop eax, NOP
    "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
    "IA" +              # dec ecx, NOP
    "hAAA" +            # push 00410041, NOP
    "Z" +               # pop edx
    "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
    "BA" +              # inc 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], dh
    "I" +               # dec ecx
    "1" +               # add [ecx], dh
    "1" +               # add [ecx], dh
    "1A" +              # add [ecx], dh NOP
    "IA" +              # dec ecx, NOP
    "J" +               # dec edx
    "Q" +               # add [ecx], dl
    "YA" +              # pop ecx, NOP
    "Z" +               # pop edx
    "B" +               # add [edx], al
    "A" +               # inc ecx       <-------
    "B" +               # add [edx], al         |
    "A" +               # inc ecx               |
    "B" +               # add [edx], al         |
    "A" +               # inc ecx               |
    "B" +               # add [edx], al         |
    "A" +               # inc ecx               |
    "B" +               # add [edx], al         |
    "kM" +              # imul eax, [eax], 10 * |
    "A" +               # add [edx], al         |
    "G" +               # inc edi               |
    "B" +               # add [edx], al         |
    "9" +               # cmp [eax], eax        |
    "u" +               # jnz ------------------
    "4JB"

  return decoder
end

.gen_decoder_prefix(reg, offset) ⇒ Object


16
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
47
# File 'lib/rex/encoder/alpha2/unicode_mixed.rb', line 16

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

  # offset untested for unicode :(
  if (offset <= 14)
    nop = 'CP' * offset
    mod = 'IA' * (14 - offset) + nop    # dec ecx,,, push ecx, pop edx
  else
    mod = 'AA' * (offset - 14)			# inc ecx
    nop = 'CP' * (14 - 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
  }

  prefix = regprefix[reg.upcase]
  if prefix.nil?
    raise "Critical: Invalid register"
  end

  return prefix
end

.gen_second(block, base) ⇒ Object


11
12
13
14
# File 'lib/rex/encoder/alpha2/unicode_mixed.rb', line 11

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