Skip to content
RCE Write-up Intermediate

Log Poisoning to Remote Code Execution | LFI | cUrl |

A PHP application passed a base64-encoded, serialised cookie value into a file include, letting the author read arbitrary files such as the system password file. Because the Nginx access log was writable through the User-Agent header, the author placed PHP code in the log and then included that log to run commands on the server.

Medusa Follow

Published on systemweakness.com

In this article, we will see how to perform Remote Code Execution through Log Poisoning which is a type of Local File Inclusion.

Medusa, 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 the application unserialised a user-controlled cookie and used its file path in an include statement without validation, and the log file was reachable through the same include.

Impact

An attacker could read sensitive server files and, once code was written to the log, run arbitrary commands on the server.

What the attacker needed

PHP backend with an includable cookie value; Nginx access log readable via the include; Ability to set the User-Agent header

The fix

The application should not unserialise user-controlled cookie data or pass it to an include; it should use a fixed allow-list of pages and keep log files outside any includable path.

How it was found

  1. Decode the base64 PHPSESSID cookie and observe a serialised object holding a file path.
  2. Change the path to a system file, re-encode it in base64 and send it in the cookie to read that file.
  3. Change the path to the Nginx access log and confirm the log can be read.
  4. Send a request with PHP code in the User-Agent header so it is written to the log.
  5. Request the log file again through the cookie so the logged PHP code executes.

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.

The site trusted a value stored in a cookie to decide which file to load, so changing that value made it load files it should never show. The attacker then wrote a small piece of PHP code into a log file the server keeps, and asked the site to load that log, which made the code run. This is called log poisoning combined with local file inclusion.

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 Medusa

View all

10 more disclosed reports, best first.

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.