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/php/hex.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Encoder6Rank = GreatRanking78def initialize9super(10'Name' => 'PHP Hex Encoder',11'Description' => %q{12This encoder returns a hex string encapsulated in13eval(hex2bin()), increasing the size by a bit more than14a factor two.15},16'Author' => 'Julien Voisin',17'License' => BSD_LICENSE,18'Arch' => ARCH_PHP)19register_options(20[21OptBool.new('Compress', [ true, 'Compress the payload with zlib', false ]) # Disabled by default as it relies on having php compiled with zlib, which might not be available on come exotic setups.22],23self.class24)25end2627def encode_block(state, buf)28# Have to have these for the decoder stub, so if they're not available,29# there's nothing we can do here.30%w[e v a l h e x 2 b i n ( ) ;].uniq.each do |c|31raise BadcharError if state.badchars.include?(c)32end3334if datastore['Compress']35%w[g z u n c o m p r e s s].uniq.each do |c|36raise BadcharError if state.badchars.include?(c)37end38end3940# Modern versions of PHP choke on unquoted literal strings.41quote = "'"42if state.badchars.include?("'")43raise BadcharError.new, "The #{name} encoder failed to encode the decoder stub without bad characters." if state.badchars.include?('"')4445quote = '"'46end4748if datastore['Compress']49buf = Zlib::Deflate.deflate(buf)50end5152hex = buf.unpack1('H*')5354state.badchars.each_byte do |byte|55# Last ditch effort, if any of the normal characters used by hex56# are badchars, try to replace them with something that will become57# the appropriate thing on the other side.58next unless hex.include?(byte.chr)5960%w[c h r ( ) .].uniq.each do |c|61raise BadcharError if state.badchars.include?(c)62end63hex.gsub!(byte.chr, "#{quote}.chr(#{byte}).#{quote}")64end6566if datastore['Compress']67return 'eval(gzuncompress(hex2bin(' + quote + hex + quote + ')));'68else69return 'eval(hex2bin(' + quote + hex + quote + '));'70end71end72end737475