Class: Rex::Encoder::Alpha2::Generic
- Inherits:
-
Object
- Object
- Rex::Encoder::Alpha2::Generic
show all
- Defined in:
- lib/rex/encoder/alpha2/generic.rb
Class Method Summary
collapse
Class Method Details
.add_terminator ⇒ Object
‘A’ signifies the end of the encoded shellcode
86
87
88
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 86
def Generic.add_terminator()
'AA'
end
|
.default_accepted_chars ⇒ Object
Note: ‘A’ is presumed to be accepted, but excluded from the accepted characters, because it serves as the terminator
13
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 13
def Generic.default_accepted_chars ; ('a' .. 'z').to_a + ('B' .. 'Z').to_a + ('0' .. '9').to_a ; end
|
.encode(buf, reg, offset, badchars = '') ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 71
def Generic.encode(buf, reg, offset, badchars = '')
encoded = gen_decoder(reg, offset)
buf.each_byte {
|block|
encoded << encode_byte(block, badchars)
}
encoded << add_terminator()
return encoded
end
|
.encode_byte(block, badchars) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 32
def Generic.encode_byte(block, badchars)
accepted_chars = default_accepted_chars.dup
badchars.each_char {|c| accepted_chars.delete(c) } if badchars
nibble_chars = Array.new(0x10) {[]}
accepted_chars.each {|c| nibble_chars[c.unpack('C')[0] & 0x0F].push(c) }
poss_encodings = []
block_low_nibble = block & 0x0F
block_high_nibble = block >> 4
first_chars = nibble_chars[block_low_nibble]
first_chars.each do |first_char|
first_high_nibble = first_char.unpack('C')[0] >> 4
second_low_nibble = gen_second(block_high_nibble, first_high_nibble) & 0x0F
second_chars = nibble_chars[second_low_nibble]
second_chars.each {|second_char| poss_encodings.push(second_char + first_char) }
end
if poss_encodings.empty?
raise RuntimeError, "No encoding of #{"0x%.2X" % block} possible with limited character set"
end
poss_encodings[rand(poss_encodings.length)]
end
|
.gen_decoder(reg, offset) ⇒ Object
22
23
24
25
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 22
def Generic.gen_decoder(reg, offset)
return ''
end
|
.gen_decoder_prefix(reg, offset) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 15
def Generic.gen_decoder_prefix(reg, offset)
''
end
|
.gen_second(block, base) ⇒ Object
27
28
29
30
|
# File 'lib/rex/encoder/alpha2/generic.rb', line 27
def Generic.gen_second(block, base)
(block^base)
end
|