Path Traversal · Lab 20
Lab 20 Module 4 Medium

Path Traversal

A site serves files from a public directory. It takes a filename as input. It does not check that the file is inside that directory. Use ../ to walk out — and read files that were never meant to be public.

The rule: the file server serves files from /public. There is a file outside that directory that holds the flag. Find it by walking up the tree.

Test

Copy these. Run them. Read what comes back.

Step 1 · Read a normal file

The endpoint takes a filename. Start with one you're allowed to see.

Terminal
curl -s "{LAB_API_BASE}/api/20/file?name=readme.txt"

What you'll see:

Response
Welcome to the lab file server.
Files here are public. Nothing interesting.

The server read readme.txt from the public directory and returned it. The endpoint trusts the name parameter completely — it prepends the server-side root /public/ and opens whatever the filesystem resolves.

Step 2 · Walk up the tree

On Unix, ../ moves up one directory. The endpoint does not sanitize the name. Try reaching a file in a sibling directory the public one can't see.

Terminal
curl -s "{LAB_API_BASE}/api/20/file?name=../private/flag.txt"

What you'll see:

Response
HL{p4th_tr4v3rs4l_pwn}

You read a file outside the public directory. That file is not supposed to be reachable from the file server. The ../ walked the path up and out of /public/, into /private/.

Step 3 · Understand what happened

The server built the path as /public/ + ../private/flag.txt. The filesystem resolved that to /private/flag.txt — a directory one level above the public one. There is no validation. There is no jail. The string you send becomes the path that gets opened.

Challenge

Now do it yourself. No copy-paste. Everything you need is above.

One level up got you the flag file /private/flag.txt. But /private/ holds another file — deep.txt — that never came up in any directory listing you've seen.

Reach it. The same traversal you just used works. Point the name parameter at the file at /private/deep.txt by walking up from /public/. The flag is inside it.

If you're feeling curious: the server also decodes URL-encoding more than once. Try %252e%252e/private/deep.txt — a double-encoded ../. It resolves to the same path. That's why filters at the wrong layer never fix this bug.

This lab is free. The deep and the full knowledge is in the book. Full 30 Lessons

Lesson 20 — Path Traversal

You've practiced the exploit. Now learn why it happens, how attackers weaponize it, developer mistakes, how to fix it etc in the full Hunterlian book.

Buy the book

Already have the book? Back to reader →