Wiz Details PostgreSQL Flaws in Google Cloud and Azure Managed Services

Summary
Wiz researchers describe PostgreSQL service flaws in Google Cloud and Azure that enabled operating-system command execution. They report escalating access in Google Cloud and achieving cross-tenant database access in Azure.
Key points
- Wiz says the flaws stemmed from cloud vendors’ modifications to PostgreSQL for managed, multi-tenant services, rather than bugs in PostgreSQL’s core code.
- In Google Cloud SQL, researchers combined a vendor-specific table-ownership permission with PostgreSQL index-function behavior to execute commands as the database administrator.
- Wiz reports escalating from database command execution to root in the container, then escaping to the host by exploiting network access and the guest agent’s configuration process.
- In Azure Database for PostgreSQL, Wiz says unrestricted CREATEROLE permissions let them grant a user powerful built-in roles and execute commands on the host.
- Wiz reports using the Azure foothold to demonstrate unauthorized access to other customers’ databases; it says Google Cloud’s stricter tenant isolation limited the impact there.
- Wiz says it disclosed issues to more than a dozen managed PostgreSQL vendors; implementation differences complicated coordinated fixes, and Aiven released its hardenings as open source.
Article Details
- Attack Vectors
- In Cloud SQL for PostgreSQL, the researchers combined a permission flaw in ALTER TABLE ownership changes with a malicious index function. ANALYZE invoked the function as the table owner, cloudsqladmin, enabling operating-system command execution through PostgreSQL COPY FROM PROGRAM.
- In the Cloud SQL container, the researchers used a symlink to redirect writes to a root-owned file under a directory they controlled. They overwrote ld.so.preload and used a shared library loaded by the SUID mount program to obtain root privileges.
- The researchers used the shared network namespace and network capabilities to inject a fake configuration response to the host's guest agent. The response added an SSH key and created a user, enabling access to the host virtual machine.
- In Azure Database for PostgreSQL, unrestricted CREATEROLE permission allowed creation of a user with pg_read_server_files, pg_write_server_files, and pg_execute_server_program roles. The researchers used COPY FROM PROGRAM to execute commands and open a reverse shell.
- Defensive Notes
- Enforce and maintain tenant isolation to limit the impact of vulnerabilities in managed services.
- Restrict CREATEROLE and prevent regular users from assigning themselves powerful built-in roles.
- Harden provider-specific PostgreSQL modifications that grant superuser-like capabilities to customers.
MITRE ATT&CK
T1059.004 · Unix ShellThe researchers executed shell commands using PostgreSQL COPY FROM PROGRAM, including a Bash reverse shell in the Azure example.T1068 · Exploitation for Privilege EscalationThe researchers escalated privileges in Cloud SQL through a PostgreSQL ownership and index-function flaw, and later escalated from the container user to root.T1098.004 · SSH Authorized KeysThe injected guest-agent configuration contained an SSH key that was added to the host instance.T1136.001 · Local AccountThe guest agent created a user specified in the injected configuration, which the researchers used to access the host.T1548.001 · Setuid and SetgidThey executed the SUID mount binary after manipulating ld.so.preload to obtain root privileges.T1565.002 · Transmitted Data ManipulationThe researchers injected a fake configuration response into the guest-agent communication with the instance metadata service.T1574.006 · Dynamic Linker HijackingThey overwrote ld.so.preload so a shared library would load when they executed the SUID mount program.T1611 · Escape to HostAfter gaining capabilities in the Cloud SQL container, they used TCP injection against the host guest agent to escape to the host virtual machine.
People
Vendors
AivenThe managed databases company Aiven, with whom we worked closely on these issues, decided to release its hardenings as an open-source project. This is a good and effective approach since any new vulnerability affectingGoogle Cloud Platform (GCP)for the first time our exploration of the infrastructure of another major cloud provider, Google Cloud Platform (GCP), exploiting the same type of vulnerability to gain initial access to the environment. Given theMicrosoft AzureDisclosed in April 2022, ExtraReplica could allow attackers to access the databases of other customers in Azure Database for PostgreSQL (Flexible Server).
Products
Azure Database for PostgreSQL (Flexible Server)ExtraReplica could allow attackers to access the databases of other customers in Azure Database for PostgreSQL (Flexible Server).Cloud SQLCase study 1: Google Cloud Platform Cloud SQLPostgreSQLAs part of our ongoing research into the cloud, Wiz Research found vulnerabilities in popular PostgreSQL-as-a-Service offerings of multiple cloud vendors. These vulnerabilities were not the result of a bug in the
Tools
PyInstallerin this article, and then automated the process by using the scapy Python library packaged with pyinstaller. The technique essentially exploits a feature in the GCP guest agent that runs on the host. Every soscapythe same TCP injection technique described in this article, and then automated the process by using the scapy Python library packaged with pyinstaller. The technique essentially exploits a feature in the GCP guest