Files
metasploit-gs/tools/exploit/random_compile_c.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.1 KiB
Ruby
Raw Normal View History

2018-10-17 16:23:56 +08:00
#!/usr/bin/env ruby
# -*- coding: binary -*-
2018-07-06 00:00:28 -05: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')
2021-03-22 15:47:41 +05:30
begin
2018-06-29 00:08:32 -05: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')))
2022-06-10 11:28:42 +01:00
require 'msfenv'
2018-06-29 00:08:32 -05:00
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.exist?(source_code_path)
2018-06-29 00:08:32 -05:00
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)
2019-10-18 08:28:25 -05:00
Metasploit::Framework::Compiler::Windows.compile_random_c_to_file(out_path, source_code, weight: weight.to_i)
if File.exist?(out_path)
2018-06-29 00:08:32 -05:00
puts "File saved as #{out_path}"
2019-10-15 12:50:58 -05:00
end
2021-03-22 15:47:41 +05:30
rescue SignalException => e
puts("Aborted! #{e}")
end