/

CVE-2021-47853

Severity:

HIGH RISK

(8.8)

OS Command Injection in phpPgAdmin 7.13.0

CVE-2021-47853

Undergoing Analysis

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 PROGRAM or 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 COPY commands.
  • Trigger point: Execution of a crafted SQL query that leverages COPY FROM PROGRAM in 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 PROGRAM and 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 PROGRAM or 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 PROGRAM usage.
  • 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.

Sources

SourceLink
github.comgithub.com/phppgadmin/phppgadmin/releases
exploit-db.comexploit-db.com/exploits/49736
vulncheck.comvulncheck.com/advisories/phppgadmin-copy-from-program-command-execution

Frequently asked

questions

Yes, if phpPgAdmin is exposed over the network and accessible to authenticated users, an attacker can exploit it remotely through the web interface, provided the necessary database privileges and PostgreSQL features are enabled.

Yes. The described scenario requires authenticated access to phpPgAdmin with the ability to create tables and run COPY statements. The exact risk depends heavily on which database roles are mapped to those authenticated users.

The safest pattern is to prevent web-exposed users from invoking database features that can spawn OS commands or access the filesystem. This typically means disabling or tightly restricting COPY FROM PROGRAM for web-facing roles and segregating administrative operations from regular user actions.

Treat database administration interfaces as high-risk and restrict them to trusted operators and networks, enforce least-privilege roles for any account reachable from the web, and regularly review database configuration for dangerous features exposed to application-facing users. Additionally, combine configuration hardening with monitoring rules for high-risk SQL constructs.

Find out what's already
exploitable in your codebase.