PostgreSQL Enumeration
PostgreSQL enumeration covers confirming the service, pulling the version, and mapping database structure, roles, and extensions once you have access. Version feeds CVE matching. Role and extension state feeds privilege escalation decisions. This page assumes either no credentials yet or valid credentials already in hand — credential testing belongs elsewhere.
Service and Version Detection
5432/tcp open postgresql PostgreSQL DB 14.5
-sV extracts the version string directly from the PostgreSQL startup message. Run default scripts alongside for any additional metadata the service exposes:
Confirm the service responds to the PostgreSQL wire protocol without credentials by attempting a connection and reading the error:
password authentication failed and no pg_hba.conf entry both confirm the service is live and reachable. A hang or connection refused means the port is filtered or closed.
Connecting with psql
If you have credentials, connect directly:
Force SSL when the server requires it:
Disable SSL when a proxy breaks TLS:
If the server uses trust authentication for the connecting IP, the prompt is skipped entirely and you land in a session without a password. Note the source address restriction — this is scoped to whatever IP the server trusts.
Session Context
Run these first to establish what the current session can see and do:
listen_addresses='*' confirms the instance is bound to all interfaces. password_encryption of md5 versus scram-sha-256 indicates the credential storage method. current_user versus session_user differing means you are operating under a SET ROLE context.
Database Enumeration
List all databases on the instance:
Switch into a database to enumerate its contents:
List schemas and the current search path:
The search_path shows which schemas the application queries by default. Non-default schemas often contain the application's actual tables.
Table Enumeration
List all tables across all schemas in the current database:
For a specific schema:
Prioritise tables that suggest credential or secret storage: users, accounts, auth, sessions, tokens, api_keys, config, settings, oauth_tokens. Table names alone do not prove a vulnerability — they identify where to look next.
Inspect column structure before reading data:
Pull a minimal sample to confirm content and types:
Role and Privilege Enumeration
List all roles with their attributes:
Full role attribute view from the catalog:
rolsuper=true means the role has full database control. From superuser, file read via pg_read_file, arbitrary file write via COPY TO, and extension loading are all available. rolreplication=true grants access to the replication protocol.
Role membership — who inherits from whom:
If the current user is not a superuser, check whether any accessible role grants elevated permissions through inheritance.
Extension Enumeration
Extensions installed on the instance determine what additional capabilities exist. Some are direct privilege escalation paths:
name | default_version | installed_version ---------------+-----------------+------------------ plpgsql | 1.0 | 1.0 plpython3u | 1.0 | 1.0 file_fdw | 1.0 | 1.0
plpython3u, plperlu, or plsh installed means untrusted procedural language functions can be created. With superuser rights, these allow OS command execution via CREATE FUNCTION. file_fdw allows querying files on the server filesystem as foreign tables. Both are covered in PostgreSQL privilege escalation pages.
Configuration Exposure
Some configuration values visible from a regular session reveal network exposure and authentication setup:
log_connections=on means every login attempt is written to the server log — relevant when testing credentials. listen_addresses='*' combined with network reach from a broad segment confirms the instance is broadly exposed.
References
-
pgsql-brute NSE Scriptnmap.org/nsedoc/scripts/pgsql-brute.html (opens in new tab)
Tests credentials against PostgreSQL — useful for confirming service behaviour during version detection
-
psql — PostgreSQL documentationwww.postgresql.org/docs/current/app-psql.html (opens in new tab)
Meta-commands, connection string format, and catalog query reference
Was this helpful?
Your feedback helps improve this page.