RCE via LFI — OSCP Tactics for Code Execution and Gaining a
A PHP web application had a local file inclusion (LFI) vulnerability in a page parameter, allowing an attacker to include and execute local files. The attacker injected PHP code into the Apache access log via the User-Agent header, then used the LFI to execute that code, achieving remote command execution and a reverse shell.
🔥 FREE VERSION — Click here for Free Article 🔥
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 included files based on user input without proper validation, and the log file was writable and executable via the LFI.
Impact
An attacker could execute arbitrary commands on the server and gain a reverse shell, leading to full system compromise.
What the attacker needed
LFI vulnerability in a parameter; Log file writable and accessible; PHP code execution via LFI
How it was found
- Identify an LFI vulnerability in the index.php?page= parameter.
- Inject PHP code into the User-Agent field, which gets written to the Apache access log.
- Use the LFI to include the access log file and execute the injected PHP code.
- Execute commands via the cmd parameter to confirm remote code execution.
- Send a URL-encoded reverse shell payload through the cmd parameter.
- Set up a listener and catch the reverse 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.
Local File Inclusion (LFI) is a bug where a web page lets you load files from the server by changing a parameter. Unlike simply reading a file, LFI can sometimes run the file if it contains code. Here, the attacker wrote PHP code into a log file (which the server records) and then used the LFI to run that log file, giving them control of 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.