Path: blob/master/modules/encoders/x86/nonalpha.rb
19670 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'rex/encoder/nonalpha'67class MetasploitModule < Msf::Encoder::NonAlpha8Rank = LowRanking910def initialize11super(12'Name' => 'Non-Alpha Encoder',13'Description' => %q{14Encodes payloads as non-alpha based bytes. This allows15payloads to bypass both toupper() and tolower() calls,16but will fail isalpha(). Table based design from17Russel Sanford.18},19'Author' => [ 'pusscat'],20'Arch' => ARCH_X86,21'License' => BSD_LICENSE,22'EncoderType' => Msf::Encoder::Type::NonAlpha,23'Decoder' => {24'BlockSize' => 125})26end2728#29# Returns the decoder stub that is adjusted for the size of the buffer30# being encoded.31#32def decoder_stub(state)33state.key = ''34state.decoder_key_size = 035Rex::Encoder::NonAlpha.gen_decoder36end3738#39# Encodes a one byte block with the current index of the length of the40# payload.41#42def encode_block(state, block)43begin44newchar, state.key, state.decoder_key_size = Rex::Encoder::NonAlpha.encode_byte(block.unpack('C')[0], state.key, state.decoder_key_size)45rescue RuntimeError => e46raise BadcharError if e.message == 'BadChar'47end48return newchar49end5051#52# Fix stuff, and add the table :)53#54def encode_end(state)55state.encoded.gsub!(/A/, state.decoder_key_size.chr)56state.encoded.gsub!(/B/, (state.decoder_key_size + 5).chr)57state.encoded[0x24, 0] = state.key58end59end606162