A recently discovered vulnerability, tracked as CVE-2024-27354, resides in phpseclib - a popular PHP library that provides support for various cryptographic operations. This vulnerability affects multiple versions of phpseclib, specifically 1.x before 1..23, 2.x before 2..47, and 3.x before 3..36. A remote attacker can take advantage of this issue to cause a denial of service by utilizing a malformed certificate containing an extremely large prime number that results in high CPU consumption for an isPrime primality check. Intriguingly enough, this issue was introduced when attempting to fix a previous vulnerability, CVE-2023-27560.

Original References

1. CVE-2024-27354 Official MITRE Entry
2. phpseclib Repository on GitHub
3. phpseclib Release Notes and Fixes

Here is a simple code snippet that demonstrates the vulnerability in action

<?php
require 'phpseclib/autoload.php';

use phpseclib3\File\X509;

$malformed_cert = "-----BEGIN CERTIFICATE-----\n" .
                  "MIIFNTCCBB2gAwIBAgICEAAwDQYJKoZIhvtOBkU/triple_insert_malformed_certificate_here\n" .
                  "-----END CERTIFICATE-----";

$loader = new X509();
try {
    $cert = $loader->loadX509($malformed_cert);
    echo "Malformed certificate loaded successfully\n";
} catch (Exception $e) {
    echo "Failed to load malformed certificate: " . $e->getMessage() . "\n";
}
?>

Replace "triple_insert_malformed_certificate_here" with the actual malformed certificate containing the extremely large prime number.

When the code is executed, the PHP process will get stuck in the isPrime primality checking function due to the enormous prime number, causing high CPU consumption and eventual denial of service.

Exploit Details

An attacker can exploit this vulnerability by crafting a X.509 certificate with a large prime number in one of its fields. Once the certificate is parsed by an affected version of phpseclib, it will cause the isPrime primality check to consume excessive CPU resources, ultimately leading to denial of service.

To further illustrate the impact, a web application that relies on phpseclib for certificate management could be vulnerable to this issue, allowing an attacker to submit such a malformed certificate and cause high CPU usage on the server, effectively rendering the application unusable for other users.

Solution

To resolve this vulnerability, it is highly recommended that you update your phpseclib installation to the latest patched version applicable to your project:

For phpseclib version 3.x, update to 3..36 or later

You can find the latest releases and the corresponding fixes in the phpseclib GitHub repository. This will help ensure that your application remains secure against this type of attack.

In conclusion, CVE-2024-27354 is a notable vulnerability present in phpseclib that stems from the improper handling of certificates containing large prime numbers. To safeguard your application against denial of service, make sure to update your phpseclib library to the latest version.

Timeline

Published on: 03/01/2024 23:15:08 UTC
Last modified on: 03/21/2024 02:52:19 UTC