Summary
phpPgAdmin 7.13.0 contains an OS command injection issue that allows authenticated users to execute arbitrary system commands through crafted SQL queries.
By abusing PostgreSQL's COPY FROM PROGRAM capability in combination with a custom table and uploaded file, an attacker can run operating system commands with the privileges of the phpPgAdmin application process.
Affected context
This vulnerability arises in environments where phpPgAdmin 7.13.0 is deployed and users can run SQL statements through the web interface.
The issue is exposed when:
- phpPgAdmin is configured to allow SQL query execution for authenticated users, and
- The underlying PostgreSQL instance permits
COPY FROM PROGRAMor similar server-side command features.
Installations that grant broad database privileges to web users or reuse database roles with elevated permissions are more exposed.
Exploit preconditions
- Attack surface: phpPgAdmin web interface (SQL query console / query tool).
- Required access: Valid authenticated access to phpPgAdmin with permission to create tables and execute
COPYcommands. - Trigger point: Execution of a crafted SQL query that leverages
COPY FROM PROGRAMin combination with an uploaded file or table. - Why exploitation is possible: The application exposes a powerful database feature (
COPY FROM PROGRAM) to web users without sufficient logical restrictions, allowing SQL-level operations to translate into OS command execution under the application or database service account.
Why this happens
The core issue maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), realized through the database layer.
phpPgAdmin forwards user-controlled SQL directly to PostgreSQL, including statements such as COPY FROM PROGRAM that bridge SQL and the operating system.
Without an application-layer policy to restrict dangerous SQL constructs, authenticated users can transform database privileges into arbitrary command execution on the host where PostgreSQL runs, effectively turning the database server into an OS command proxy.
Potential impact
- Execution of arbitrary operating system commands with the privileges of the database or web server account
- Reading, modifying, or deleting files accessible to that account
- Planting backdoors or persistence mechanisms on the underlying server
- Pivoting to other internal systems reachable from the database host
- Exfiltration or corruption of application and customer data
General mitigation guidance
Mitigation is centered on reducing the power of SQL exposed to web users and constraining OS-level capabilities of the database:
- Restrict or disable
COPY FROM PROGRAMand similar OS-bridging features in PostgreSQL for roles used by phpPgAdmin. - Apply strict least-privilege to database roles available via phpPgAdmin (e.g., no superuser or high-privilege roles in the web UI).
- Segment administrative functionality: separate a locked-down read/write role for phpPgAdmin from higher-privilege operational roles.
- Harden the database host environment: ensure the DB/service account has minimal filesystem and network permissions.
- Consider alternative administration patterns that do not expose raw SQL execution to general authenticated users.
How teams detect issues like this
Effective detection typically combines database-level monitoring with application review:
- Monitor PostgreSQL logs and audit trails for use of
COPY FROM PROGRAMor other OS-interfacing commands from phpPgAdmin-connected sessions. - Use database activity monitoring (DAM) or SIEM rules to flag creation of unusual tables followed by
COPY FROM PROGRAMusage. - During code and configuration review, identify flows that grant web users the ability to execute arbitrary SQL, especially commands that interact with the filesystem or shell.
- Employ static or configuration analysis tools to highlight over-privileged database roles and unsafe PostgreSQL settings.

