Common attacks and weaknesses
- Brute force against the postgres account.
- trust authentication in pg_hba.conf allowing login without password.
- COPY ... PROGRAM abused for command execution by superusers.
PostgreSQL database server.
The application sends a SQL query to the PostgreSQL server on port 5432, which returns rows from its tables. Encryption is optional: traffic is only protected if TLS is enabled on the server and the client.
| Service | Port | Transport | Description | Reference | Updated |
|---|---|---|---|---|---|
| postgresql | 5432 | TCP, UDP | PostgreSQL Database | - | - |
// source: IANA service name and port number registry
Linux
sudo ss -ltnup 'sport = :5432' # process listening on 5432
sudo lsof -nP -i :5432macOS
sudo lsof -nP -i :5432
Windows (PowerShell)
Get-NetTCPConnection -LocalPort 5432 -State Listen | Select LocalAddress, OwningProcess Get-NetUDPEndpoint -LocalPort 5432 netstat -ano | findstr :5432
From another machine
nmap -p 5432 -sV <host> sudo nmap -sU -p 5432 <host> nc -zv <host> 5432
Block it in the firewall
sudo ufw deny 5432/tcp # Linux (ufw) New-NetFirewallRule -DisplayName "Block 5432" -Direction Inbound -LocalPort 5432 -Protocol TCP -Action Block # Windows
PostgreSQL database server.
Port 5432 is registered for TCP and UDP. In practice the service mostly uses TCP.
It is rated 8/10 (high) when exposed to the Internet. Brute force against the postgres account. Listen on private addresses only.
On Linux run "ss -ltnup 'sport = :5432'", on macOS "lsof -nP -i :5432", and on Windows "netstat -ano | findstr :5432" to see the local process. From another machine, "nmap -p 5432 <host>" shows whether it is reachable.