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/test/tests/test_encoders.rb
Views: 11766
#1# Simple script to test a group of encoders against every exploit in the framework,2# specifically for the exploits badchars, to see if a payload can be encoded. We ignore3# the target arch/platform of the exploit as we just want to pull out real world bad chars.4#56msfbase = __FILE__7while File.symlink?(msfbase)8msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))9end1011$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))1213require 'msfenv'1415$msf = Msf::Simple::Framework.create1617EXPLOITS = $msf.exploits1819def print_line(message)20$stdout.puts(message)21end2223def format_badchars(badchars)24str = ''25if (badchars)26badchars.each_byte do |b|27str << "\\x%02X" % [ b ]28end29end30str31end3233def encoder_v_payload(encoder_name, payload, verbose = false)34success = 035fail = 036EXPLOITS.each_module do |name, mod|37exploit = mod.new38print_line("\n#{encoder_name} v #{name} (#{format_badchars(exploit.payload_badchars)})") if verbose39begin40encoder = $msf.encoders.create(encoder_name)41raw = encoder.encode(payload, exploit.payload_badchars, nil, nil)42success += 143rescue44print_line(" FAILED! badchars=#{format_badchars(exploit.payload_badchars)}\n") if verbose45fail += 146end47end48return [ success, fail ]49end5051def generate_payload(name)52payload = $msf.payloads.create(name)5354# set options for a reverse_tcp payload55payload.datastore['LHOST'] = '192.168.2.1'56payload.datastore['RHOST'] = '192.168.2.254'57payload.datastore['RPORT'] = '5432'58payload.datastore['LPORT'] = '4444'59# set options for an exec payload60payload.datastore['CMD'] = 'calc'61# set generic options62payload.datastore['EXITFUNC'] = 'thread'6364return payload.generate65end6667def run(encoders, payload_name, verbose = false)68payload = generate_payload(payload_name)6970table = Rex::Text::Table.new(71'Header' => 'Encoder v Payload Test - ' + ::Time.new.strftime("%d-%b-%Y %H:%M:%S"),72'Indent' => 4,73'Columns' => [ 'Encoder Name', 'Success', 'Fail' ]74)7576encoders.each do |encoder_name|77success, fail = encoder_v_payload(encoder_name, payload, verbose)7879table << [ encoder_name, success, fail ]80end8182return table83end8485if ($0 == __FILE__)8687print_line("[+] Starting.\n")8889encoders = [90'x86/bloxor',91'x86/shikata_ga_nai',92'x86/jmp_call_additive',93'x86/fnstenv_mov',94'x86/countdown',95'x86/call4_dword_xor'96]9798payload_name = 'windows/shell/reverse_tcp'99100verbose = false101102result_table = run(encoders, payload_name, verbose)103104print_line("\n\n#{result_table.to_s}\n\n")105106print_line("[+] Finished.\n")107end108109110