Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/encoders/x86/unicode_mixed.rb
19567 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
require 'rex/encoder/alpha2/unicode_mixed'
7
8
class MetasploitModule < Msf::Encoder::Alphanum
9
Rank = ManualRanking
10
11
def initialize
12
super(
13
'Name' => 'Alpha2 Alphanumeric Unicode Mixedcase Encoder',
14
'Description' => %q{
15
Encodes payload as unicode-safe mixedcase text. This encoder uses
16
SkyLined's Alpha2 encoding suite.
17
},
18
'Author' => [ 'pusscat', 'skylined' ],
19
'Arch' => ARCH_X86,
20
'License' => BSD_LICENSE,
21
'EncoderType' => Msf::Encoder::Type::AlphanumUnicodeMixed,
22
'Decoder' => {
23
'BlockSize' => 1
24
})
25
register_options(
26
[
27
OptString.new('BufferRegister', [true, 'The register that points to the encoded payload', 'ECX'])
28
]
29
)
30
end
31
32
#
33
# Returns the decoder stub that is adjusted for the size of the buffer
34
# being encoded.
35
#
36
def decoder_stub(_state)
37
reg = datastore['BufferRegister']
38
offset = datastore['BufferOffset'].to_i || 0
39
if !reg
40
raise EncodingError, 'Need BufferRegister'
41
end
42
43
Rex::Encoder::Alpha2::UnicodeMixed.gen_decoder(reg, offset)
44
end
45
46
#
47
# Encodes a one byte block with the current index of the length of the
48
# payload.
49
#
50
def encode_block(state, block)
51
Rex::Encoder::Alpha2::UnicodeMixed.encode_byte(block.unpack1('C'), state.badchars)
52
end
53
54
#
55
# Tack on our terminator
56
#
57
def encode_end(state)
58
state.encoded += Rex::Encoder::Alpha2::UnicodeMixed.add_terminator
59
end
60
61
#
62
# Returns the unicode version of the supplied buffer.
63
#
64
def to_native(buffer)
65
Rex::Text.to_unicode(buffer)
66
end
67
end
68
69