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_mixed.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'rex/encoder/alpha2/alpha_mixed'67class MetasploitModule < Msf::Encoder::Alphanum8Rank = LowRanking910def initialize11super(12'Name' => "Alpha2 Alphanumeric Mixedcase Encoder",13'Description' => %q{14Encodes payloads as alphanumeric mixedcase 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::AlphanumMixed,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 = 'VTX630VXH49HHHPhYAAQhZYYYYAAQQDDDd36FFFFTXVj0PPTUPPa301089'44reg = 'ECX'45off = 046modified_registers.concat (47[48Rex::Arch::X86::ESP,49Rex::Arch::X86::EDI,50Rex::Arch::X86::ESI,51Rex::Arch::X86::EBP,52Rex::Arch::X86::EBX,53Rex::Arch::X86::EDX,54Rex::Arch::X86::ECX,55Rex::Arch::X86::EAX56])57else58res = Rex::Arch::X86.geteip_fpu(state.badchars, modified_registers)59if (not res)60raise EncodingError, "Unable to generate geteip code"61end62buf, reg, off = res63end64else65reg.upcase!66end6768stub = buf + Rex::Encoder::Alpha2::AlphaMixed::gen_decoder(reg, off, modified_registers)6970# Sanity check that saved_registers doesn't overlap with modified_registers71modified_registers.uniq!72if (modified_registers & saved_registers).length > 073raise BadGenerateError74end7576stub77end7879#80# Encodes a one byte block with the current index of the length of the81# payload.82#83def encode_block(state, block)84Rex::Encoder::Alpha2::AlphaMixed::encode_byte(block.unpack('C')[0], state.badchars)85end8687#88# Tack on our terminator89#90def encode_end(state)91state.encoded += Rex::Encoder::Alpha2::AlphaMixed::add_terminator()92end9394# Indicate that this module can preserve some registers95def can_preserve_registers?96true97end9899# Convert the SaveRegisters to an array of x86 register constants100def saved_registers101Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters'])102end103end104105106