Home Directory Traversal
Post
Cancel

Directory Traversal

Intro

This post/writeup is all about the Directory Traversal vulnerabilities.

I’ll be using primarily Portswigger Web Academy Labs, but i do intent do throw other labs and writeups here as well.

TOC

File path traversal, simple case

This lab contains a file path traversal vulnerability in the display of product images.

To solve the lab, retrieve the contents of the /etc/passwd file.

If we check the source, we see that images will be loaded through parameter.

picture 120

If not sanitized corectly, we’ll have a directory traversal so let’s have a try.

picture 121

Lab has been solved:

picture 122

File path traversal, traversal sequences blocked with absolute path bypass

This lab contains a file path traversal vulnerability in the display of product images.

The application blocks traversal sequences but treats the supplied filename as being relative to a default working directory.

To solve the lab, retrieve the contents of the /etc/passwd file.

Solution - Absolute Path: /image?filename=/etc/passwd

picture 123

File path traversal, traversal sequences stripped non-recursively

This lab contains a file path traversal vulnerability in the display of product images.

The application strips path traversal sequences from the user-supplied filename before using it.

To solve the lab, retrieve the contents of the /etc/passwd file.

Solution: /image?filename=....//....//...//....//etc/passwd

picture 124

File path traversal, traversal sequences stripped with superfluous URL-decode

This lab contains a file path traversal vulnerability in the display of product images.

The application blocks input containing path traversal sequences. It then performs a URL-decode of the input before using it.

To solve the lab, retrieve the contents of the /etc/passwd file.

Solution: /image?filename=%252e%252e%252f%252e%252e%252f%252e%252e%252fetc/passwd

picture 125

File path traversal, validation of start of path

This lab contains a file path traversal vulnerability in the display of product images.

The application transmits the full file path via a request parameter, and validates that the supplied path starts with the expected folder.

To solve the lab, retrieve the contents of the /etc/passwd file.

Solution: /image?filename=/var/www/images/../../../etc/passwd

picture 126

PS: I’m not sure how common this vulnerability is!

File path traversal, validation of file extension with null byte bypass

This lab contains a file path traversal vulnerability in the display of product images.

The application validates that the supplied filename ends with the expected file extension.

To solve the lab, retrieve the contents of the /etc/passwd file.

Solution: /image?filename=../../../etc/passwd%00.png

picture 127

This post is licensed under CC BY 4.0 by the author.