Skip to content
RCE Write-up Intermediate

⚡️Oops, They Logged It! Turning LFI into Remote Shell Like a

A file parameter on a development server allowed local file inclusion, and because the web server logged the User-Agent header, an attacker could inject PHP code into the log and then include the log file to execute commands. This led to remote code execution and a reverse shell.

iski Follow

Published on infosecwriteups.com

Free Link🎈

Iski, on infosecwriteups.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 file parameter was not validated, allowing path traversal, and the application included files without restricting to a safe directory; additionally, the web server logged unsanitised user input (User-Agent) to a file that was accessible via the LFI.

Impact

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

What the attacker needed

A file parameter that is vulnerable to LFI; web server logs accessible via LFI; ability to send requests with custom User-Agent

How it was found

  1. Find a URL with a file parameter that takes a filename.
  2. Test for local file inclusion by trying to read the system password file.
  3. Inject PHP code into the web server's access log by sending a request with a custom User-Agent header.
  4. Include the access log file through the file parameter to execute the injected code.
  5. Run a command like whoami to confirm code execution.
  6. Use a reverse shell command to get an interactive shell.

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 had a feature that let you choose a file to display, but it did not check which files you picked. By picking system files like the password file, the author could read them. Then, because the web server writes every request (including the browser's User-Agent) to a log file, the author put some code in the User-Agent. When the log file was displayed through the same feature, the code ran on the server, giving control.

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 iski

View all

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