Path: blob/master/modules/encoders/x86/alpha_upper.rb
19516 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'rex/encoder/alpha2/alpha_upper'67class MetasploitModule < Msf::Encoder::Alphanum8Rank = LowRanking910def initialize11super(12'Name' => 'Alpha2 Alphanumeric Uppercase Encoder',13'Description' => %q{14Encodes payloads as alphanumeric uppercase text. This encoder uses15SkyLined's Alpha2 encoding suite.16A pure alpha encoder is impossible without having a register that points at or near the shellcode.17In a default configuration the first few bytes at the beginning are an fnstenv getpc stub (the same as used in shikata_ga_nai) and thus are not alphanumeric.18You can set BufferRegister for full alpha (see Encoder options for details).19},20'Author' => [ 'pusscat', 'skylined' ],21'Arch' => ARCH_X86,22'License' => BSD_LICENSE,23'EncoderType' => Msf::Encoder::Type::AlphanumUpper,24'Decoder' => {25'BlockSize' => 126})27end2829#30# Returns the decoder stub that is adjusted for the size of the buffer31# being encoded.32#33def decoder_stub(state)34modified_registers = []35reg = datastore['BufferRegister']36off = (datastore['BufferOffset'] || 0).to_i37buf = ''3839# We need to create a GetEIP stub for the exploit40if !reg41if datastore['AllowWin32SEH'] && datastore['AllowWin32SEH'].to_s =~ (/^(t|y|1)/i)42buf = 'VTX630WTX638VXH49HHHPVX5AAQQPVX5YYYYP5YYYD5KKYAPTTX638TDDNVDDX4Z4A63861816'43reg = 'ECX'44off = 045modified_registers.concat(46[47Rex::Arch::X86::ESP,48Rex::Arch::X86::EDI,49Rex::Arch::X86::ESI,50Rex::Arch::X86::EAX51]52)53else54res = Rex::Arch::X86.geteip_fpu(state.badchars, modified_registers)55if !res56raise EncodingError, 'Unable to generate geteip code'57end5859buf, reg, off = res60end61else62reg.upcase!63end6465stub = buf + Rex::Encoder::Alpha2::AlphaUpper.gen_decoder(reg, off, modified_registers)6667# Sanity check that saved_registers doesn't overlap with modified_registers68modified_registers.uniq!69if !(modified_registers & saved_registers).empty?70raise BadGenerateError71end7273stub74end7576#77# Encodes a one byte block with the current index of the length of the78# payload.79#80def encode_block(state, block)81return Rex::Encoder::Alpha2::AlphaUpper.encode_byte(block.unpack('C')[0], state.badchars)82end8384#85# Tack on our terminator86#87def encode_end(state)88state.encoded += Rex::Encoder::Alpha2::AlphaUpper.add_terminator89end9091# Indicate that this module can preserve some registers92def can_preserve_registers?93true94end9596# Convert the SaveRegisters to an array of x86 register constants97def saved_registers98Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters'])99end100end101102103