Skip to content
RCE Write-up Intermediate

LFI to RCE: Log Poisoning via PHP Sessions and Apache Logs

The article explains how an attacker can turn a local file inclusion (LFI) vulnerability into remote code execution by writing PHP code into server-created files such as PHP session files or Apache access logs, then including those files through the LFI. The attacker can then execute arbitrary commands on the server.

medium.com

Published on medium.com

The previous parts all had one thing in common — we needed some way to get our PHP code onto the server, whether through a URL, a file upload, or a remote host. Log poisoning doesn’t need any of that.

Moncef fennan, on medium.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

The application includes user-controlled file paths without proper validation, and the server writes user-controlled data (such as session values or User-Agent headers) into files without sanitisation, allowing PHP code injection.

Impact

An attacker could execute arbitrary commands on the server, leading to full compromise.

What the attacker needed

LFI vulnerability; Writable session files or logs; Ability to control input written to files

How it was found

  1. Include the PHP session file through the LFI to confirm it is readable and see stored values.
  2. Pass PHP code as the language parameter so it gets written into the session file.
  3. Include the session file again with a command parameter to execute the injected code.
  4. Include the Apache access log through the LFI to confirm it is readable.
  5. Modify the User-Agent header to contain PHP code and send a request so the code is logged.
  6. Include the access log with a command parameter to execute the injected 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.

Local file inclusion (LFI) lets an attacker make a web server read files it shouldn't. This article shows that if the attacker can also write data into a file the server creates (like a session file or a log), they can put malicious code there and then use LFI to run it, taking 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.

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.