mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-09-11 17:08:02 +02:00
generate random c within compile_random_c
This commit is contained in:
parent
3c50f3d54e
commit
42b251be01
@ -62,25 +62,27 @@ module Metasploit
|
||||
|
||||
# Returns the binary of a randomized and compiled source code.
|
||||
#
|
||||
# @param rand_c_template [String]
|
||||
# @param c_template [String]
|
||||
#
|
||||
# @raise [NotImplementedError] If the type is not supported.
|
||||
# @return [String] The compiled code.
|
||||
def self.compile_random_c(rand_c_template, opts={})
|
||||
def self.compile_random_c(c_template, opts={})
|
||||
type = opts[:type] || :exe
|
||||
cpu = opts[:cpu] || Metasm::Ia32.new
|
||||
|
||||
self.compile_c(rand_c_template, type, cpu)
|
||||
random_c = self.generate_random_c(c_template, opts)
|
||||
self.compile_c(random_c, type, cpu)
|
||||
end
|
||||
|
||||
# Saves the randomized compiled code as a file. This is basically a wrapper for #self.compile_random_c
|
||||
#
|
||||
# @param out_file [String] The file path to save the binary as.
|
||||
# @param rand_c_template [String] The randomized C source code to compile.
|
||||
# @param c_template [String] The randomized C source code to compile.
|
||||
# @param opts [Hash] Options to pass to #compile_random_c
|
||||
# @return [Integer] The number of bytes written.
|
||||
def self.compile_random_c_to_file(out_file, rand_c_template, opts={})
|
||||
pe = self.compile_random_c(rand_c_template, opts)
|
||||
def self.compile_random_c_to_file(out_file, c_template, opts={})
|
||||
random_c = self.generate_random_c(c_template, opts)
|
||||
pe = self.compile_random_c(random_c, opts)
|
||||
File.write(out_file, pe)
|
||||
end
|
||||
end
|
||||
|
@ -72,8 +72,7 @@ int main() {
|
||||
def run
|
||||
vprint_line c_template
|
||||
# The randomized code allows us to generate a unique EXE
|
||||
random_c = Metasploit::Framework::Compiler::Windows.generate_random_c(c_template)
|
||||
bin = Metasploit::Framework::Compiler::Windows.compile_random_c(random_c)
|
||||
bin = Metasploit::Framework::Compiler::Windows.compile_random_c(c_template)
|
||||
print_status("Compiled executable size: #{bin.length}")
|
||||
file_create(bin)
|
||||
end
|
||||
|
@ -33,8 +33,7 @@ elsif out_path.nil? || out_path.empty?
|
||||
end
|
||||
|
||||
source_code = File.read(source_code_path)
|
||||
rand_c_src = Metasploit::Framework::Compiler::Windows.generate_random_c(source_code, weight: weight.to_i)
|
||||
Metasploit::Framework::Compiler::Windows.compile_random_c_to_file(out_path, rand_c_src)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user