Local File Inclusion (LFI)
What is Local File Inclusion (LFI)?
Local File Inclusion (LFI)A vulnerability that lets an attacker make a server include and execute or display local files chosen via unsanitized input.
Local File Inclusion (LFI) arises when a web application passes user-controlled input into a file-loading function — PHP include/require, JSP, or classic ASP — without validation, letting an attacker choose which local file the server reads or executes. It is catalogued as CWE-98 (improper control of filename for include/require) and overlaps with directory traversal (CWE-22), but LFI specifically abuses the language's include machinery, so disclosed files can run as code. Classic payloads read /etc/passwd, application source, or configuration holding database credentials.
The real danger is escalation to remote code execution. Attackers use log poisoning (injecting PHP into a User-Agent or SSH log, then including that log), /proc/self/environ, PHP session files, or uploaded images with embedded code. Since 2022, the PHP filter chain technique (popularised by Synacktiv) weaponises php://filter wrappers: a long sequence of convert.iconv.* and convert.base64-* filters generates an arbitrary PHP payload from any file — even an empty one — turning a pure file-read primitive into full RCE, and an error-based variant leaks file contents even when output is never echoed back. LFI has featured in countless breaches of PHP CMSs and appliance admin panels.
Defences: never build include paths from user input; use allow-lists of fixed template names mapped through a lookup table; canonicalise and verify paths stay within a base directory; disable allow_url_include; and restrict the php://filter wrapper where the runtime permits.
flowchart TD
A[User input: ?page=value] --> B{Path validated<br/>against allow-list?}
B -->|Yes| C[Include fixed template safely]
B -->|No| D[Attacker-controlled path]
D --> E[../../etc/passwd<br/>read sensitive files]
D --> F[Log poisoning /<br/>session / proc entries]
D --> G[php://filter iconv chain<br/>Synacktiv technique]
F --> H[Remote Code Execution]
G --> H● Examples
- 01
An endpoint with page=../../../var/log/apache2/access.log that executes attacker-controlled User-Agent strings as PHP.
- 02
An admin panel using ?lang=es that becomes vulnerable when ?lang=../../etc/passwd discloses system users.
● Frequently asked questions
What is Local File Inclusion (LFI)?
A vulnerability that lets an attacker make a server include and execute or display local files chosen via unsanitized input. It belongs to the Attacks & Threats category of cybersecurity.
What does Local File Inclusion (LFI) mean?
A vulnerability that lets an attacker make a server include and execute or display local files chosen via unsanitized input.
How do you defend against Local File Inclusion (LFI)?
Defences for Local File Inclusion (LFI) typically combine technical controls and operational practices, as detailed in the full definition above.
What are other names for Local File Inclusion (LFI)?
Common alternative names include: LFI.