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

What to check

  • Grep for include, require, include_once, require_once and 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.php present and register_argc_argv On? Is the app on the official php Docker 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 .php outside 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_argv Off.
  • 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.

Sources