Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/encoders/x86/nonalpha.rb
19664 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/nonalpha'
7
8
class MetasploitModule < Msf::Encoder::NonAlpha
9
Rank = LowRanking
10
11
def initialize
12
super(
13
'Name' => 'Non-Alpha Encoder',
14
'Description' => %q{
15
Encodes payloads as non-alpha based bytes. This allows
16
payloads to bypass both toupper() and tolower() calls,
17
but will fail isalpha(). Table based design from
18
Russel Sanford.
19
},
20
'Author' => [ 'pusscat'],
21
'Arch' => ARCH_X86,
22
'License' => BSD_LICENSE,
23
'EncoderType' => Msf::Encoder::Type::NonAlpha,
24
'Decoder' => {
25
'BlockSize' => 1
26
})
27
end
28
29
#
30
# Returns the decoder stub that is adjusted for the size of the buffer
31
# being encoded.
32
#
33
def decoder_stub(state)
34
state.key = ''
35
state.decoder_key_size = 0
36
Rex::Encoder::NonAlpha.gen_decoder
37
end
38
39
#
40
# Encodes a one byte block with the current index of the length of the
41
# payload.
42
#
43
def encode_block(state, block)
44
begin
45
newchar, state.key, state.decoder_key_size = Rex::Encoder::NonAlpha.encode_byte(block.unpack('C')[0], state.key, state.decoder_key_size)
46
rescue RuntimeError => e
47
raise BadcharError if e.message == 'BadChar'
48
end
49
return newchar
50
end
51
52
#
53
# Fix stuff, and add the table :)
54
#
55
def encode_end(state)
56
state.encoded.gsub!(/A/, state.decoder_key_size.chr)
57
state.encoded.gsub!(/B/, (state.decoder_key_size + 5).chr)
58
state.encoded[0x24, 0] = state.key
59
end
60
end
61
62