Hack Notes
GithubTwitterTryHackMeHackTheBox
  • Hack Notes
    • # whoami
  • 🕸️Web Application Security
    • Web Application Security Notes
      • SQL Injection
        • Basic Microsoft SQL injection Cheatsheet
        • Basic PostgreSQL injection Cheatsheet
        • Basic MySQL Injection Cheatsheet
        • Basic Oracle SQLi Cheatsheet
      • Authentication Vulnerabilities
        • Authentication Flaws Checklist
        • Authentication Vulnerability Practical
      • Directory Travarsal
        • Directory Traversal Lab
      • Command Injection
        • Command Injection Labs
      • Business logic flaws
        • Business Logic Vulnerabilities Labs
      • Information Disclosure
        • Information Disclosure Labs
      • Access Control
        • Broken Access Controls in Practice
      • File Upload Vulnerability
      • Server Side Request Forgery (SSRF)
      • XML External Entity Injections
      • Web Penetration Testing Tools
  • 📖Writeups
    • TryHackMe
      • The advent of Cyber 1 (2019)
      • THM Basic Pen-Testing Machine
      • THM Room CC: Pentesting
      • THM Machine DailyBugle
      • THM Machine Fortress
      • THM Machine Internal
      • THM Room: OWASP Top 10 Answers
      • THM Machine: Overpass
      • THM Machine: Overpass 2 - Hacked
      • THM Machine: Overpass 3 - Hosting
      • THM Room: Pickle Rick CTF
      • THM Machine Relevant
      • THM Machine: SkyNet
      • THM Room: Web Fundamentals
  • ☠️CNWPP
    • CNWPP
      • CNWPP Content
      • Week #1 Introduction to Pentest
      • Week #2 Pentesting Methodologies
      • Week #3 Network Pentesting
      • Week #4 Web Application Pentesting
  • 🏛️Active Directory (AD)
    • Active Directory Attacks
      • LLMNR Poisoning Attack
      • SMB Relay Attack
      • IPv6 Attacks
        • IPv6 Attack In Action
      • Kerberos
        • Kerberos Pre Authentication Attack
        • Kerberoasting
        • DCsync Attack
Powered by GitBook
On this page
  • LAB #1: File path traversal, simple case
  • LAB #2: File path traversal, traversal sequences blocked with absolute path bypass
  • LAB #3: File path traversal, traversal sequences stripped non-recursively
  • LAB #4: File path traversal, traversal sequences stripped with superfluous URL-decode
  • LAB #5: File path traversal, validation of the start of the path
  • LAB #6: File path traversal, validation of file extension with null byte bypass

Was this helpful?

  1. Web Application Security
  2. Web Application Security Notes
  3. Directory Travarsal

Directory Traversal Lab

LAB #1: File path traversal, simple case

Lab URl: https://portswigger.net/web-security/file-path-traversal/lab-simple

Objective: view the content of /etc/passwd

This lab contains a shopping application that has different products. Each product has its image and they are getting that image from an image API using a parameter name filename. The full URL of the image API is like the following.

https://0a30000b0355a606c1d7941d00800012.web-security-academy.net/image?filename=65.jpg

This didn't enforce any protection against directory traversal so attackers can use directory traversal to view server internal files. Using the following command we can get the content of the /etc/passwd file.

curl https://0a30000b0355a606c1d7941d00800012.web-security-academy.net/image?filename=../../../../etc/passwd

As the API is used for giving an image file so the browser will not show the content in the browser they will show the following error.

The image "https://0a30000b0355a606c1d7941d00800012.web-security-academy.net/image?filename=../../../../etc/passwd" cannot be displayed because it contains errors.

So we must use tools like curl that will show us raw responses.

LAB #2: File path traversal, traversal sequences blocked with absolute path bypass

Lab URL: https://portswigger.net/web-security/file-path-traversal/lab-absolute-path-bypass

Objective: view the content of /etc/passwd

This lab contains a shopping application that has different products. Each product has its image and they are getting that image from an image API using a parameter name filename. The full URL of the image API is like the following.

