Skip to content
RCE Write-up Intermediate

Apache / PHP 5.x Remote Code Execution Exploit

The PHP CGI binary on Apache servers could be executed with attacker-controlled command-line arguments because the security check that normally blocks direct access could be bypassed by setting two php.ini options via the query string. An attacker could run arbitrary PHP code and therefore execute programs on the system.

exploit-db.com

Published on exploit-db.com

void usage(char argv[]) { printf("usage: %s <--target target> <--port port> <--protocol http|https> " \ "<--reverse-ip ip> <--reverse-port port> [--force-interpreter interpreter]\n", argv[0]); exit(1); }

kingcope, on exploit-db.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 the PHP CGI binary parsed command-line arguments from the query string, allowing an attacker to set cgi.force_redirect and cgi.redirect_status_env to zero and bypass the security check.

Impact

An attacker could execute arbitrary PHP code and therefore run programs on the system, leading to full compromise of the web server.

What the attacker needed

Php5-cgi or php-cgi installed; php-cgi accessible under /cgi-bin/; Apache http server

The fix

The vulnerability was fixed in PHP 5.3.12 and 5.4.2 and later versions.

How it was found

  1. Send a request to the php-cgi binary path with query-string arguments that set cgi.force_redirect and cgi.redirect_status_env to zero.
  2. Include a POST body containing PHP code that opens a reverse shell.
  3. The php-cgi binary executes the PHP code and connects back to the attacker.

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 can run as a CGI program, which is a separate executable that the web server calls for each request. Normally the server blocks direct requests to that program, but a flaw let an attacker pass extra command-line options through the URL, turning off the protection and running their own PHP code.

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.