## 問題描述:
為了方便的獲得網站域名,開發人員一般依賴于HTTP Host header。例如,在php里用\_SERVER\["HTTP\_HOST"\]。但是這個header是不可信賴的,如果應用程序沒有對host header值進行處理,就有可能造成惡意代碼的傳入。

## 修復方案(nginx):
**1.** **方法一:修改nginx.conf**
添加一個默認server,nginx 會根據訪問頭(request head)中Host 的數據來確定使用哪個server來處理當前請求。如果請求沒有匹配任何 server,或者訪問頭(request head)中沒有包含Host的數據,那么nginx會將該請求路由給默認的 server,當host頭被修改匹配不到server時會跳到該默認server,該默認server直接返回403錯誤。
```
server {
listen 80 default_server;
server_name _;
access_log off;
return 403;
}
```
**2.** **方法二:修改nginx.conf**
在目標server添加檢測規則,參考以下配置:(if部分)
```
server {
server_name 192.168.0.171;
listen 80;
if ($http\_Host !~\*^192.168.0.171:80$)
{
return 403;
}
include /etc/nginx/default.d/\*.conf;
location / {
root /www/dvwa;
index index.php index.html index.htm;
}
}
```
**驗證方式:**
驗證使用BurpSuite工具的Repeater模塊。
修復前:修改host還是可以正常訪問

修復后:修改host無法訪問了
