CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/exploit/random_compile_c.rb
Views: 11767
1
#!/usr/bin/env ruby
2
# -*- coding: binary -*-
3
def help
4
puts "Usage:"
5
puts "#{__FILE__} [weight] [source code path] [output path]"
6
puts
7
puts "Example:"
8
puts "#{__FILE__} 80 /tmp/helloworld.c /tmp/helloworld.exe"
9
exit
10
end
11
12
help if ARGV.empty? || ARGV.include?('-h')
13
begin
14
msfbase = __FILE__
15
while File.symlink?(msfbase)
16
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
17
end
18
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
19
require 'msfenv'
20
require 'metasploit/framework/compiler/windows'
21
22
weight = ARGV.shift
23
source_code_path = ARGV.shift
24
out_path = ARGV.shift
25
26
if source_code_path.nil? || source_code_path.empty? || !File.exist?(source_code_path)
27
puts "Please set the source code path"
28
exit
29
elsif out_path.nil? || out_path.empty?
30
puts "Please set the destination path"
31
exit
32
end
33
34
source_code = File.read(source_code_path)
35
Metasploit::Framework::Compiler::Windows.compile_random_c_to_file(out_path, source_code, weight: weight.to_i)
36
if File.exist?(out_path)
37
puts "File saved as #{out_path}"
38
end
39
rescue SignalException => e
40
puts("Aborted! #{e}")
41
end
42
43