In this blog, I will demonstrate how a simple directory listing vulnerability led to full system compromise during a penetration test.
Prologue
“The best exploits are the ones that never feel like exploits at all.”
— Mr. Robot
I discovered that a web server was exposing its directory contents.
Several configuration and compressed files were visible, indicating possible sensitive information leakage.
Source Code Analysis
After downloading and analyzing the exposed files, I found a PHP configuration file containing PostgreSQL database credentials.
Database Connection
Using the extracted credentials, I connected to the PostgreSQL server and successfully authenticated.
PostgreSQL to Reverse Shell
After confirming access, I attempted to escalate this to Remote Command Execution.
Role Enumeration
First, I enumerated the database role.
The user had superuser privileges, which was promising.
Permission Enumeration
To enumerate detailed permissions, I used the following query:
| |

The presence of the pg_execute_server_program privilege allowed OS-level command execution.
Remote Code Execution
Using PostgreSQL’s COPY FROM PROGRAM, I executed a reverse shell payload
| |

Listener setup:
| |

SSH Connection
Port 22 (SSH) was open on the target.
I located the home directory of the postgres user
Added my public key to authorized_keys
Successfully logged in via SSH
Priviledge Escalation
While reviewing /etc/passwd, I noticed a system user whose credentials matched those found in the PHP file. Trying the same password worked.
This user also had sudo privileges, allowing immediate root shell access
Lateral Movement
The compromised server resided in a private Class B network. I scanned the subnet for SSH using Gill-Singh-A/Port-Scanner and performed SSH password spraying using Gill-Singh-A/SSH-Brute-Force
This resulted in successful access to two additional hosts
Attack Path
