diff --git a/lib/msf/core/post/linux/compile.rb b/lib/msf/core/post/linux/compile.rb index ccc35229800bf..047d303e16d5c 100644 --- a/lib/msf/core/post/linux/compile.rb +++ b/lib/msf/core/post/linux/compile.rb @@ -11,7 +11,7 @@ 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 @@ -36,6 +36,16 @@ def live_compile? def upload_and_compile(path, data, compiler_args='') write_file "#{path}.c", strip_comments(data) + if datastore['COMPILER'] == 'Auto' + if has_gcc? + datastore['COMPILER'] = 'gcc' + elsif has_clang? + datastore['COMPILER'] = 'clang' + else + fail_with Module::Failure::BadConfig, "Unable to find gcc nor clang on the remote target." + end + end + compiler_cmd = "#{datastore['COMPILER']} -o '#{path}' '#{path}.c'" if session.type == 'shell' compiler_cmd = "PATH=\"$PATH:/usr/bin/\" #{compiler_cmd}"