一个专业运
维技术分享!

配置Nginx以解决http host头攻击漏洞

大致意思就是你代码里如果用到host头这个字段,那么别人就能通过这个字段注入恶意代码。

修复方式:
在nginx配置文件中的Server中添加一下代码,大致意思是判断host头是否是指定的host,如果是则放行,不是就返回403(资源不可用)
#方法一
server{
listen 80;
server_name www.xlsys.cn;
#host头攻击漏洞-Jack.liu2020.09.16
set $flag = 0;
if($host == "www.xlsys.cn"){
set $flag = 1;
}
if($flag = 0){
return 403;
}
#....省略...........
 location / {
root /www/h5;
index index.php index.html index.htm;
}
}
==================================================
#多host头配置方法
server{ 
listen 80;
server_name www.xlsys.cn;
#host头攻击漏洞-Jack.liu2020.09.16
set $flag = 0; 
if($host == "www.xlsys.cn" || $host == "www.****.cn" || $host == "localhost")
{ set $flag = 1; 
} 
if($flag = 0){ 
return 403;
}
#....省略...........
 location / {
root /www/h5;
index index.php index.html index.htm;
}
}
==================================================
#方法二
server {
listen 80;
server_name www.xlsys.cn;
#host头攻击漏洞-Jack.liu2020.09.16
if ($http_Host !~* ^www.xlsys.cn|134.175.*.52|192.168.10.*|175.6.*.12|127.0.0.1$)
{
return 403;
}
#....省略...........
 location / {
root /www/h5;
index index.php index.html index.htm;
}
}


微信扫描下方的二维码阅读本文

赞(6) 打赏
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。小柳实验室 » 配置Nginx以解决http host头攻击漏洞

相关推荐

  • 暂无文章

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