Skip to content
Misconfiguration Write-up Intermediate

How Attackers Weaponize Php Fpm To Steal Your Env File

A PHP-FPM instance was configured to listen on a public TCP port, allowing attackers to bypass Nginx and send raw FastCGI requests. By setting SCRIPT_FILENAME to a valid PHP file and injecting auto_prepend_file via PHP_VALUE, an attacker could read the .env file and obtain secrets such as database credentials and API keys.

I Putu Nanda Amanta Follow

Published on systemweakness.com

How did they get in? The culprit might not be your code, your framework, or your Nginx rules.

I Putu Nanda Amanta, on systemweakness.com

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 PHP-FPM was configured to listen on a public TCP port ([redacted]:9000) without firewall restrictions, allowing direct FastCGI requests that bypass Nginx and permit injection of PHP configuration directives.

Impact

An attacker could read the .env file and obtain database credentials, API keys, and other secrets, potentially leading to data theft or ransomware.

What the attacker needed

PHP-FPM listening on a public TCP port; Firewall allows external access to port 9000; A PHP file exists on the server

The fix

PHP-FPM should be configured to listen on a Unix socket or bound to localhost with allowed clients restricted, and firewalls should block external access to port 9000.

How it was found

  1. Scan the server and find port 9000 open.
  2. Craft raw FastCGI packets and send them directly to the server's IP on port 9000, bypassing Nginx.
  3. Set SCRIPT_FILENAME to any existing PHP file on the server.
  4. Inject PHP_VALUE with auto_prepend_file pointing to the .env file.
  5. Receive the HTTP response containing the contents of the .env file.

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.

PHP-FPM is a program that runs PHP code for web servers like Nginx. If it is exposed directly to the internet on a network port, an attacker can talk to it without going through Nginx and trick it into reading sensitive files, such as the .env file that holds passwords and keys.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More by I Putu Nanda Amanta

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.