Skip to content
RCE Disclosed report Advanced CVE-2019-11043

CVE-2019-11043: a buffer underflow in fpm_main.c can lead to RCE in php-fpm

A missing bounds check in php-fpm's fpm_main.c causes a buffer underflow when the FastCGI PATH_INFO variable is empty, leading to a single-byte out-of-bounds write. An attacker can exploit this via crafted HTTP requests to Nginx with a specific configuration, potentially achieving remote code execution.

neex Follow with d90pwn and beched

Originally disclosed on HackerOne

Bounty$1,500 Critical View original
  • Triaged in 41 hours
  • Fixed in 12 months
  • Paid in 12 months
  • Disclosed after 13 months

The vulnerability exists in php-fpm because of missing bounds check in fpm_main.c. If the FastCGI variable PATH_INFO is empty, the underflow happens when the code tries to calculate the value of the path_info variable. An invalid pointer in path_info leads to a single byte out-of-bounds write, which can be leveraged to code execution.

The php-fpm allows anyone who can connect to its' port to execute code, so an RCE in php-fpm is not interesting by itself. However, this particular issue can be exploited even by a user who has access to the HTTP server (which is Nginx typically). In certain Nginx configurations, it is possible to make it send empty PATH_INFO value by breaking regexp in fastcgi_split_pathinfo directive using an encoded newline character (%0a).

The issue was reported to PHP maintainers in the bug 78599 and assigned CVE-2019-11043. It was disclosed on October 22.

The exploit for the issue is available at https://github.com/neex/phuip-fpizdam/.

To reproduce the issue, follow the steps at the "Playground environment" section in the exploit's README. The repo contains a Dockerfile, which builds the version of PHP just before the fix.

Exploit works only when Nginx config allows to trigger the bug (that is, to send empty PATH_INFO FastCGI variable). The full list of preconditions can be found at the exploit repository. There are real world examples of big projects empoying such configuration, see e.g. https://twitter.com/chybeta/status/1187213401124036608 (this particular issue is already reported to the corresponding bug bounty program and they hardened the Nginx config).

As the vulnerability resides in php-fpm, not Nginx, there might be other ways to trigger the vulnerability when other HTTP server software is used. However, I'm not aware of any at this moment.

Impact

If the attack is successful, the attacker can execute code at the server that runs php-fpm with the privileges of the php-fpm process. Again, note that the attacker doesn't have access to the php-fpm socket, she only makes HTTP requests to the nginx.

The original report as published on HackerOne, by neex. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a missing bounds check in fpm_main.c when calculating the path_info variable, causing a buffer underflow when PATH_INFO is empty.

Impact

An attacker could execute code on the server with the privileges of the php-fpm process, but only if the Nginx configuration is vulnerable.

What the attacker needed

Nginx with fastcgi_split_pathinfo misconfiguration; Ability to send HTTP requests to Nginx

The fix

The Dockerfile builds the PHP version just before the fix, implying a fix exists.

How it was found

  1. Set up the playground environment using the Dockerfile from the exploit repository.
  2. Ensure the Nginx configuration allows sending an empty PATH_INFO FastCGI variable.
  3. Use the exploit tool to send crafted requests that trigger the buffer underflow.
  4. Achieve code execution on the server running php-fpm.

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 report has not been written yet. The Original tab links to the source.

php-fpm is a program that runs PHP code for web servers. A bug in it means that when a certain piece of information (PATH_INFO) is empty, the program writes one byte outside its intended memory area. This can be abused by someone sending special web requests to take over the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by neex

View all

5 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.