Pentesting PostgreSQL
Enumeration
Nmap Scripts
nmap -sV -p 5432 --script="pgsql-*" $ipBanner Grabbing
nc -nv $ip 5432Connecting to PostgreSQL
Using psql Client
# Basic connection
psql -h <host> -p 5432 -U <username> -d <database>
# With password in environment variable (avoids password prompt)
PGPASSWORD='password' psql -h 127.0.0.1 -p 5432 -U postgres -d cozyhosting
# Connect to default database
psql -h <host> -U postgres
# Connect via Unix socket (local)
psql -U postgresCommon Default Credentials
Username
Password
Essential psql Commands
Navigation & Meta-Commands
Command
Description
Example Workflow
Extracting Data
Dumping Users and Passwords
Searching for Sensitive Data
File Operations (Requires Superuser)
Reading Files
Writing Files
Command Execution
Using COPY FROM PROGRAM (PostgreSQL 9.3+)
Using Extensions
Cracking PostgreSQL Hashes
Privilege Escalation
Check Current User Privileges
PostgreSQL to System Shell
Useful Resources
Last updated