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
  • What is directory traversal?
  • Obstacles in exploitation
  • Common Payloads

Was this helpful?

  1. Web Application Security
  2. Web Application Security Notes

Directory Travarsal

What is directory traversal?

Directory traversal (also known as file path traversal or Local file Inclusion) is a web security vulnerability in which an attacker can read arbitrary files from the server that includes the source code file of the application. Sometimes attackers can write to some arbitrary files that could lead to full remote code execution on the server.

Scenario

Consider an application that shows the image file and the image is loaded via HTML like the following.

<img src="/loadImage?filename=218.png">

In the above code, they request the web API endpoint in which they load the file. They should look like the following in URL form.

http://example.com/loadImage?filename=218.png

The image is loaded from some hard-coded path in the web root and in that case they are following.

/var/www/html/images/218.png

If the application doesn't secure it properly it could lead to arbitrary file reading. instead of giving the image file name, we can give him ../../../etc/passwd , and if they give us the context /etc/passwd they are vulnerable to path traversal attack. The ../ sequence is used to go back to one directory so by going back multiple times we come to the file root and then specify the /etc/passwd file. we can also simply just add multiple ../ sequences because we cannot go further back after hitting the root file system.

One thing we should know is which OS application is running and we have to specify the files that are present there like on unix os /etc/passwd the file always exits that have all the user information in the system but for Windows, we have other files that are readable to everyone and that could be used to detect directory traversal.

Following are some common files that are readable and may be used to detect it.

Unix
Windows

/etc/passwd

/windows/boot.ini

/etc/group

/autoexec.bat

/etc/hosts

/windows/system.ini

/proc/self/environ

/windows/win.ini

Note: One windows both ..\ and ../ are valid directory traversal sequences.

Obstacles in exploitation

Some applications implement some hardening for path traversal attacks that includes striping or blocking the directory traversal sequences from user-supplied filenames. This kind of protection often bypasses by just using an absolute path i.e /etc/passwd. If that does not help then single or double URL encoding of the directory traversal sequences may bypass the protection for example the payload ../../etc/passwd after url encoded may look like this %2E%2E%2F%2E%2E%2Fetc%2Fpasswd. Sometimes non-standard encodings, such as ..%c0%af or ..%ef%bc%8f may also do the trick.

if the application tries to validate the user-supplied filename must start with some expected location i.e /var/www/images then we can add that and after then use directory traversal sequences to go back i.e filename=/var/www/images/../../../../etc/passwd.

If the application validates that the extension must be an image file .png then in some backend languages, it is possible to use a Null byte to terminate the extension checking requirement for example.

filename=../../../../../etc/passwd%00.png

Common Payloads

Unix
Windows

/etc/passwd

/Windows/win.ini

../../../../../../etc/passwd

../../../../../../Windows/win.ini

....//....//....//....//....//....//etc/passwd

....//....//....//....//....//....//Windows/win.ini

%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2Fetc%2Fpasswd

%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2F%2E%2E%2E%2E%2F%2FWindows%2Fwin%2Eini

%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2Fetc%2Fpasswd

%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2FWindows%2Fwin%2Eini

%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252Fetc%252Fpasswd

%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252FWindows%252Fwin%252Eini


PreviousAuthentication Vulnerability PracticalNextDirectory Traversal Lab

Last updated 2 years ago

Was this helpful?

🕸️