Skip to content

LearnWeb and API

Path traversal and file read testing

Brief

A download or preview route that builds a file path from a name the user sends can often be walked out of its folder, letting anyone with an account read files the application can read, such as its database password. One harmless file proves the read, and the configuration file beside it, read with its secret masked, shows the impact.

Exam prep eJPT, OSCP

Stage
Escalation
Reviewed
On this page
  1. Check first
  2. How do I find a parameter that names a file?
  3. Which forms of../ does the server let through?
  4. What is the least-impact proof?
  5. How do I retest the fix?
  6. The defender sees
  7. Done when
  8. Not covered
  9. Tools
  10. Related research
  11. Reviewed

All commands

Situation
The input list from the first hour, a test account on an application named in the scope letter, and a route that takes a file name: a download, preview, template, export or language file. Every request on this page reads one file, and no secret value is printed.
Goal
One finding per route that reads outside its folder, with the form that got through, one harmless file and the configuration file with its secret masked.
Outputs
Captured on 5 Nov 2026 against the Atarus Bench Web and API lab fixture, edition web-api-0.3, running on loopback, with one origin playing every host, renamed to the example domains and printed as https (the lab ran plain http); the nginx and Express banners are the fixture's own, set by its Python code. The files are a fabricated tree inside the fixture whose / is its own scratch directory, so the /etc/hostname on this page is the fixture's file, not the capture host's.

Check first

  • The first hour input list, marked where a value names a file: name, file, path, template, lang and page parameters, downloads, previews and exports.
  • One normal request to each such route, so a 404 and a 200 mean something.
  • The server's operating system and language, since Windows also takes ..\ and the language decides how a path is joined.
  • Whether a firewall sits in front of the application, because its 403 and the application's 404 mean different things.
  • The client's agreement that one harmless file is the whole proof and that secrets are masked before they reach our evidence.

Steps

How do I find a parameter that names a file?

curl -s -D - -H "Authorization: Bearer $TESTER_A_TOKEN" \
  "https://app.example.com/api/documents/download?name=terms-2026.txt"

Expected output

HTTP/1.1 200 OK
Server: nginx/1.18.0
Content-Type: text/plain; charset=utf-8
Content-Length: 54
X-Powered-By: Express
Content-Disposition: attachment; filename="terms-2026.txt"   # <- the name we sent comes back as the file name

Ledger terms of service, 2026 edition (lab document).

The download route takes a file name in name and sends that file back, with the name repeated in Content-Disposition. A value that looks like a file name, an extension in a parameter, or that header is the mark of a route for this page. This request is the baseline: one known file, its size and its status.

Negative result. The route takes an id (/documents/412) and looks the file up on the server. There is no path to walk; test it for IDOR instead.

Fix. Take an id, not a name, and map it to a stored path on the server.

Which forms of ../ does the server let through?

for n in ../config/app.ini ..%2fconfig%2fapp.ini ....//config/app.ini /etc/hostname; do
  printf '%-24s ' "$n"
  curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TESTER_A_TOKEN" \
    "https://app.example.com/api/documents/download?name=$n"
done

Expected output

../config/app.ini        404
..%2fconfig%2fapp.ini    404
....//config/app.ini     200   # <- removing the inner ../ once joins the outer .. and / into a new ../
/etc/hostname            200   # <- an absolute name replaces the base folder

Four requests for files outside the documents folder, status only, so nothing is read yet. The plain ../ and its URL-encoded form both get 404: the server decodes the query string before its filter sees it, so both reach the filter as ../ and are stripped. ....// gets through, because a filter that removes ../ once leaves ../ behind. The absolute name gets through because of how the application joins it to the base folder. Some join functions return the second path whole when it is absolute: Python's os.path.join, Java's Path.resolve and Node's path.resolve do, and Node's path.join does not.

Negative result. All four get the same answer as any missing file, a 404 or a 400, and no form returns a 200.

