Path traversal Cheat Sheet
Path Traversal Cheat Sheet
General knowledge recall, not freshly verified against current docs — cross-check OS/framework-specific path handling details before relying on them.
1. What It Is
An app takes user input and uses it (directly or with partial sanitization) to build a filesystem path — for reading, writing, including, or deleting a file. If the input isn’t properly constrained, the attacker can reference a path outside the intended directory using ../ (or OS/encoding variants) to reach arbitrary files.
Related but distinct: Local File Inclusion (LFI) — traversal where the result is executed (e.g., PHP include()), not just read. Remote File Inclusion (RFI) — same but the “file” is a remote URL. Both build on the same root cause.
2. Where to Spot It (candidate parameters)
Look for any parameter that smells like a filesystem reference:
- Obvious:
file=,path=,filename=,doc=,page=,template=,include=,load= - Less obvious:
lang=en(loading a language file),theme=,download=,report=,image=,attachment=, avatar/upload filenames, log viewers,?id=that turns out to resolve to a file on disk - File upload features where the filename itself is attacker-controlled and later used in a file operation
- Any feature that reads/serves/previews/exports a file based on user input
3. How to Test
3.1 Baseline probes
Start simple, from the parameter’s apparent working directory:
?file=../../../../etc/passwd (Linux)
?file=..\..\..\..\windows\win.ini (Windows)
Watch for:
- File contents returned directly → confirmed
- A different error message than “file not found” (e.g., a permissions error vs. not-found) → partial confirmation, keep adjusting depth
- No visible change → may still be vulnerable but blind (see 3.5), or genuinely not injectable
3.2 Depth guessing
You usually don’t know how deep the web root is. Pad with extra ../ — most implementations simply ignore traversal past the filesystem root, so over-padding (../ x10+) is safe and often used by default:
?file=../../../../../../../../etc/passwd
3.3 Filter bypass techniques (test each if the basic payload is blocked/stripped)
| Technique | Example |
|---|---|
| URL encoding | %2e%2e%2f for ../ |
| Double URL encoding | %252e%252e%252f (useful if the app decodes once before filtering, then a downstream component decodes again) |
| Absolute path (skip relative entirely) | file=/etc/passwd |
| Null byte (legacy, mostly patched in modern language runtimes) | file=../../etc/passwd%00.jpg — historically used to truncate an appended extension |
| Non-recursive filter bypass | ....//....// (if the filter strips ../ once without re-checking the result, this collapses back into ../../) |
| Unicode / overlong UTF-8 encoding | %c0%ae%c0%ae/ variants on some older/misconfigured servers |
| Mixed slash direction (Windows backends) | ..\/..\/ or ..%5c..%5c |
| Case variation (on case-insensitive filesystems/filters) | rarely relevant but cheap to try |
3.3b Ready-to-paste /etc/passwd payloads (plain, encoded, double-encoded)
Plain, at a few common depths:
../../../../etc/passwd
../../../../../../etc/passwd
../../../../../../../../etc/passwd
URL-encoded (.=%2e, /=%2f):
%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
Double URL-encoded (%→%25; only works when something in the chain decodes, filters, then decodes again — e.g. a WAF decodes once and checks, the app server decodes again before file access):
%252e%252e%252f%252e%252e%252f%252e%252e%252f%252e%252e%252fetc%252fpasswd
%252e%252e%252f%252e%252e%252f%252e%252e%252f%252e%252e%252f%252e%252e%252f%252e%252e%252fetc%252fpasswd
Other quick variants:
....//....//....//....//etc/passwd (non-recursive filter bypass)
..%2f..%2f..%2f..%2fetc/passwd (mixed literal dots + encoded slash)
/etc/passwd (absolute path)
3.4 OS-specific high-value targets to request once traversal is confirmed
- Linux:
/etc/passwd(confirmation, low sensitivity),/etc/shadow(requires privilege, good escalation proof point), app config files (/var/www/.env,config.php),/proc/self/environ, web server config (/etc/nginx/nginx.conf,/etc/apache2/apache2.conf), SSH keys (~/.ssh/id_rsa) if path is guessable. - Windows:
C:\windows\win.ini(confirmation),C:\windows\system32\drivers\etc\hosts, application config files, IIS config (web.config). - Always start with a harmless confirmation file (
/etc/passwd,win.ini) before touching anything more sensitive — matches the principle of minimal-impact proof.
3.5 Blind path traversal (no content reflected back)
- Compare response differences (status code, length, timing) between a valid vs. invalid traversal depth/path, same approach as blind SQLi.
- If the feature writes/includes rather than displays (e.g., a template include), look for indirect evidence: error messages naming a path, behavior change, or — if the app executes the included file (LFI) — attempt to include a file you can influence content of (log poisoning: inject a payload into something logged, like
User-Agent, then traverse to and include the log file so it executes).
3.6 File upload / filename-based traversal
- If a feature accepts a filename from the user (upload name, “save as” name, export filename) and later uses that filename in a path operation, test traversal sequences inside the filename itself:
../../../../var/www/html/shell.phpas the upload’s filename. - Check whether the server strips the original extension/path server-side or trusts the client-supplied name as-is.
3.7 Confirming severity
- Read-only traversal: information disclosure — severity depends on what’s reachable (config/credentials/source vs. a non-sensitive known file).
- Traversal + inclusion (LFI): can escalate to RCE if combined with an injectable write point (log poisoning, upload, session file injection) — a much higher-severity finding, worth calling out explicitly in a report rather than stopping at “file read.”
- Write-capable traversal (less common — export/save functions): can lead to arbitrary file overwrite, potentially overwriting app code or config.
4. Documentation for Reporting
- Exact parameter, exact payload (including any encoding used), and the file retrieved as proof (redact sensitive contents in the write-up, just show enough to prove read access — e.g., the first few lines of
/etc/passwd). - Note which bypass technique was required, if any, since “basic
../works” vs. “required double-encoding to bypass a filter” are different findings for the remediation team. - If LFI/RCE escalation was demonstrated, document that chain separately and clearly — it changes the severity rating.