diff --git a/Gemfile.lock b/Gemfile.lock index 12247023041a..f7ab1e88be29 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - metasploit-framework (6.4.27) + metasploit-framework (6.4.28) aarch64 abbrev actionpack (~> 7.0.0) diff --git a/lib/metasploit/framework/version.rb b/lib/metasploit/framework/version.rb index 8aa7675e81d7..59d2e6c04e1d 100644 --- a/lib/metasploit/framework/version.rb +++ b/lib/metasploit/framework/version.rb @@ -32,7 +32,7 @@ def self.get_hash end end - VERSION = "6.4.27" + VERSION = "6.4.28" MAJOR, MINOR, PATCH = VERSION.split('.').map { |x| x.to_i } PRERELEASE = 'dev' HASH = get_hash diff --git a/lib/msf/core/post/linux/compile.rb b/lib/msf/core/post/linux/compile.rb index ccc35229800b..562f962a1bd6 100644 --- a/lib/msf/core/post/linux/compile.rb +++ b/lib/msf/core/post/linux/compile.rb @@ -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']) @@ -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' @@ -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