Local File Inclusion
Path Traversal into an interpreter’s include or template loader: the application executes or renders a local file chosen by the attacker, turning file selection into code execution whenever any reachable file contains, or can be made to contain, code (CWE-98).
How it works
- Sink. PHP
include/require(and template resolution that ends in one) interpret the target as source code. The classic shape is a request parameter concatenated into an include path with no validation. Chaining Security Bugs in Discuz! X5.0: from Race Condition to Pre-Auth RCE - Read vs execute. Including a non-code file discloses it; including a file holding interpreter code runs it. That makes LFI a read primitive and, with a second step, an RCE primitive.
- Getting code onto disk. The notes show three routes:
- An uploaded file the app thinks is an image: upload, then include it. Discuz! documents this chain; the PayloadPlayground upload guide names upload + LFI as an execution path when the upload directory itself won’t execute. File Upload Vulnerability Testing: Bypassing Filters and Getting RCE
- A file already on the box that acts as a gadget: PEAR’s
pearcmd.phpwhenregister_argc_argvis On (default in the officialphpDocker image and in default cPanel with PHP before 8.5). Used against WordPress core and in HTB Pterodactyl. WordPress: Unauthenticated path traversal leading to conditional RCE 0xdf hacks stuff - Session or other server-written files: Wiz observed PHP2Shell-branded tools that actually relied on session poisoning plus a separate LFI. PHP2Shell: Exploitation Attempts and Remediation Trends
- Second-order directory. In Discuz! X5.0 the include filename was regex-checked, but the plugin directory came from importable plugin data stored in the DB, so the check passed while the resolved path pointed at the attachments directory.
- Path from the URL itself. WP Ghost rebuilt a filesystem path from the URL-decoded request URI in its 404 handler and passed it to
include, reachable unauthenticated. Critical LFI to RCE in WP Ghost Plugin Affecting 200k+ Sites - Non-PHP “LFI”. In Python/Flask apps the term is used for arbitrary file read through a file parameter; the impact comes from what is read (app secrets, source), e.g. leaking a
SECRETenv var to forge an admin cookie, then Jinja2 SSTI. Poet writeup: LFI to forged cookie to Jinja2 SSTI RCE A URL fetcher acceptingfile://gives the same read; see Local File Read via SSRF. How an Unauthenticated MCP Server Led to SSRF, LFI, and AWS Credential Theft - CloudSEK - Strip-once filters fail. The TryHackMe “Include” room needed a non-recursive-filter bypass, i.e. the app removed traversal sequences once instead of rejecting them. TryHackMe Include: BOPLA, SSRF, LFI and SSH
What to check
- Grep for
include,require,include_once,require_onceand template/view loaders whose argument contains any variable; trace each variable to a source (request, URI, DB, import data, config). - Treat DB- and import-sourced path components as untrusted (second-order).
- Is the target matched against a fixed allowlist, or only filtered? Strip/replace filters are a finding by themselves.
- Does the 404/fallback or rewrite layer map URLs to files?
- Which writable locations can the web user reach (uploads, attachments, sessions, logs)? Are any includable?
- Is
pearcmd.phppresent andregister_argc_argvOn? Is the app on the officialphpDocker image? - For theme/template resolution (WordPress), do theme directories create unexpected match points (the core bug needed a top-level theme directory starting with
page-)? - For read-only LFI, what secrets would hand over the next step (signing keys, env, source)?
Notable cases
- WordPress core 4.7–7.1.1 —
get_page_template()includes a chosen local.phpoutside theme dirs, unauthenticated, conditional RCE; fixed in 7.1.2 and backported. WordPress path traversal - WP Ghost — CVE-2025-26909 — unauthenticated LFI to RCE, CVSS 9.6, 200k+ sites, fixed in 5.4.02. WP Ghost LFI
- Discuz! X5.0 (and X3.5) — KIS-2026-11 — admin plugin LFI, final link of a pre-auth RCE chain after a race-condition auth bypass. Discuz! X5.0 chain
- Pterodactyl panel (HTB) — unauthenticated locale-endpoint traversal makes PHP include files, chained with pearcmd. 0xdf hacks stuff
- Unauthenticated MCP server — media fetch tool accepted
file://, read the process environment, then AWS creds via IMDS. CloudSEK MCP Server - YesWeHack snippet series includes LFI via
include()and LFI-to-RCE via pearcmd as review exercises. GitHub - yeswehack/vulnerable-code-snippets
Defenses
- Allowlist, don’t filter. Map a small set of keys to fixed files; never place request data in an include path.
$pages = ['home' => 'home.php', 'about' => 'about.php']; $key = $_GET['page'] ?? 'home'; if (!isset($pages[$key])) { http_response_code(404); exit; } include __DIR__ . '/pages/' . $pages[$key]; - If a dynamic path is unavoidable, canonicalize and verify it sits under the intended directory, and validate every component including DB/import-derived directories (see Path Traversal > Prevention).
- Remove gadgets: drop PEAR from production images, keep
register_argc_argvOff. - Keep code and data apart: store uploads and attachments outside any includable tree, randomize names, and don’t let uploads land in executable or includable paths (Unrestricted File Upload).
- Restrict fetchers to
http(s)so URL tools can’t become file readers (Local File Read via SSRF, MCP Security). - Patch the platform: WordPress 7.1.2 (and backports), WP Ghost 5.4.02.
Related
- Path Traversal (parent guide) · Zip Slip and Archive Extraction · Unrestricted File Upload · Web Shells · Remote Code Execution · Local File Read via SSRF · Server-Side Template Injection · Jinja2 SSTI · Race Conditions · Vulnerability Chaining
Sources
- Chaining Security Bugs in Discuz! X5.0: from Race Condition to Pre-Auth RCE · original
- File Upload Vulnerability Testing: Bypassing Filters and Getting RCE · original
- WordPress: Unauthenticated path traversal leading to conditional RCE · original
- 0xdf hacks stuff · original
- PHP2Shell: Exploitation Attempts and Remediation Trends · original
- Critical LFI to RCE in WP Ghost Plugin Affecting 200k+ Sites · original
- Poet writeup: LFI to forged cookie to Jinja2 SSTI RCE · original
- How an Unauthenticated MCP Server Led to SSRF, LFI, and AWS Credential Theft - CloudSEK · original
- TryHackMe Include: BOPLA, SSRF, LFI and SSH · original
- GitHub - yeswehack/vulnerable-code-snippets: Twitter vulnerable snippets · original