From Directory Listing to Root Shell
A web server exposed a directory listing that included a PHP configuration file with PostgreSQL credentials. The attacker used those credentials to connect to the database, execute OS commands via PostgreSQL's COPY FROM PROGRAM, and ultimately gain root access and move laterally to other hosts.
medium.com
Published on medium.com
In this blog, I will demonstrate how a simple directory listing vulnerability led to full system compromise during a penetration test.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the web server had directory listing enabled and stored sensitive configuration files with plaintext credentials in a publicly accessible directory.
Impact
The attacker could execute arbitrary commands on the database server, gain SSH access, escalate to root, and compromise two additional hosts on the private network.
What the attacker needed
Directory listing enabled on web server; Sensitive files exposed in web directory; PostgreSQL accessible with credentials from file; SSH port open on target
How it was found
- Discover directory listing on the web server.
- Download exposed files and find a PHP configuration file with PostgreSQL credentials.
- Connect to the PostgreSQL server using the extracted credentials.
- Enumerate database roles and permissions to find superuser and pg_execute_server_program.
- Use PostgreSQL COPY FROM PROGRAM to execute a reverse shell payload.
- Add an SSH public key to the postgres user's authorized_keys and log in via SSH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A directory listing is when a web server shows all files in a folder instead of a normal web page. Here, that let the attacker download a configuration file that contained a database password. With that password, the attacker could run commands on the server and take full control.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.