CVE-2020-16629

9.8 CRITICAL

📋 TL;DR

CVE-2020-16629 is a critical SQL injection vulnerability in PhpOK CMS that allows attackers to inject malicious SQL through attachment data, then use the attachment replacement function to write arbitrary PHP files to the server. This enables remote code execution on affected systems. All users running vulnerable versions of PhpOK are affected.

💻 Affected Systems

Products:
  • PhpOK CMS
Versions: 5.4.137 and likely earlier versions
Operating Systems: All operating systems running PHP
Default Config Vulnerable: ⚠️ Yes
Notes: Requires the api.php endpoint to be accessible, which is typically exposed in default installations.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Complete system compromise with remote code execution, allowing attackers to install backdoors, steal data, deface websites, or pivot to internal networks.

🟠

Likely Case

Website defacement, data theft, and installation of web shells for persistent access.

🟢

If Mitigated

Limited impact if proper input validation and file upload restrictions are in place, though SQL injection could still expose database contents.

🌐 Internet-Facing: HIGH - Directly exploitable via web interface without authentication.
🏢 Internal Only: MEDIUM - Could be exploited by internal attackers or through compromised internal systems.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: CONFIRMED
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Public exploit code is available on GitHub, making this easily weaponizable by attackers with minimal technical skill.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 5.4.138 or later

Vendor Advisory: https://github.com/Gh0stF/phpok_cve/issues/1

Restart Required: No

Instructions:

1. Backup your current installation and database. 2. Download the latest version of PhpOK from the official source. 3. Replace all files except configuration files and uploads directory. 4. Verify the update by checking the version in admin panel.

🔧 Temporary Workarounds

Block api.php Access

all

Temporarily block access to the vulnerable api.php endpoint

# For Apache: add to .htaccess
<Files "api.php">
    Order allow,deny
    Deny from all
</Files>
# For Nginx: add to server block
location ~ /api\.php$ {
    deny all;
    return 403;
}

Input Validation Filter

all

Add input validation for attachment parameters

# Add to relevant PHP files before SQL queries
$attachment_data = filter_var($_POST['attachment_data'], FILTER_SANITIZE_STRING);

🧯 If You Can't Patch

  • Implement a Web Application Firewall (WAF) with SQL injection and file upload protection rules
  • Restrict file permissions to prevent PHP file writing in upload directories

🔍 How to Verify

Check if Vulnerable:

Check if running PhpOK version 5.4.137 or earlier by examining the version in admin panel or checking PHP files for version strings.

Check Version:

grep -r "5\.4\.137" /path/to/phpok/installation/ || php -r "include '/path/to/phpok/version.php'; echo $version;"

Verify Fix Applied:

Verify version is 5.4.138 or later and test that api.php no longer accepts malicious SQL injection in attachment parameters.

📡 Detection & Monitoring

Log Indicators:

  • Unusual SQL queries in database logs
  • Multiple failed attempts to access api.php with SQL patterns
  • Unexpected PHP file creation in upload directories

Network Indicators:

  • POST requests to api.php with SQL keywords in parameters
  • Unusual file upload patterns to attachment endpoints

SIEM Query:

source="web_logs" AND (uri="/api.php" AND (param="*SELECT*" OR param="*UNION*" OR param="*INSERT*"))

🔗 References

📤 Share & Export