LFI to RCE
The article demonstrates how a local file inclusion (LFI) vulnerability in DVWA allows an attacker to include and execute files on the server. By poisoning the Apache access log with PHP code in the User-Agent header and then including that log file via the LFI, the attacker achieves remote code execution (RCE).
medium.com
Published on medium.com
In this article, I will show how can you get Remote Code Execution (RCE) using Local File Inclusion (LFI). However, before diving into the details, let’s first explore and understand each of these vulnerabilities individually.
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 a file based on user input without validating it, and it also logs user-controlled data (the User-Agent header) to a file that can be included.
Impact
An attacker could execute arbitrary commands on the server, leading to full system compromise.
What the attacker needed
Access to a vulnerable LFI endpoint; ability to write to a log file via requests; log file readable by the web server
The fix
The application should validate and sanitise user input used in file inclusion, and avoid logging unsanitised user input that can be included.
How it was found
- Identify that the page parameter is used to include files and try to include /etc/passwd to confirm LFI.
- Send a request with PHP code in the User-Agent header so it gets written to the Apache access log.
- Use the LFI to include the access.log file, causing the PHP code in the log to execute.
- Observe the command output in the response, confirming RCE.
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 choose which file on the server it loads. If the page also writes your input into a log file, you can put code into that log and then ask the page to load the log, which runs your code. This is called log poisoning and leads to remote code execution (RCE), meaning the attacker can run commands on 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.