LFI to RCE: Poisoning Your Own Log File

Day 14 made the shell run a command directly. Today the application does the work for you, by reading a file it was never supposed to read, and sometimes executing it along the way. Local File Inclusion, LFI, happens when an application takes user input and uses it to decide which file to open, include, or display, without properly restricting that input to the files it actually meant to offer. Remote File Inclusion, RFI, is the more severe sibling, where the application can be made to pull and execute a file from a server you control entirely.
This is the thirteenth class in the series, and it closes a loop that has been building since Day 9’s SSRF and Day 10’s XXE. All three classes share the same underlying question: what happens when the server fetches or reads something based on a value you supplied. SSRF asked it of an HTTP client, XXE asked it of an XML parser, and LFI asks it of the filesystem itself.
Inside scope only, with minimal proof. LFI can expose source code, configuration files, and credentials. Confirm with a known, harmless file, and escalate to code execution only as far as a single, documented command.
What LFI actually is
Many applications, especially older PHP codebases, build pages dynamically by including a file named in a request parameter.
<?php
$page = $_GET['page'];
include($page . '.php');
?>
The intended use: ?page=about loads about.php. The developer assumed the parameter would only ever hold a short, trusted page name. Nothing stops an attacker from supplying something else entirely.
?page=../../../../etc/passwd%00
If the application does not restrict the value to an allowlist of known page names, and the underlying language’s include function does what it is told, the server reads and, depending on the function used, potentially executes whatever file the traversal sequence points at. ../ repeated enough times walks up out of the intended directory and into anywhere else on the filesystem the web server process can read.
RFI is the same vulnerable pattern with one additional condition: the application’s configuration allows fetching and including a remote URL rather than only a local path, which, in older or misconfigured PHP environments, literally executes the fetched remote content as code the moment it is included, no local file write required at all.
Why this is still common, despite being decades old
Legacy PHP patterns never fully disappeared. Dynamic includes based on a parameter were a standard templating technique for years before modern frameworks and routing systems made the pattern largely unnecessary, and a huge amount of still-running production code predates that shift.
Developers reach for a blocklist instead of an allowlist. Stripping ../ once, rather than validating the final resolved path against a fixed list of permitted files, is the classic mistake, and it fails against encoded traversal sequences, double-encoded sequences, and path normalization quirks specific to the underlying operating system.
Wrapper and stream support in PHP creates its own attack surface beyond plain file paths. PHP’s php://, data://, expect://, and zip:// stream wrappers let an include-style vulnerability reach far beyond ordinary file reading, as the escalation techniques below show, turning a seemingly contained LFI into direct code execution without needing an external file write at all.
Modern frameworks are not fully immune either. Template engines, theme or plugin systems in content management platforms, and file preview or export features in current applications can reintroduce the same underlying mistake in a different form, a user-influenced value deciding which file on disk gets read.
Real disclosed reports
- U.S. Department of Defense, critical full local file read, disclosed via HackerOne. Among several LFI findings DoD has received through its public bug bounty program, this one was rated critical for allowing complete, unrestricted reading of local files on the affected system, illustrating how severity for this class scales directly with how little restriction stands between the parameter and the filesystem.
- U.S. Department of Defense, Pulse Secure file disclosure, CVE-2019-11510. This widely known vulnerability in Pulse Secure VPN appliances allowed an unauthenticated attacker to read arbitrary files, including ones containing plaintext credentials, and was subsequently exploited in the wild well beyond the original bug bounty disclosure, becoming one of the most consequential LFI-class vulnerabilities of its era specifically because VPN appliances sit at a uniquely privileged network position.
- Yahoo, Local File Include via a URL sub-parameter, disclosed through HackerOne. A parameter nested inside a larger URL value, rather than a simple top-level query parameter, was used to construct a file path server-side, a reminder that LFI-vulnerable parameters are not always the obvious, top-level ones your initial recon pass might flag first.
- GitLab, arbitrary file read via a documentation path parameter, disclosed through HackerOne. The flaw traced back to a
file_get_contents call built from a user-influenced docs path, read-only rather than include-based, and therefore a pure disclosure bug without a direct code execution path, but still enough to expose sensitive files outside the intended documentation directory.
- GSA Bounty, limited LFI, disclosed through HackerOne. A lower-severity example explicitly labeled “limited” by the researcher, worth knowing because not every LFI finding needs to read
/etc/passwd or achieve RCE to be valid and paid, a restricted-but-real file read within a narrower directory scope is still a legitimate, reportable finding.
- A private bug bounty program, LFI upgraded to unauthenticated RCE on a login form, documented in a widely referenced independent writeup by security researcher RCE Security. The researcher found an LFI in a
lang parameter on an unauthenticated login page, lang=../../../../../../etc/passwd returning the file’s contents directly, and then specifically pursued turning it into RCE before reporting, since RCE findings are consistently rated and paid higher than a read-only file disclosure of the same root cause.
Read the Pulse Secure CVE first, since it shows the real-world ceiling for this bug class, an unauthenticated file read vulnerability that went on to be weaponized at internet scale well beyond its original bounty report. Then read the RCE Security writeup for the clearest demonstration of deliberately escalating a basic LFI finding before submitting it, exactly the mindset the next section builds on.
Escalating LFI to code execution
A plain LFI that only reads files is a valid, often well-paid finding on its own. But the techniques below, several of which the RCE Security writeup above specifically credits as community knowledge, are what separate a disclosure-only report from a full RCE one, and RCE reports pay substantially more.
Log poisoning. Web servers log every incoming request, including the User-Agent header, by default, into a file the web server process itself can usually read. If the LFI can reach that log file, and you first send a request with a PHP payload planted inside the User-Agent header, <?php system($_GET['cmd']); ?>, the log file now contains your payload as plain text. Including that log file through the LFI causes the PHP interpreter to execute the payload embedded inside it, turning a read primitive into a code execution primitive using nothing but a header you control on an entirely separate, otherwise unrelated request.
The PHP ZIP wrapper technique. On a target where you can both upload a file and separately trigger an LFI, create a PHP file, compress it into a ZIP archive, upload the ZIP through any upload feature, even one that is not itself vulnerable, and then include it via the LFI using PHP’s zip:// stream wrapper syntax, ?page=zip://path/to/file.zip%23shell, which tells PHP to look inside the archive and execute the named file from within it directly, bypassing extension checks the upload feature might otherwise enforce since the archive’s own extension is the only thing that needs to pass.
The php://filter and data wrapper techniques. Where direct code execution via the wrappers above is not available, php://filter can still be used to read source code as base64-encoded output rather than having it execute, which is invaluable for source code disclosure on an LFI that cannot be escalated further, letting you recover application logic, hardcoded credentials, or further vulnerable code paths you would otherwise never see.
/proc/self/environ inclusion, largely a historical technique now. On older Linux systems running Apache with certain configurations, environment variables for the current process, including the User-Agent header value, were readable through /proc/self/environ, letting the same log poisoning concept work through a different file entirely. Most current distributions have closed this path, but it remains useful context for understanding the general pattern, planting a payload somewhere the server will read it back from, regardless of which specific file ends up being the vehicle.
Where to look, pointed at your recon
- Any parameter that resembles a filename, page name, or path.
page=, file=, template=, view=, include=, lang=, doc=, path=, straight from your Day 1 to 3 params.txt.
- Language and localization features, since the Yahoo and RCE Security cases above both involved exactly this kind of parameter, a value meant to pick a language file that instead becomes a direct filesystem path.
- Document, template, and theme preview features, especially in content management systems and admin panels surfaced through your JS file analysis, where a theme or layout name is used to construct a file path to include.
- Any feature exposing error messages that reveal the underlying file path structure, since this tells you exactly how many directory levels you need to traverse to reach the filesystem root, saving significant trial and error.
- Upload features present anywhere on the same application, even ones unrelated to the suspected LFI parameter, since the ZIP wrapper escalation technique specifically needs an upload path to exist somewhere, not necessarily on the same endpoint as the inclusion itself.
How to hunt it, step by step
Step 1: find candidate parameters. From recon, list every parameter resembling a file, page, path, or language selector.
Step 2: test basic traversal with a known file. Submit ../../../../etc/passwd and variations with more or fewer traversal sequences, since the correct depth depends on how many directory levels deep the application’s working path actually is.
Step 3: if basic traversal fails, try encoding and null byte variants. URL-encoded ..%2f, double-encoded ..%252f, and, on older PHP versions specifically, a trailing null byte to truncate an appended extension the application might be adding automatically.
Step 4: confirm the underlying language and check for wrapper support. If the target is PHP-based, test php://filter/convert.base64-encode/resource= wrapped around the suspected include target to attempt source code disclosure even where direct traversal is restricted.
Step 5: check for RFI specifically. Try supplying a URL you control instead of a local path, if accepted and the response reflects content fetched from your server, the application is vulnerable to RFI, a significantly more severe variant since it needs no local file write at all.
Step 6: if basic LFI is confirmed, attempt log poisoning. Send a separate request with a PHP payload in the User-Agent header, identify the correct log file path for the underlying web server and operating system, then include that log file via the LFI parameter and observe whether your payload executes.
Step 7: if an upload feature exists anywhere on the application, attempt the ZIP wrapper technique. Upload a ZIP archive containing a minimal PHP payload, then include it through the LFI using the zip:// wrapper syntax.
Step 8: prove execution with the smallest possible command, and clean up immediately. id or whoami output is sufficient proof. Remove any uploaded file or planted log entry as soon as the finding is documented.
Writing the LFI report
Title: Local File Inclusion in [parameter] at [endpoint] allows [file disclosure / remote code execution]
Summary:
One sentence: which parameter, which technique, and whether the
impact demonstrated was file read or code execution.
Steps to Reproduce:
1. Submit [request] with [traversal payload or wrapper syntax] in
[parameter].
2. Observe [file contents returned / base64-encoded source
disclosed] confirming the inclusion point.
3. (If escalated) Plant [payload] via [User-Agent header / uploaded
ZIP archive], then include [log file path / zip:// reference]
through the same parameter, and observe [command output]
confirming code execution.
(Exact requests for each step, response showing file contents or
command output, and confirmation that any planted payload or
uploaded file was removed.)
Impact:
The application includes a file determined by user-supplied input
without adequate restriction, allowing disclosure of arbitrary
local files [and, if escalated, remote code execution] under the
privileges of the web application process. State the realistic
worst case, source code and credential exposure at minimum, full
server compromise if code execution was demonstrated.
Remediation:
Never pass user input directly into a file inclusion or file read
function. Use a fixed, server-side allowlist mapping short,
validated identifiers to specific permitted file paths, rather
than constructing a path from input at all. Disable remote file
inclusion support at the language or framework configuration
level if it is not explicitly required. Restrict the web server
process's filesystem read permissions to only what the
application genuinely needs.
Strong LFI reports, the RCE Security writeup and the Pulse Secure CVE especially, clearly separate what was proven through basic traversal from what was additionally achieved through escalation, and explain exactly which technique bridged the two, which is what lets a triager immediately understand both the baseline severity and the ceiling.
What programs often reject
- Traversal payloads that return a generic error with no actual file content disclosed, with no further escalation attempted
- Findings against files explicitly intended to be readable by the application’s own design, where no genuine boundary was crossed
- RFI claims on an application correctly configured to block remote URL inclusion, where only local traversal actually succeeded
- Reports that achieve code execution but leave a live, unremoved webshell or planted log payload on the target’s infrastructure past the point needed to prove the finding
The mindset: a path is still just a string the server trusts
This series has repeatedly asked whether a boundary enforces what it claims to. An include statement or a file-read function has one job, and it does that job on whatever string it is handed, with no inherent concept of “the directories the developer meant” versus “the directories you can reach by walking far enough up the tree.” Whenever a parameter plausibly shapes a file path, the only real question is how many ../ sequences, or which wrapper, stand between that parameter and somewhere the developer never intended you to read.
Homework for Day 15
- From recon, list every parameter resembling a filename, page, template, or language selector across the target.
- Test basic directory traversal on each candidate, trying several traversal depths and both raw and URL-encoded forms.
- If the target is PHP-based, test
php://filter for source code disclosure even where direct file reads seem restricted.
- Where an upload feature exists anywhere on the application, attempt the ZIP wrapper escalation technique end to end in a lab or sandbox environment first, to understand the mechanics before trying it against a live target.
- Read the Pulse Secure CVE-2019-11510 writeup and the RCE Security private program writeup end to end. For each, note exactly which escalation path turned a file read into something more severe, and how each report framed the realistic impact.
A confirmed LFI with demonstrated source code or credential disclosure is typically high severity, and one escalated to code execution through log poisoning or a wrapper technique is usually critical. Document it with the exact traversal or wrapper payload, the escalation technique if applicable, and the allowlist-based remediation.
Day 16 moves to a bug where the vulnerability is not in what the application reads but in what it renders back to a template engine, Server Side Template Injection, and how it differs from the XSS you already know from Day 7.