Skip to content
Smuggling / CRLF Write-up Advanced

PHP-FPM request smuggling allows unauthenticated remote code execution

PHP can fail to discard unread bytes from an HTTP request body before reusing a persistent PHP-FPM or LSAPI connection. In PHP-FPM, an unauthenticated attacker can make those bytes form a separate FastCGI request, bypass front-end routing and execute attacker-controlled PHP code with the privileges of the worker.

github.com

Published on github.com

PHP can fail to discard unread bytes from an HTTP request body before reusing a persistent PHP-FPM or LSAPI connection. In PHP-FPM, an unauthenticated attacker can make those bytes form a separate FastCGI request, bypass front-end routing and execute attacker-controlled PHP code with the privileges of the worker.

The author, on github.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

PHP treated the existence of a lazily-read php://input stream as proof that the request body had been consumed, so it skipped discarding unread bytes before reusing a persistent FastCGI connection.

Impact

Successful exploitation can execute attacker-controlled PHP code as the worker without user interaction, but only when the front end enables persistent backend connections and the application opens php://input without reading it fully; standard configurations that close the FastCGI connection after each request are not affected.

What the attacker needed

Front end reuses backend connections; app opens php://input without reading it fully; attacker knows an existing PHP script path

The fix

The issue was fixed by draining input according to whether the body was fully consumed and by closing the connection when the previous FastCGI input record is incomplete; until upgrading, disable backend connection reuse.

How it was found

  1. The front end keeps persistent backend connections to PHP-FPM.
  2. The application opens php://input without reading it to the end.
  3. A malformed multipart body makes the parser stop at a predictable position, leaving attacker bytes unread.
  4. Those leftover bytes are parsed as a new FastCGI request with attacker-chosen parameters.
  5. The forged request sets allow_url_include and auto_prepend_file to execute its own input as PHP.

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.

When a web server talks to PHP, it can keep the same connection open for several requests. This report shows that if PHP does not fully read one request's body, leftover bytes can be mistaken for a new request. An attacker can use that to run their own PHP code on the server, without needing a login.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.