Skip to content

Commit

Permalink
Merge pull request #19462 from jvoisin/auto_compile
Browse files Browse the repository at this point in the history
Add an `Auto` option to live_compile
  • Loading branch information
smcintyre-r7 authored Sep 19, 2024
2 parents 3b33b23 + 38972a7 commit cd96bcd
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/msf/core/post/linux/compile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ def initialize(info = {})
super
register_options( [
OptEnum.new('COMPILE', [true, 'Compile on target', 'Auto', ['Auto', 'True', 'False']]),
OptEnum.new('COMPILER', [true, 'Compiler to use on target', 'gcc', ['gcc', 'clang']]),
OptEnum.new('COMPILER', [true, 'Compiler to use on target', 'Auto', ['Auto', 'gcc', 'clang']]),
], self.class)
end

def get_compiler
if has_gcc?
return 'gcc'
elsif has_clang?
return 'clang'
else
return nil
end
end

def live_compile?
return false unless %w{ Auto True }.include?(datastore['COMPILE'])

Expand All @@ -24,6 +34,8 @@ def live_compile?
elsif datastore['COMPILER'] == 'clang' && has_clang?
vprint_good 'clang is installed'
return true
elsif datastore['COMPILER'] == 'Auto' && get_compiler.present?
return true
end

unless datastore['COMPILE'] == 'Auto'
Expand All @@ -36,7 +48,13 @@ def live_compile?
def upload_and_compile(path, data, compiler_args='')
write_file "#{path}.c", strip_comments(data)

compiler_cmd = "#{datastore['COMPILER']} -o '#{path}' '#{path}.c'"
compiler = datastore['COMPILER']
if datastore['COMPILER'] == 'Auto'
compiler = get_compiler
fail_with(Module::Failure::BadConfig, "Unable to find a compiler on the remote target.") unless compiler.present?
end

compiler_cmd = "#{compiler} -o '#{path}' '#{path}.c'"
if session.type == 'shell'
compiler_cmd = "PATH=\"$PATH:/usr/bin/\" #{compiler_cmd}"
end
Expand Down

0 comments on commit cd96bcd

Please sign in to comment.