CVE-2022-31626

7.5 HIGH

📋 TL;DR

This CVE describes a buffer overflow vulnerability in PHP's pdo_mysql extension with mysqlnd driver when connecting with an excessively long password. Attackers who can control the connection host and password parameters can trigger remote code execution. Affects PHP 7.4.x below 7.4.30, 8.0.x below 8.0.20, and 8.1.x below 8.1.7.

💻 Affected Systems

Products:
  • PHP
Versions: PHP 7.4.x below 7.4.30, 8.0.x below 8.0.20, 8.1.x below 8.1.7
Operating Systems: All operating systems running affected PHP versions
Default Config Vulnerable: ⚠️ Yes
Notes: Requires pdo_mysql extension with mysqlnd driver enabled and third-party control over both host and password parameters for database connections.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution leading to complete system compromise, data theft, and lateral movement within the network.

🟠

Likely Case

Denial of service through application crashes, with potential for RCE if attackers can control both host and password parameters.

🟢

If Mitigated

Limited impact if proper input validation and least privilege are enforced, though buffer overflow could still cause crashes.

🌐 Internet-Facing: HIGH - Web applications using vulnerable PHP versions with user-controlled database connection parameters are directly exposed.
🏢 Internal Only: MEDIUM - Internal applications could be exploited by authenticated users or through other attack vectors.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: UNKNOWN
Unauthenticated Exploit: ✅ No
Complexity: MEDIUM

Exploitation requires control over both host and password parameters, which may limit attack surface in many configurations.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: PHP 7.4.30, 8.0.20, 8.1.7 or later

Vendor Advisory: https://bugs.php.net/bug.php?id=81719

Restart Required: Yes

Instructions:

1. Update PHP to version 7.4.30+, 8.0.20+, or 8.1.7+ using your package manager. 2. For Linux: 'sudo apt update && sudo apt upgrade php' (Debian/Ubuntu) or 'sudo yum update php' (RHEL/CentOS). 3. Restart web server: 'sudo systemctl restart apache2' or 'sudo systemctl restart nginx'. 4. Verify PHP version with 'php -v'.

🔧 Temporary Workarounds

Disable pdo_mysql extension

linux

Temporarily disable the vulnerable extension if not required

sudo phpdismod pdo_mysql
sudo systemctl restart apache2

Use mysqli instead of pdo_mysql

all

Switch database connections to mysqli extension if possible

🧯 If You Can't Patch

  • Implement strict input validation for database connection parameters, especially host and password fields
  • Use application-level firewalls or WAF to block requests with excessively long password parameters

🔍 How to Verify

Check if Vulnerable:

Run 'php -v' and check if version is below 7.4.30, 8.0.20, or 8.1.7. Also check if pdo_mysql is enabled with 'php -m | grep pdo_mysql'.

Check Version:

php -v

Verify Fix Applied:

After update, run 'php -v' to confirm version is 7.4.30+, 8.0.20+, or 8.1.7+. Test database connections with pdo_mysql to ensure functionality.

📡 Detection & Monitoring

Log Indicators:

  • Web server error logs showing PHP segmentation faults or crashes
  • Database connection failures with unusually long password parameters

Network Indicators:

  • Unusual outbound connections from web servers following database connection attempts

SIEM Query:

source="web_server_logs" AND ("segmentation fault" OR "buffer overflow" OR "pdo_mysql")

🔗 References

📤 Share & Export