CVE-2024-0985

8.0 HIGH

📋 TL;DR

This PostgreSQL vulnerability allows an attacker who creates a materialized view to execute arbitrary SQL functions with the privileges of the user who runs REFRESH MATERIALIZED VIEW CONCURRENTLY. The attacker can lure a superuser or role member into refreshing their malicious view, enabling privilege escalation. Affected users include PostgreSQL administrators and users with refresh privileges on attacker-controlled views.

💻 Affected Systems

Products:
  • PostgreSQL
Versions: All versions before PostgreSQL 16.2, 15.6, 14.11, 13.14, and 12.18
Operating Systems: All operating systems running affected PostgreSQL versions
Default Config Vulnerable: ⚠️ Yes
Notes: Requires attacker to have CREATE privilege on a schema and victim to have REFRESH privilege on the materialized view. Default PostgreSQL installations are vulnerable if these conditions are met.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full database compromise: attacker gains superuser privileges, can read/modify/delete all data, create backdoors, and potentially execute operating system commands via PostgreSQL extensions.

🟠

Likely Case

Privilege escalation leading to unauthorized data access, data modification, or creation of persistent backdoors within the database.

🟢

If Mitigated

Limited impact if only non-privileged users refresh views, but still potential for data exposure within their access scope.

🌐 Internet-Facing: MEDIUM - Requires authenticated database access and social engineering to lure privileged users, but internet-facing PostgreSQL instances increase attack surface.
🏢 Internal Only: HIGH - Internal attackers with database access can exploit this against administrators, making it a significant insider threat.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ✅ No
Complexity: MEDIUM

Exploit requires attacker to create malicious materialized view and social engineer victim into refreshing it. Technical details and proof-of-concept are publicly available.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: PostgreSQL 16.2, 15.6, 14.11, 13.14, or 12.18

Vendor Advisory: https://www.postgresql.org/support/security/CVE-2024-0985/

Restart Required: Yes

Instructions:

1. Backup your PostgreSQL database
2. Stop PostgreSQL service
3. Upgrade to patched version using your distribution's package manager
4. Restart PostgreSQL service
5. Verify version with 'SELECT version();'

🔧 Temporary Workarounds

Restrict CREATE privileges

all

Limit CREATE privilege on schemas to trusted users only to prevent attackers from creating malicious materialized views.

REVOKE CREATE ON SCHEMA schema_name FROM untrusted_user;

Restrict REFRESH privileges

all

Limit REFRESH MATERIALIZED VIEW privileges to trusted administrators only.

REVOKE ALL ON MATERIALIZED VIEW view_name FROM untrusted_user;

🧯 If You Can't Patch

  • Implement strict access controls: only allow trusted administrators to refresh materialized views and create objects in schemas.
  • Monitor for suspicious REFRESH MATERIALIZED VIEW CONCURRENTLY commands, especially from non-administrative users or on unfamiliar views.

🔍 How to Verify

Check if Vulnerable:

Run 'SELECT version();' in PostgreSQL and compare against affected versions. If version is before 16.2, 15.6, 14.11, 13.14, or 12.18, system is vulnerable.

Check Version:

SELECT version();

Verify Fix Applied:

Run 'SELECT version();' and confirm version is 16.2, 15.6, 14.11, 13.14, 12.18 or later.

📡 Detection & Monitoring

Log Indicators:

  • REFRESH MATERIALIZED VIEW CONCURRENTLY commands on unfamiliar or recently created views
  • Multiple failed refresh attempts followed by successful privileged operations

Network Indicators:

  • Unusual database connections preceding REFRESH commands
  • Pattern of view creation followed by refresh requests

SIEM Query:

source="postgresql.log" AND "REFRESH MATERIALIZED VIEW CONCURRENTLY" | stats count by user, view_name

🔗 References

📤 Share & Export