The Complete Guide to PortSwigger Directory Traversal and How to Prevent It

Mukilan Baskaran
InfoSec Write-ups
Published in
4 min readNov 2, 2022

--

PortSwigger is a company that specializes in vulnerability research and development of security tools. It is a company which has been instrumental in the development of the Burp Suite, an integrated platform for web application security testing.

In this tutorial, we will be looking at PortSwigger Directory Traversal and how to prevent it.

PortSwigger Directory Traversal occurs when an attacker is able to access files or directories that they are not supposed to be able to access by sending requests with specially crafted URLs. This can happen because of a configuration problem with the web server or if there are vulnerabilities in the web application itself.

There are two ways you can prevent PortSwigger Directory Traversal: -Use Apache’s mod_rewrite module -Use .htaccess file The mod rewrite module is disabled by default in Apache 2.4, while the .htaccess file is only available in Apache 2.2 and older.On Linux servers, the following command can be used to enable mod rewrite:Ubuntu/Debian:apache2ctl -e apache2ctl -e enablerewrite or apache2ctl -S on

What is a Directory Traversal Attack

A directory traversal attack is an attack on a computer system that uses file and path names to access data on a system. This type of attack exploits the fact that many operating systems allow users to input arbitrary strings into the file name when referencing a file. A directory traversal attack involves using one of these strings to access files or directories that may not be intended to be accessible, such as web server root directories, configuration files, and application source code.

The directory traversal attack is also known as “directory climbing” or “directory hopping”.

Directory traversal is a type of computer security vulnerability that results from insufficient input sanitization and allows access to arbitrary files stored in the affected computer’s file system.

How to Prevent a Directory Traversal Attack

Directory traversal or path traversal is a type of computer security vulnerability typically found in web applications.

This attack is possible because some programming languages allow spaces in a file name, and the operating system does not always check for these spaces. This can be prevented by using a web application firewall (WAF) to filter out requests with double dots, or by preventing users from uploading files with spaces in the filename.

Website security is a major concern for companies in today’s digital world. Portswigger’s directory traversal prevention service will effectively protect your website from hackers and other cyber attacks.

Different Methods of Achieving a Directory Traversal Attack

Directory traversal is a type of attack that exploits the fact that many operating systems and programming languages use “/” to separate directories in a path. This allows an attacker to access arbitrary files and directories in the system by providing a specially crafted path.

There are various methods of achieving this directory traversal attack, but it does not matter which one is used as long as the end result is the same. The following are some of the most popular methods:

- Using directory names that contain “../”

- Using ../../

Portswigger is an open-source, free project that makes it easy to find and exploit security vulnerabilities in web applications.

Steps that I followed find this vulnerability:

step 1: I captured the requests using burp suite and analysed it.

step 2: Then I found “?filename=” parameter with image file(.jpg)

step 3: I sent this request to the repeater and change the filename parameter value to ../../../etc/passwd

Finally solution got it. If you like the video subscribe and make a like.

From Infosec Writeups: A lot is coming up in the Infosec every day that it’s hard to keep up with. Join our weekly newsletter to get all the latest Infosec trends in the form of 5 articles, 4 Threads, 3 videos, 2 GitHub Repos and tools, and 1 job alert for FREE!

--

--