metasploit-framework/tools/exploit/random_compile_c.rb

39 lines
1.0 KiB
Ruby
Raw Normal View History

2018-10-17 08:23:56 +00:00
#!/usr/bin/env ruby
# -*- coding: binary -*-
2018-07-06 05:00:28 +00:00
def help
puts "Usage:"
puts "#{__FILE__} [weight] [source code path] [output path]"
puts
puts "Example:"
puts "#{__FILE__} 80 /tmp/helloworld.c /tmp/helloworld.exe"
exit
end
help if ARGV.empty? || ARGV.include?('-h')
2018-06-29 05:08:32 +00:00
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
require 'msf/core'
require 'metasploit/framework/compiler/windows'
weight = ARGV.shift
source_code_path = ARGV.shift
out_path = ARGV.shift
if source_code_path.nil? || source_code_path.empty? || !File.exists?(source_code_path)
puts "Please set the source code path"
exit
elsif out_path.nil? || out_path.empty?
puts "Please set the destination path"
exit
end
source_code = File.read(source_code_path)
Metasploit::Framework::Compiler::Windows.compile_random_c_to_file(out_path, source_code, weight: weight.to_i)
if File.exists?(out_path)
puts "File saved as #{out_path}"
end