Path: blob/master/tools/exploit/random_compile_c.rb
19778 views
#!/usr/bin/env ruby1# -*- coding: binary -*-2def help3puts "Usage:"4puts "#{__FILE__} [weight] [source code path] [output path]"5puts6puts "Example:"7puts "#{__FILE__} 80 /tmp/helloworld.c /tmp/helloworld.exe"8exit9end1011help if ARGV.empty? || ARGV.include?('-h')12begin13msfbase = __FILE__14while File.symlink?(msfbase)15msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))16end17$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))18require 'msfenv'19require 'metasploit/framework/compiler/windows'2021weight = ARGV.shift22source_code_path = ARGV.shift23out_path = ARGV.shift2425if source_code_path.nil? || source_code_path.empty? || !File.exist?(source_code_path)26puts "Please set the source code path"27exit28elsif out_path.nil? || out_path.empty?29puts "Please set the destination path"30exit31end3233source_code = File.read(source_code_path)34Metasploit::Framework::Compiler::Windows.compile_random_c_to_file(out_path, source_code, weight: weight.to_i)35if File.exist?(out_path)36puts "File saved as #{out_path}"37end38rescue SignalException => e39puts("Aborted! #{e}")40end414243