Skip to content
RCE Write-up Advanced

Unpredicted PHP Vulnerability Found

A newline character in the URL caused Nginx to set an empty value for a FastCGI variable, which PHP-FPM mishandled, allowing an attacker to inject arbitrary FastCGI variables and execute PHP code. This could lead to remote code execution on servers using the fastcgi_split_path directive.

lab.wallarm.com

Published on lab.wallarm.com

We all know that Capture the Flag (CTF) tasks are synthetic. They are designed as games or puzzles for security professionals to solve in order to hone, demonstrate, and add skills.

The author, on lab.wallarm.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 a mismatch between Nginx's fastcgi_split_path directive and PHP-FPM's parsing of FastCGI variables when a newline is present, leading to variable injection.

Impact

This could allow an attacker to execute arbitrary PHP code on the server, leading to remote code execution.

What the attacker needed

Nginx with fastcgi_split_path directive; PHP-FPM backend

The fix

The issue was fixed in PHP; additionally, filtering %0a/%0d bytes in URLs or applying a WAF rule can mitigate it.

How it was found

  1. Send a URL containing a newline byte (%0a) to a server using Nginx with fastcgi_split_path.
  2. Observe that the server returns more data than expected, with the extra data related to bytes after the newline.
  3. Investigate the unusual behavior to understand how FastCGI variables are being manipulated.
  4. Exploit the issue to inject arbitrary FastCGI variables such as PHP_VALUE.
  5. Use the injected variables to execute arbitrary PHP code.

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 passes a request to PHP, it uses a protocol called FastCGI. A bug in how PHP handled a special newline character in the URL let attackers sneak in extra instructions, potentially running their own code on 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.

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.