The Database Hacker's Handbook: Defending Database Servers
by David Litchfield, Chris Anley, John Heasman, Bill Grindlay
Finding Targets
PostgreSQL is not configured for network access by default, so it is first worth considering how to determine its presence given local access to a system. This is achieved by examining the process list for “postmaster” or “postgres.” On Unix systems the PostgreSQL local socket is typically located in /tmp and is named s.PGSQL.5432. It can be determined by listing listening TCP and Unix sockets via netstat –l.
Many deployment scenarios require the database to be remotely available. PostgreSQL typically listens on port 5432 TCP. An attacker may therefore perform a simple sweep of the network for systems that respond to TCP SYN packets on port 5432 in order to determine the presence of PostgreSQL servers:
$ nmap -sS 10.0.0.0/24 -p 5432 Starting nmap 3.70 ( http://www.insecure.org/nmap ) Interesting ports on 10.1.1.248: PORT STATE SERVICE 5432/tcp open postgres Nmap run completed -- 1 IP address (1 host up) scanned in 4.907 seconds
An administrator may choose to change the port on which the postmaster listens, possibly as an obfuscation measure to slow down an attacker. It is simple, however, to detect a listening postmaster. A PostgreSQL client such as psql could be used to attempt connection. Given that the username, database, SSL connection option, and host from which the connection originates must have an entry in the pg_hba.conf file, an attacker is unlikely to match a valid entry on an initial probe. Thus the expected response would be something like the following: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access