Path Traversal Writeup
PortSwigger
Author:
Pham Quoc Trung
Used Tools:
BurpSuite
Problem Solving:
Lab: File path traversal, simple case
Description:
This lab contains a path traversal vulnerability in the display of product images.
To solve the lab, retrieve the contents of the /etc/passwd
file.

Solution:
Mục tiêu của bài này là phải đọc được nội dung file /etc/passwd
. Trước tiên mình sẽ nhìn trong BurpSuite để xem có request nào liên quan tới việc đọc file hay không. Sau khi ấn vào một sản phẩm mình thấy có request để đọc file ảnh của sản phẩm đó

Thử sửa tên file ảnh thành /etc/passwd
, mình thấy có lỗi trả về, có vẻ chức năng này có bị lỗi path traversal. Thử dò vị trí dần bằng cách thêm ../
, mình đã đọc được nội dung file tại ../../../etc/passwd

Và mình đã hoàn thành bài lab

Lab: File path traversal, traversal sequences blocked with absolute path bypass
Description:
This lab contains a 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:
Vẫn như bài trước, mình bắt được request để lấy file ảnh của sản phẩm

Thử thay tên file ảnh bằng /etc/passwd
, mình đọc được file này luôn. Có vẻ ứng dụng này cho phép sử dụng absolute path

Bài lab đã được hoàn thành

Lab: File path traversal, traversal sequences stripped non-recursively
Description:
This lab contains a 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:
Vẫn như các lab trên, mình có request lấy ảnh

Khi thử với cả 2 cách từ 2 lab trên, mình đều không ra được kết quả


Dựa trên đề bài, có vẻ ứng dụng đã filter để xóa đi chuỗi ../
được truyền vào. Vậy mình sẽ thử thay bằng ....//
. Khi đó, nếu ứng dụng xóa đi ../
thì chuỗi còn lại ghép vào sẽ trở thành ../
.

Vậy là mình đã hoàn thành bài lab này

Lab: File path traversal, traversal sequences stripped with superfluous URL-decode
Description:
This lab contains a 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:
Tương tự bài trên, tuy nhiên giờ các cách cũ đều không hoạt động nữa

Ngoài ra đề bài còn nói rằng ứng dụng sẽ tiến hành URL-decode input của mình trước khi thực thi. Mình sẽ thử URL-encode payload của mình 2 lần, để sau khi decode nó vẫn sẽ ở dạng URL-encode, có thể bypass được việc strip

Và bài lab đã được hoàn thành

Lab: File path traversal, validation of start of path
Description:
This lab contains a 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:
Với bài này, request có dạng như sau

Khi mình thử với các cách trước thì chương trình trả về lỗi như này

Có vẻ là mọi file đưa vào đều phải bắt nguồn từ /var/www/images/
. Vậy thì đơn giản, mình cứ cho đường dẫn đó vào rồi thoát ra khỏi nó bằng ../
thôi.

Hoàn thành bài lab

Lab: File path traversal, validation of file extension with null byte bypass
Description:
This lab contains a 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:
Tương tự thì mấy cách trước cũng đã không hoạt động

Theo như đề bài thì file truyền vào file có extension nhất định. Dựa trên cách chương trình lấy file thì có vẻ nó cần phải là .jpg
. Vậy làm sao để đọc được file /etc/passwd
nhỉ? Mình sẽ thử sử dụng kí tự null hay %00
. Lí giải cho điều này vì đây là kí tự kết thúc một chuỗi, khi đọc file /etc/passwd%00.jpg
thì phần extension sẽ bị bỏ qua

Vậy là mình đã hoàn thành bài lab cuối cùng

Bonus:
Có thể sử dụng Intruder để fuzzing path traversal



Cơ mà có vẻ sẽ chỉ giải được các trường hợp dễ

© 2024,Pham Quoc Trung. All rights reserved.
Last updated