2007-02-18 00:10:39 +00:00
|
|
|
##
|
2008-10-02 05:23:59 +00:00
|
|
|
# $Id$
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2006-05-08 15:04:50 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'rex/encoder/nonupper'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Encoder::NonUpper
|
2006-05-08 15:04:50 +00:00
|
|
|
|
|
|
|
Rank = LowRanking
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => "Non-Upper Encoder",
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => %q{
|
2009-12-21 23:05:44 +00:00
|
|
|
Encodes payloads as non-alpha based bytes. This allows
|
|
|
|
payloads to bypass tolower() calls, but will fail isalpha().
|
|
|
|
Table based design from Russel Sanford.
|
2006-05-08 15:04:50 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'pusscat'],
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
'EncoderType' => Msf::Encoder::Type::NonUpper,
|
|
|
|
'Decoder' =>
|
|
|
|
{
|
|
|
|
'BlockSize' => 1,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the decoder stub that is adjusted for the size of the buffer
|
|
|
|
# being encoded.
|
|
|
|
#
|
|
|
|
def decoder_stub(state)
|
2009-12-23 04:23:56 +00:00
|
|
|
state.key = ""
|
|
|
|
state.decoder_key_size = 0
|
2006-05-08 15:04:50 +00:00
|
|
|
Rex::Encoder::NonUpper::gen_decoder()
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Encodes a one byte block with the current index of the length of the
|
|
|
|
# payload.
|
|
|
|
#
|
|
|
|
def encode_block(state, block)
|
2009-09-28 05:23:23 +00:00
|
|
|
begin
|
2010-04-30 08:40:19 +00:00
|
|
|
newchar, state.key, state.decoder_key_size =
|
2009-09-28 05:23:23 +00:00
|
|
|
Rex::Encoder::NonUpper::encode_byte(datastore['badchars'], block.unpack('C')[0], state.key, state.decoder_key_size)
|
|
|
|
rescue RuntimeError => e
|
|
|
|
# This is a bandaid to deal with the fact that, since it's in
|
|
|
|
# the Rex namespace, the encoder itself doesn't have access to the
|
|
|
|
# Msf exception classes. Turn it into an actual EncodingError
|
|
|
|
# exception so the encoder doesn't look broken when it just fails
|
|
|
|
# to encode.
|
|
|
|
raise BadcharError if e.message == "BadChar"
|
|
|
|
end
|
2009-12-23 04:23:56 +00:00
|
|
|
return newchar
|
|
|
|
end
|
2006-05-08 15:04:50 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Fix stuff, and add the table :)
|
|
|
|
#
|
|
|
|
def encode_end(state)
|
2009-12-23 04:23:56 +00:00
|
|
|
state.encoded.gsub!(/A/, state.decoder_key_size.chr)
|
|
|
|
state.encoded.gsub!(/B/, (state.decoder_key_size+5).chr)
|
|
|
|
state.encoded[0x24, 0] = state.key
|
|
|
|
end
|
2009-09-28 05:23:23 +00:00
|
|
|
end
|