https://0a2100ff03287847c5707ebf004200f8.web-security-academy.net/image?filename=25.jpg

They enforce some protection that will strip any combination of ../ and they are striping that in the loop so we cannot use payload like this ....//....// will also block any URL encoding also doesn't work. But by using an absolute path they will give us the content of the /etc/passwd file.

curl https://0a2100ff03287847c5707ebf004200f8.web-security-academy.net/image?filename=/etc/passwd

LAB #3: File path traversal, traversal sequences stripped non-recursively

Lab URL: https://portswigger.net/web-security/file-path-traversal/lab-sequences-stripped-non-recursively

Objective: view the content of /etc/passwd

This lab contains a shopping application that has different products. Each product has its image and they are getting that image from an image API using a parameter name filename. The full URL of the image API is like the following.

https://0a2100ff03287847c5707ebf004200f8.web-security-academy.net/image?filename=25.jpg

They enforce some protection that will strip any combination of ../ but they didn't do striping in a loop or recursively so we can use payload like this ....//....// and that will bypass the protection and give us the contents of /etc/passwd file.

curl https://0ac400c9034b1ecac1a9a98400c5000e.web-security-academy.net/image?filename=....//....//....//....//....//etc/passwd

LAB #4: File path traversal, traversal sequences stripped with superfluous URL-decode

Lab URL: https://portswigger.net/web-security/file-path-traversal/lab-superfluous-url-decode

Objective: view the content of /etc/passwd

This lab contains a shopping application that has different products. Each product has its image and they are getting that image from an image API using a parameter name filename. The full URL of the image API is like the following.

https://0a68000304308ecac0dcf95800c800af.web-security-academy.net/image?filename=5.jpg

They enforce some protection against directory traversal attacks in which they block any sequences ../ and we can also don't get the files using an absolute path. Using a double URL to encode the directory traversal payload we can get the context of the /etc/passwd file.

curl https://0a68000304308ecac0dcf95800c800af.web-security-academy.net/image?filename=..%252f..%252f..%252fetc/passwd

LAB #5: File path traversal, validation of the start of the path

Lab URL: https://portswigger.net/web-security/file-path-traversal/lab-validate-start-of-path

Objective: view the content of /etc/passwd

This lab contains a shopping application that has different products. Each product has its image and they are getting that image from an image API using a parameter name filename. The full URL of the image API is like the following.

https://0a11006b04fb4ccfc0c6402100f8006c.web-security-academy.net/image?filename=/var/www/images/13.jpg

In the above URL, we can see the filename parameter start with the directory /var/www/image if we didn't pass that path in our URL they show us an error saying

Missing parameter 'filename'

They are validating if the URL has that path or not if not then throw an error. This validation can easily be bypassed using a payload like the following.

/var/www/images/../../../etc/passwd

we can get the contents of /etc/passwd using the following command.

curl https://0a11006b04fb4ccfc0c6402100f8006c.web-security-academy.net/image?filename=/var/www/images/../../../etc/passwd

LAB #6: File path traversal, validation of file extension with null byte bypass

Lab URL: https://portswigger.net/web-security/file-path-traversal/lab-validate-file-extension-null-byte-bypass

Objective: view the content of /etc/passwd

This lab contains a shopping application that has different products. Each product has its image and they are getting that image from an image API using a parameter name filename. The full URL of the image API is like the following.

https://0a1400e80330a27ec02ddb9b00b10089.web-security-academy.net/image?filename=30.jpg

They add some extension validation in it. If the file doesn't have an extension .jpg it will not show any result and throw an error.

No such file

Any payload other payload didn't work but we can bypass this validation using a Null byte in our payload like the following.

../../../../../etc/passwd%00.jpg

Using this payload we can get the contents of the /etc/passwd file using the following command.

curl https://0a1400e80330a27ec02ddb9b00b10089.web-security-academy.net/image?filename=../../../../etc/passwd%00.jpg

PreviousDirectory TravarsalNextCommand Injection

Last updated 2 years ago

Was this helpful?

🕸️