2007-02-18 00:10:39 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2006-01-06 00:57:14 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'rex/encoder/alpha2/alpha_upper'
|
|
|
|
|
|
|
|
|
2016-03-07 08:56:58 +00:00
|
|
|
class Metasploit < Msf::Encoder::Alphanum
|
2006-01-06 02:25:23 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
Rank = LowRanking
|
2006-01-06 00:57:14 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => "Alpha2 Alphanumeric Uppercase Encoder",
|
|
|
|
'Description' => %q{
|
|
|
|
Encodes payloads as alphanumeric uppercase text. This encoder uses
|
|
|
|
SkyLined's Alpha2 encoding suite.
|
|
|
|
},
|
|
|
|
'Author' => [ 'pusscat', 'skylined' ],
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
'EncoderType' => Msf::Encoder::Type::AlphanumUpper,
|
|
|
|
'Decoder' =>
|
|
|
|
{
|
|
|
|
'BlockSize' => 1,
|
|
|
|
})
|
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#
|
|
|
|
# Returns the decoder stub that is adjusted for the size of the buffer
|
|
|
|
# being encoded.
|
|
|
|
#
|
|
|
|
def decoder_stub(state)
|
2015-06-08 19:35:48 +00:00
|
|
|
modified_registers = []
|
2013-08-30 21:28:54 +00:00
|
|
|
reg = datastore['BufferRegister']
|
|
|
|
off = (datastore['BufferOffset'] || 0).to_i
|
|
|
|
buf = ''
|
2009-11-08 00:45:51 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# We need to create a GetEIP stub for the exploit
|
|
|
|
if (not reg)
|
|
|
|
if(datastore['AllowWin32SEH'] and datastore['AllowWin32SEH'].to_s =~ /^(t|y|1)/i)
|
|
|
|
buf = 'VTX630WTX638VXH49HHHPVX5AAQQPVX5YYYYP5YYYD5KKYAPTTX638TDDNVDDX4Z4A63861816'
|
|
|
|
reg = 'ECX'
|
|
|
|
off = 0
|
2015-06-08 19:35:48 +00:00
|
|
|
modified_registers.concat (
|
|
|
|
[
|
|
|
|
Rex::Arch::X86::ESP,
|
|
|
|
Rex::Arch::X86::EDI,
|
|
|
|
Rex::Arch::X86::ESI,
|
|
|
|
Rex::Arch::X86::EAX
|
|
|
|
])
|
2013-08-30 21:28:54 +00:00
|
|
|
else
|
2015-06-08 19:35:48 +00:00
|
|
|
res = Rex::Arch::X86.geteip_fpu(state.badchars, modified_registers)
|
2013-08-30 21:28:54 +00:00
|
|
|
if (not res)
|
2015-05-18 20:33:01 +00:00
|
|
|
raise EncodingError, "Unable to generate geteip code"
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
buf, reg, off = res
|
|
|
|
end
|
|
|
|
else
|
|
|
|
reg.upcase!
|
|
|
|
end
|
2006-09-10 05:10:48 +00:00
|
|
|
|
2015-06-08 19:35:48 +00:00
|
|
|
stub = buf + Rex::Encoder::Alpha2::AlphaUpper::gen_decoder(reg, off, modified_registers)
|
|
|
|
|
|
|
|
# Sanity check that saved_registers doesn't overlap with modified_registers
|
|
|
|
modified_registers.uniq!
|
|
|
|
if (modified_registers & saved_registers).length > 0
|
|
|
|
raise BadGenerateError
|
|
|
|
end
|
|
|
|
|
|
|
|
stub
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#
|
|
|
|
# Encodes a one byte block with the current index of the length of the
|
|
|
|
# payload.
|
|
|
|
#
|
|
|
|
def encode_block(state, block)
|
|
|
|
return Rex::Encoder::Alpha2::AlphaUpper::encode_byte(block.unpack('C')[0], state.badchars)
|
|
|
|
end
|
2006-01-06 00:57:14 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#
|
|
|
|
# Tack on our terminator
|
|
|
|
#
|
|
|
|
def encode_end(state)
|
|
|
|
state.encoded += Rex::Encoder::Alpha2::AlphaUpper::add_terminator()
|
|
|
|
end
|
2015-06-08 19:35:48 +00:00
|
|
|
|
|
|
|
# Indicate that this module can preserve some registers
|
|
|
|
def can_preserve_registers?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Convert the SaveRegisters to an array of x86 register constants
|
|
|
|
def saved_registers
|
|
|
|
Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters'])
|
|
|
|
end
|
2009-11-08 00:45:51 +00:00
|
|
|
end
|