What You'll Learn
You'll learn how attackers manipulate file paths using sequences like ../ to break out of intended directories and access sensitive files they shouldn't be able to reach.
The Core Problem
When applications accept user-provided filenames for file operations (like uploads, downloads, or includes), they often assume the file will stay within a designated folder. Path traversal exploits the way operating systems handle relative paths to escape these boundaries.
How It Works
Imagine an application that serves user profile pictures from /var/www/uploads/. If a user requests profile.jpg, the server constructs the full path: /var/www/uploads/profile.jpg and returns it.
But what if an attacker submits ../../etc/passwd as the filename?
The server might construct: /var/www/uploads/../../etc/passwd
The ../ sequences tell the operating system to move up one directory level. Two ../ moves up twice:
- Start:
/var/www/uploads/ - After
../:/var/www/ - After
../../:/var/ - Final:
/var/etc/passwd
Now the attacker has accessed a system password file instead of a harmless profile picture.
Real-World Example
GET /download?file=../../../../etc/shadow
GET /avatar?filename=../../../config/database.yml
POST /import data=../../app/secrets.env
These requests attempt to "climb" the directory tree to reach sensitive configuration files, credentials, or source code.
Why It's Dangerous
Path traversal can expose:
- Configuration files with database credentials
- Application source code
- System files like
/etc/passwd - Other users' uploaded files
- Private cryptographic keys
Key Takeaway: Path traversal exploits inadequate input validation by using ../ sequences to navigate outside intended directories, potentially exposing any file the web server process can read.