CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/encoders/x86/unicode_mixed.rb
Views: 11780
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
{
24
'BlockSize' => 1
25
})
26
register_options(
27
[
28
OptString.new('BufferRegister', [true, 'The register that points to the encoded payload', 'ECX'])
29
]
30
)
31
end
32
33
#
34
# Returns the decoder stub that is adjusted for the size of the buffer
35
# being encoded.
36
#
37
def decoder_stub(_state)
38
reg = datastore['BufferRegister']
39
offset = datastore['BufferOffset'].to_i || 0
40
if !reg
41
raise EncodingError, 'Need BufferRegister'
42
end
43
44
Rex::Encoder::Alpha2::UnicodeMixed.gen_decoder(reg, offset)
45
end
46
47
#
48
# Encodes a one byte block with the current index of the length of the
49
# payload.
50
#
51
def encode_block(state, block)
52
Rex::Encoder::Alpha2::UnicodeMixed.encode_byte(block.unpack1('C'), state.badchars)
53
end
54
55
#
56
# Tack on our terminator
57
#
58
def encode_end(state)
59
state.encoded += Rex::Encoder::Alpha2::UnicodeMixed.add_terminator
60
end
61
62
#
63
# Returns the unicode version of the supplied buffer.
64
#
65
def to_native(buffer)
66
Rex::Text.to_unicode(buffer)
67
end
68
end
69
70