LFI Explained: Local File Inclusion for Bug Bounty Beginners (and How to Prevent It)
Some of the oldest bugs in web security are still the ones paying bounties today. Local File Inclusion — LFI — has been around since the early days of PHP, and it still shows up in modern applications whenever a developer lets user input decide which file the server loads. If you’re starting in bug bounty, LFI is one of the highest-value bugs to learn: it’s common, it’s easy to test for, and when it hits, it can expose the server’s most sensitive files.
What LFI Actually Is
Many websites load content by including a file whose name comes from the URL. A page like this is the classic setup:
https://example.com/index.php?page=about
The server takes the page value, builds a path like pages/about.php, and includes it. The problem starts when the server trusts that value completely. If you can change about to something else, you can make the server include a different file — one it was never supposed to show you.
The Basic Test
On a target you have permission to test — a bug bounty program in scope, or your own lab — try swapping the parameter for a file that exists on every Linux server:
https://example.com/index.php?page=../../../../etc/passwd
The ../ sequences walk up out of the intended directory, one level at a time. If the page suddenly shows the contents of /etc/passwd — the system’s user list — you’ve found LFI. The same trick works with other files: /etc/hosts, application config files, and anything else the web server process can read.
Why It’s Dangerous
Reading /etc/passwd is only the beginning. LFI gets serious when the attacker can:
- Read application config files — database credentials, API keys and session secrets often sit in files the web server can read.
- Read log files — and then poison them. If an attacker can get their own input written into a log file (through a User-Agent header, for example), and then include that log file through LFI, the log becomes executable code. That turns a file-read bug into full remote code execution.
- Chain it with file upload — if the application lets users upload images, an attacker can upload a file containing code and then include it through the LFI flaw.
This escalation path — from reading files to running code — is why LFI reports with a working proof of concept earn real bounties.
How to Test for It (Legally)
- Only test targets in scope. A bug bounty program’s scope tells you exactly what you’re allowed to test. LFI testing outside scope is unauthorized access.
- Start with harmless files. /etc/passwd proves the bug without damaging anything. Never try to read or modify files that could disrupt the target.
- Try the common wrappers. PHP’s php://filter wrapper lets you read a file’s source code as base64, which is useful when the server executes PHP files instead of displaying them: php://filter/convert.base64-encode/resource=index
- Watch for the tell. A page that suddenly shows file contents, throws a “file not found” error naming a path, or changes behaviour when you add ../ is worth a closer look.
How Developers Prevent It
If you build web apps, LFI is easy to prevent:
- Never build file paths from user input. Use a fixed allowlist of page names instead: if the value isn’t in the list, reject it.
- Strip path separators. Remove ../, / and null bytes from any input that touches the filesystem.
- Use basename() or equivalent. Reduce any file input to just the filename, so directory traversal becomes impossible.
- Run with least privilege. The web server process should only be able to read the files it actually needs.
LFI is a reminder that the web’s oldest mistakes never really die — they just move into new codebases. Learn to spot the pattern (user input becoming a file path), test it safely in scope, and you’ll have a bug class that keeps paying for years.
Only test systems you own or have written permission to test.



Comments
Post a Comment