Why this works

Filters work on the string the user sent; the file system works on the resolved path. Any filter that does not resolve the path first can be beaten by a form the filter's author did not list.

Fix. Join the name to the base folder and resolve the result to its real path, following symlinks (os.path.realpath in Python, Path.toRealPath in Java, fs.realpathSync in Node; path.resolve alone does not follow links). Then check that it starts with the resolved base folder followed by a separator, and refuse anything else before opening a file. Never filter ../ out of the string.

What is the least-impact proof?

curl -s -H "Authorization: Bearer $TESTER_A_TOKEN" \
  "https://app.example.com/api/documents/download?name=/etc/hostname"

Expected output

ledger-app-01   # <- a file outside the documents folder, harmless to read

/etc/hostname exists on nearly every Linux server, holds nothing sensitive and proves the read; on Windows, C:\Windows\win.ini plays the same part. We do not read /etc/shadow, private keys, /proc/self/environ or the application's source. The finding's weight is the configuration file beside the application, so we read that once with the secret masked by the command itself:

curl -s -H "Authorization: Bearer $TESTER_A_TOKEN" \
  "https://app.example.com/api/documents/download?name=....//config/app.ini" \
  | sed -E 's/^(password *= *).*/\1<masked>/'

Expected output

[database]
host = db01.corp.example.com
user = ledger
password = <masked>   # <- masked before printing; only a key named password is masked

[mail]
relay = smtp.corp.example.com

The sed runs before anything is printed, so the evidence holds the file's shape and the name of the secret, not its value. The pattern masks only a key named password. When the file may hold others, such as secret_key or api_token, mask every value with s/=.*/= <masked>/ and keep only the key names. The report says the route can read the database password, and the client rotates it, since anyone who found the route before us could have read it too.

Negative result. The harmless file gets the same 404 as any missing file.

Fix. The resolve-then-check above. Keep secrets out of files the application's own account can read: a secrets manager or environment injected at start, so a read through the application finds no password to take.

How do I retest the fix?

for n in 2026-10.csv ../config/app.ini ....//config/app.ini /etc/hostname; do
  printf '%-24s ' "$n"
  curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TESTER_A_TOKEN" \
    "https://app.example.com/api/statements/download?name=$n"
done

Expected output

2026-10.csv              200   # <- the one file this route serves
../config/app.ini        400
....//config/app.ini     400
/etc/hostname            400   # <- refused before any file is opened

The retest sends the same forms to the fixed route, plus one name it should serve. The lab keeps a second route written the fixed way, the statement download, so this page can show the answer a fix gives: it normalises the path and requires the statements folder as the parent, so every form gets 400 and the real file still gets 200. The lab tree has no symlinks, so normalising is enough there; a real fix resolves the real path as above. On an engagement this is the same route after the client's change.

Negative result. Every form gets a 400, or the same 404 as a missing file, and the legitimate name still gets a 200: the fix holds.

Fix. If any form still gets a 200, the change filtered strings instead of resolving the path; send it back with the resolve-then-check above.

The defender sees

Each request is one access log line with the form in the query string: ....//, ..%2f, %2e%2e and absolute names in name are easy to match, and a 200 on one of them is worth an alert. A firewall running the OWASP Core Rule Set flags ../ and its encoded forms in its 930 local file inclusion group; a doubled form such as ....// can slip past those rules, which is one more reason the fix belongs in the application. The read itself leaves nothing else: opening a file for reading is not logged by default on Linux, and file integrity monitoring watches for changes, not reads. If nothing logged the requests, that goes in the report beside the finding.

Done when

Every route that takes a file name has had the four forms, and each one that reads outside its folder has one harmless file and one masked configuration file saved with their requests.

Not covered

Writing files through a path, archive extraction that writes outside its folder, inclusion that runs the file as code, Windows paths and UNC names, and reading anything beyond one harmless file and one masked configuration file.