CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2023-49316
7.50.15%

CVE-2023-49316: Denial of Service via Unbounded Degree in phpseclib Binary Finite Fields

Alon Barad
Alon Barad
Software Engineer

May 9, 2026·6 min read·3 visits

PoC Available

Executive Summary (TL;DR)

phpseclib 3.x before 3.0.34 fails to bound the degree parameter when parsing Elliptic Curve keys over binary fields, allowing unauthenticated attackers to cause a fatal Out-Of-Memory (OOM) crash via a crafted ASN.1 payload.

The phpseclib cryptographic library version 3.x prior to 3.0.34 contains a Denial of Service (DoS) vulnerability in its mathematical field generation logic. When parsing maliciously crafted X.509 certificates or PKCS#8 private keys specifying Elliptic Curve parameters over a binary finite field, the library fails to validate the degree parameter. This flaw allows a remote attacker to force the PHP application to perform unbounded memory allocations, exhausting server resources and terminating the application worker process.

Vulnerability Overview

CVE-2023-49316 represents a Denial of Service (DoS) vulnerability in the phpseclib cryptographic library. The flaw exists within the component responsible for parsing X.509 certificates and PKCS#8 private keys. It specifically affects versions of the v3 branch prior to 3.0.34. This vulnerability was identified as part of a broader academic research initiative into X.509DoS attacks targeting cryptographic implementations.

The vulnerability emerges when the library processes ASN.1 structures defining Elliptic Curve parameters over binary finite fields. The library extracts the degree parameter from the user-supplied cryptographic object and utilizes it directly in memory allocation routines. Because the library omits structural validation of this mathematical parameter, an attacker can specify an arbitrarily large degree.

Processing a maliciously crafted payload forces the PHP engine to attempt extensive contiguous memory allocations. This excessive allocation behavior reliably triggers an Out-Of-Memory (OOM) condition, abruptly terminating the PHP process. Applications relying on phpseclib to validate client certificates or parse user-uploaded keys expose this attack surface to unauthenticated external actors.

Root Cause Analysis

The root cause is a CWE-834 (Loop/String Iteration) and unbounded memory allocation flaw in the BinaryField class constructor. When phpseclib parses an ASN.1 encoded Elliptic Curve key, it instantiates the mathematical field defined by the key parameters. For binary fields over GF(2^m), the degree m dictates the size of the underlying polynomial representation.

In the vulnerable implementation located at Math/BinaryField.php, the extracted integer degree $m is passed to the native PHP function str_repeat. The exact vulnerable instruction is $val = str_repeat('0', $m) . '1';. This operation attempts to construct a binary string representing the polynomial basis.

The ASN.1 parser trusts the length headers and integer values embedded within the cryptographic payload. An attacker can set $m to the maximum integer limit of the architecture, such as the 32-bit ceiling limit. The subsequent str_repeat call demands gigabytes of memory, instantly exceeding the standard memory_limit directive configured in the php.ini environment.

The lack of mathematical domain validation prior to string instantiation constitutes the core architectural failure. Cryptographic parameters parsed from untrusted boundaries must be constrained to standardized bounds before being consumed by memory-intensive operations.

Code Analysis

Analyzing the Math/BinaryField.php constructor reveals the direct path from parameter extraction to memory exhaustion. The constructor signature accepts a variadic parameter list $indices, representing the polynomial coefficients. The primary degree is extracted via array_shift($indices) and immediately utilized.

The vulnerable code path operates without any upper bounds checking on the $m variable. The snippet below highlights the logic failure prior to the 3.0.34 release.

