Class: Metasploit::Framework::Compiler::Windows
- Inherits:
-
Object
- Object
- Metasploit::Framework::Compiler::Windows
- Defined in:
- lib/metasploit/framework/compiler/windows.rb
Class Method Summary collapse
-
.compile_c(c_template, type = :exe, cpu = Metasm::Ia32.new) ⇒ String
Returns the binary of a compiled source.
-
.compile_c_to_file(out_file, c_template, type = :exe, cpu = Metasm::Ia32.new) ⇒ Integer
Saves the compiled code as a file.
-
.compile_random_c(c_template, opts = {}) ⇒ String
Returns the binary of a randomized and compiled source code.
-
.compile_random_c_to_file(out_file, c_template, opts = {}) ⇒ Integer
Saves the randomized compiled code as a file.
-
.generate_random_c(c_template, opts = {}) ⇒ String
Returns randomized c source code.
Class Method Details
.compile_c(c_template, type = :exe, cpu = Metasm::Ia32.new) ⇒ String
Returns the binary of a compiled source.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/metasploit/framework/compiler/windows.rb', line 20 def self.compile_c(c_template, type=:exe, cpu=Metasm::Ia32.new) headers = Compiler::Headers::Windows.new source_code = Compiler::Utils.normalize_code(c_template, headers) pe = Metasm::PE.compile_c(cpu, source_code) case type when :exe pe.encode when :dll pe.encode('dll') else raise NotImplementedError end end |
.compile_c_to_file(out_file, c_template, type = :exe, cpu = Metasm::Ia32.new) ⇒ Integer
Saves the compiled code as a file. This is basically a wrapper of #self.compile.
42 43 44 45 |
# File 'lib/metasploit/framework/compiler/windows.rb', line 42 def self.compile_c_to_file(out_file, c_template, type=:exe, cpu=Metasm::Ia32.new) pe = self.compile_c(c_template, type) File.write(out_file, pe, mode: 'wb') end |
.compile_random_c(c_template, opts = {}) ⇒ String
Returns the binary of a randomized and compiled source code.
69 70 71 72 73 74 75 |
# File 'lib/metasploit/framework/compiler/windows.rb', line 69 def self.compile_random_c(c_template, opts={}) type = opts[:type] || :exe cpu = opts[:cpu] || Metasm::Ia32.new random_c = self.generate_random_c(c_template, opts) self.compile_c(random_c, type, cpu) end |
.compile_random_c_to_file(out_file, c_template, opts = {}) ⇒ Integer
Saves the randomized compiled code as a file. This is basically a wrapper for #self.compile_random_c
83 84 85 86 |
# File 'lib/metasploit/framework/compiler/windows.rb', line 83 def self.compile_random_c_to_file(out_file, c_template, opts={}) pe = self.compile_random_c(c_template, opts) File.write(out_file, pe, mode: 'wb') end |
.generate_random_c(c_template, opts = {}) ⇒ String
Returns randomized c source code.
53 54 55 56 57 58 59 60 61 |
# File 'lib/metasploit/framework/compiler/windows.rb', line 53 def self.generate_random_c(c_template, opts={}) weight = opts[:weight] || 80 headers = Compiler::Headers::Windows.new source_code = Compiler::Utils.normalize_code(c_template, headers) randomizer = Metasploit::Framework::Obfuscation::CRandomizer::Parser.new(weight) randomized_code = randomizer.parse(source_code) randomized_code.to_s end |