Skip to content
RCE Write-up Intermediate

From LFI to RCE: How I Turned a File Read into Shell Access

A file-reading parameter allowed local file inclusion, and the attacker found that the User-Agent header was written into a readable process environment file. By placing PHP code in the User-Agent and then reading that file, the code executed on the server, giving remote code execution.

medium.com

Published on medium.com

Hello everyone! Welcome to my very first blog post.

Sujeet Kamble, 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

Likely the filename parameter accepted path traversal without restriction, and the PHP process environment file exposed attacker-controlled request headers that were then included and executed as PHP.

Impact

An attacker could read local files and execute arbitrary commands on the server, leading to full compromise.

What the attacker needed

Access to the vulnerable web endpoint; ability to set the User-Agent header

How it was found

  1. Find a parameter named filename that renders file contents.
  2. Confirm local file read by fetching the system password file.
  3. Fuzz common Linux file paths to find readable files.
  4. Notice that the process environment file reflects the User-Agent header.
  5. Change the User-Agent to PHP code and read the environment file again.
  6. Observe command output in the response, confirming code execution.

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.

A file-reading feature let the attacker ask the server for files outside the website folder, such as system files. One of those files records information about the current request, including the browser's User-Agent text. Because the server ran PHP, putting PHP code in that text and then reading the file made the server run the 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.