Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/encoders/x86/alpha_upper.rb
Views: 11777
##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{26'BlockSize' => 1,27})28end2930#31# Returns the decoder stub that is adjusted for the size of the buffer32# being encoded.33#34def decoder_stub(state)35modified_registers = []36reg = datastore['BufferRegister']37off = (datastore['BufferOffset'] || 0).to_i38buf = ''3940# We need to create a GetEIP stub for the exploit41if (not reg)42if(datastore['AllowWin32SEH'] and datastore['AllowWin32SEH'].to_s =~ /^(t|y|1)/i)43buf = 'VTX630WTX638VXH49HHHPVX5AAQQPVX5YYYYP5YYYD5KKYAPTTX638TDDNVDDX4Z4A63861816'44reg = 'ECX'45off = 046modified_registers.concat (47[48Rex::Arch::X86::ESP,49Rex::Arch::X86::EDI,50Rex::Arch::X86::ESI,51Rex::Arch::X86::EAX52])53else54res = Rex::Arch::X86.geteip_fpu(state.badchars, modified_registers)55if (not res)56raise EncodingError, "Unable to generate geteip code"57end58buf, reg, off = res59end60else61reg.upcase!62end6364stub = buf + Rex::Encoder::Alpha2::AlphaUpper::gen_decoder(reg, off, modified_registers)6566# Sanity check that saved_registers doesn't overlap with modified_registers67modified_registers.uniq!68if (modified_registers & saved_registers).length > 069raise BadGenerateError70end7172stub73end7475#76# Encodes a one byte block with the current index of the length of the77# payload.78#79def encode_block(state, block)80return Rex::Encoder::Alpha2::AlphaUpper::encode_byte(block.unpack('C')[0], state.badchars)81end8283#84# Tack on our terminator85#86def encode_end(state)87state.encoded += Rex::Encoder::Alpha2::AlphaUpper::add_terminator()88end8990# Indicate that this module can preserve some registers91def can_preserve_registers?92true93end9495# Convert the SaveRegisters to an array of x86 register constants96def saved_registers97Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters'])98end99end100101102