# Portswigger Information Disclosure 🤪
<style>body {text-align: justify}</style>
Hi, dưới đây là writeup của 5/5 bài lab về lỗ hổng [Information Disclosure](https://portswigger.net/web-security/information-disclosure) mình đã solve trong quá trình ôn tập thi chứng chỉ của Portswigger.
### 1. Information disclosure in error messages
##### Description
> This lab's verbose error messages reveal that it is using a vulnerable version of a third-party framework. To solve the lab, obtain and submit the version number of this framework.
##### Writeup
Mục tiêu của bài lab này là trigger được lỗi của ứng dụng và trích xuất thông tin version của framework được sử dụng.

Khi truy cập sản phẩm theo `productId`, giá trị `productId` phải là một số nguyên int.

Khi truy xuất sản phẩm với `productId` không phải dạng int thì nó sẽ báo lỗi debug. Đọc lỗi cho biết ứng dụng được dev bằng Java và framework được sử dụng là `Apache Struts 2 2.3.31`.

Lấy version trên và submit, ta solve được challenge.

### 2. Information disclosure on debug page
##### Description
> This lab contains a debug page that discloses sensitive information about the application. To solve the lab, obtain and submit the `SECRET_KEY` environment variable.
##### Writeup
Khi xem source trang chủ, ta thấy xuất hiện 1 comment chứa đường link dẫn tới trang `Debug` tại `/cgi-bin/phpinfo.php`.

Truy cập `/cgi-bin/phpinfo.php`, ta thấy đây là trang phpinfo mặc định chứa các thông tin của server. Trong đó có trường `SECRET_KEY` cần tìm.

Lấy giá trị `SECRET_KEY` tìm được và submit, ta sẽ solve được challenge.

### 3. Source code disclosure via backup files
##### Description
> This lab leaks its source code via backup files in a hidden directory. To solve the lab, identify and submit the database password, which is hard-coded in the leaked source code.
##### Writeup
Truy cập trang `robots.txt`, ta thấy ứng dụng có để lộ ra một thư mục `/backup`.

Tại thư mục `/backup`, xuất hiện một file backup mã nguồn java.

Truy cập file backup trên theo đường dẫn `/backup/ProductTemplate.java.bak`, ta đọc được mã nguồn. Cụ thể, file này có chứa một hàm kết nối database và có để lộ config về database. Trong đó, `password` chính là thứ ta cần tìm (được gạch đỏ).

Submit password trên và ta solve được challenge.

### 4. Authentication bypass via information disclosure
##### Description
> This lab's administration interface has an authentication bypass vulnerability, but it is impractical to exploit without knowledge of a custom HTTP header used by the front-end.
>
> To solve the lab, obtain the header name then use it to bypass the lab's authentication. Access the admin interface and delete Carlos's account.
>
> You can log in to your own account using the following credentials: `wiener:peter`
##### Writeup
Ứng dụng web của lab này cho phép user thực hiện được `TRACE` method ở tất cả các request. Khi đó, user có thể đọc được request thực sự mà server nhận được → Điều này dẫn đến có thể để lộ một số trường header nhạy cảm. Cụ thể ở đây là `X-Custom-IP-Authorization`. Đây là header có chức năng xác định IP nguồn của request để từ đó authorize theo. Như vậy, nếu `X-Custom-IP-Authorization: 127.0.0.1` thì chứng tỏ request được gửi từ localhost và có thể được authorize làm admin.

Với user thường, truy cập `/admin` sẽ bị cấm.

Tuy nhiên, khi thêm `X-Custom-IP-Authorization: 127.0.0.1`, ta đã vào được và có đủ chức năng của admin.

Thực hiện xóa user carlos.

Sau đó, ta đã solve được challenge.

### 5. Information disclosure in version control history
##### Description
> This lab discloses sensitive information via its version control history. To solve the lab, obtain the `password` for the `administrator` user then log in and delete Carlos's account.
##### Writeup
Đối với bài lab này, thư mục `/.git` bị public → các thông tin log về các commit sẽ bị lộ.

Sử dụng câu lệnh sau để download thư mục `.git` về để phân tích.
```bash
wget -r https://0a8c00ff04fcc303c15b210300c600c1.web-security-academy.net/.git/ --no-check-certificate
```
Sử dụng câu lệnh `git log` ta xem được các commit mà các developers đã thực hiện. Có xuất hiện commit `ef5...` chứa thông tin về admin password.

Dùng `git show <commit id>`, ta sẽ xem được chi tiết thay đổi của commit đó. Cụ thể, nó xóa admin password đi tại file admin.conf và thành bằng `env('ADMIN_PASSWORD')`. Tuy nhiên, ta đã leak được password của admin là `2237xgsyi4lba8qqcrwt`.

Lúc này ta đăng nhập bằng tài khoản `administrator:2237xgsyi4lba8qqcrwt` và xóa user `carlos` đi. Như vậy, ta đã solve challenge thành công.

###### tags: `portswigger`, `information-disclosure`