Skip to content
RCE Write-up Intermediate

How I Got a $1000 Bounty for Chaining LFI to RCE via Log Injecti

The application included files based on a user-supplied page parameter, allowing local file inclusion. By injecting PHP code into the Apache access log via the User-Agent header and then including that log file, the attacker achieved remote code execution.

zoningxtr Follow

Published on medium.com

Disclaimer: This content is foreducational purposes only. The author isnot responsible for any use or misuseof the information provided.

Zoningxtr, 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 PHP code directly included a file path taken from the page parameter without validation or restriction, allowing path traversal and inclusion of arbitrary local files.

Impact

Full remote code execution on the server, leading to server compromise, potential data exfiltration, and lateral movement.

What the attacker needed

Web server logs requests to a file; log file is readable by the web server; PHP allow_url_include is off (not needed)

The fix

The code should validate the page parameter against a whitelist of allowed files and use basename() to prevent path traversal.

How it was found

  1. Replace the page parameter value with a path traversal sequence pointing to /etc/passwd and observe the file contents returned.
  2. Send an HTTP request with a User-Agent header containing PHP code to write the code into the Apache access log.
  3. Request the page parameter with a path traversal sequence pointing to the Apache access log and include a cmd parameter to execute a command.
  4. Observe the output of the id command, confirming command 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.

The website let users choose which file to show by changing a value in the address bar. Because it did not check that value, an attacker could make the server show any file on the computer. The attacker then wrote a small program into a log file that the server keeps, and asked the server to run that log file, which executed the program.

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 zoningxtr

View all

7 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.