public function __construct(...$indices)
{
    $m = array_shift($indices);
    // VULNERABLE: $m is strictly controlled by the ASN.1 input.
    // A large integer causes an immediate fatal OOM error.
    $val = str_repeat('0', $m) . '1';

The vendor patch introduces a strict boundary check immediately after extracting the degree parameter. The fix enforces a hard limit of 571, derived from the Standards for Efficient Cryptography Group (SECG) SEC 2 standard.

public function __construct(...$indices)
{
    $m = array_shift($indices);
    if ($m > 571) {
        // PATCH: Rejects degrees exceeding the largest known standard curve
        throw new \OutOfBoundsException('Degrees larger than 571 are not supported');
    }
    $val = str_repeat('0', $m) . '1';

This remediation strategy effectively eliminates the DoS vector by bounding the memory allocation to a negligible 572 bytes. Any malicious payload attempting to define a larger binary curve will trigger a safe, catchable OutOfBoundsException rather than a fatal memory exhaustion error.

Exploitation and Attack Methodology

Exploiting CVE-2023-49316 requires submitting a crafted X.509 certificate or PKCS#8 key to a vulnerable endpoint. The attack necessitates no authentication, provided the application validates cryptographic material from anonymous sources. Typical vectors include mutually authenticated TLS endpoints (mTLS), SAML identity providers processing signed assertions, or applications importing user-provided SSH keys.

The exploit payload is constructed by modifying an otherwise valid Elliptic Curve public key. The attacker alters the ASN.1 sequence corresponding to the ECParameters structure. Specifically, the attacker defines a characteristic-two basis where the degree m is set to an exceptionally large integer.

When the phpseclib EC::loadFormat() method processes the PKCS#8 payload, it decodes the ASN.1 hierarchy and dynamically invokes the BinaryField constructor. The process transition from parsing to mathematical instantiation occurs automatically, leaving no opportunity for the consuming application to intercept or validate the object structure beforehand.

The following Proof-of-Concept snippet relies on a base64-encoded PKCS#8 block containing the malicious ASN.1 parameters. Execution crashes the PHP worker thread immediately.

use phpseclib3\Crypt\EC;
 
$key = '-----BEGIN PUBLIC KEY-----
MIIBDDCB0wYHKoZIzj0CATCBxwIBATAgBgcqhkjOPQECMBUCBH////8GCSqGSM49
AQIDAgICAMEwTQQZABeFj+t6mJdRaeFx93tAh94JisipEd97AQQZAP37Sb/mw6if
rK2qeh5bvHzBwuXYMUeIFAMVABA/rsdNaW5naHVhUXV3f8Wxke8wBDMEAfSBvF8P
++Ep0rWzfb970v2F5YlNy2MDF4QAl45nykDcSzPPqnjoa0X+wsyAbavfOGwUCGQEA
AAAAAAAAAAAAAADH80p3j0Q6zJIOukkCAQIDNAAEAE2mUTAwdPK952h3G8ZinK8B
z9DYTLdGkQDqox3AtEs9nn6kE1O/vHE4bqMegjj4gbA=
-----END PUBLIC KEY-----';
 
// This call triggers the OOM DoS in vulnerable versions
EC::loadFormat('PKCS8', $key);

Impact Assessment

The primary impact of this vulnerability is a complete Denial of Service targeting the availability of the host application. Because PHP typically operates in a shared-nothing web server architecture, such as PHP-FPM, a single crafted request terminates the worker process handling it.

An attacker transmitting these payloads continuously can exhaust the entire pool of available PHP worker processes. This sustained resource exhaustion prevents the server from handling legitimate user requests. The attack requires minimal bandwidth, classifying it as a highly asymmetric exhaustion attack.

The CVSS v3.1 base score of 7.5 correctly reflects the network-based attack vector, low complexity, and lack of required privileges. While confidentiality and integrity remain unaffected, the high availability impact poses a substantial risk to critical infrastructure relying on PHP-based identity or certificate management.

The EPSS score of 0.00149 indicates a low probability of active exploitation in the wild. However, the trivial nature of the exploit and the availability of generated PoC payloads within academic research necessitate prompt remediation.

Mitigation and Remediation Strategies

The definitive remediation for CVE-2023-49316 is updating the phpseclib dependency to version 3.0.34. Organizations must audit their composer.lock files to identify all transitive and direct dependencies on vulnerable 3.0.x versions. Execution of the standard composer update procedures generally resolves the issue without introducing backward compatibility concerns.

For environments where immediate patching is strictly prohibited, mitigation requires intercepting and validating cryptographic inputs prior to parsing. Implementing a strict byte-size limit on uploaded PEM/DER files can reduce the attack surface, though it will not prevent all variants of the attack.

Web Application Firewalls (WAF) offer minimal protection against this specific exploit. The malicious degree parameter is embedded deep within the Base64-encoded or binary ASN.1 structure, rendering pattern matching ineffective. Security appliances cannot parse nested cryptographic structures reliably without degrading overall network throughput.

Developers must ensure proper exception handling surrounds all invocations of EC::loadFormat() and related parsing functions. While the vendor patch prevents the fatal Out-Of-Memory error, the resulting OutOfBoundsException must still be caught and handled gracefully to prevent application state corruption or unhandled runtime exceptions.

Official Patches

phpseclibOfficial 3.0.34 Release Notes

Fix Analysis (1)

Technical Appendix

CVSS Score
7.5/ 10
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Probability
0.15%
Top 65% most exploited

Affected Systems

phpseclib 3.0.x

Affected Versions Detail

Product
Affected Versions
Fixed Version
phpseclib
phpseclib
>= 3.0.0, < 3.0.343.0.34
AttributeDetail
CWE IDCWE-834
Attack VectorNetwork
CVSS v3.17.5
EPSS Score0.15%
ImpactHigh (Availability)
Exploit StatusProof-of-Concept
CISA KEVNot Listed

MITRE ATT&CK Mapping

T1499.004Endpoint Denial of Service: Application Exhaustion Flood
Impact
CWE-834
Loop with Unreachable Exit Condition ('Infinite Loop')

Loop with Unreachable Exit Condition ('Infinite Loop') / Resource Exhaustion

Known Exploits & Detection

Research PaperX.509DoS: Exploiting and Detecting Denial-of-Service Vulnerabilities in X.509 Certificate Parsing

Vulnerability Timeline

Patch committed to phpseclib repository
2023-11-22
Official release of version 3.0.34 and public disclosure
2023-11-27
CVE-2023-49316 assigned and published in NVD
2023-11-27
Additional context provided by USENIX X.509DoS research findings
2024-01-01

References & Sources

  • [1]GitHub Security Advisory: GHSA-2f25-pfq3-c7h8
  • [2]Fix Commit in phpseclib
  • [3]USENIX Paper: X.509DoS

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.