CVE-2022-31626
📋 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
- PHP
📦 What is this software?
Php by Php
Php by Php
Php by Php
⚠️ 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.
🎯 Exploit Status
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
linuxTemporarily disable the vulnerable extension if not required
sudo phpdismod pdo_mysql
sudo systemctl restart apache2
Use mysqli instead of pdo_mysql
allSwitch 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
- https://bugs.php.net/bug.php?id=81719
- https://lists.debian.org/debian-lts-announce/2022/12/msg00030.html
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/3T4MMEEZYYAEHPQMZDFN44PHORJWJFZQ/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/ZZTZQKRGEYJT5UB4FGG3MOE72SQUHSL4/
- https://security.gentoo.org/glsa/202209-20
- https://security.netapp.com/advisory/ntap-20220722-0005/
- https://www.debian.org/security/2022/dsa-5179
- https://bugs.php.net/bug.php?id=81719
- https://lists.debian.org/debian-lts-announce/2022/12/msg00030.html
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/3T4MMEEZYYAEHPQMZDFN44PHORJWJFZQ/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/ZZTZQKRGEYJT5UB4FGG3MOE72SQUHSL4/
- https://security.gentoo.org/glsa/202209-20
- https://security.netapp.com/advisory/ntap-20220722-0005/
- https://www.debian.org/security/2022/dsa-5179