Apache httpd 换行解析漏洞(CVE-2017-15715)
影响版本: 2.4.0~2.4.29
漏洞复现
进入docker容器/vulhub-master/httpd/CVE-2017-15715的目录下
cd进入漏洞目录,自动化编译环境 docker-compose build 启动整个环境 sudo docker-compose up -d
 查看docker的ip  在浏览器中输入docker的ip:8080  这是个简单的上传文件的表单 在桌面创建1.php文件,将1.php上传,设置好代理用burpsuit进行抓包(我设置的代理ip是127.0.0.1,端口号为8088,端口不要设置为被占用的端口号,要不然无法连接)  直接放包的话,会被后端设置的黑名单拦截 黑名单代码: 
返回响应:  这回我们在1.php后插入一个\x0A,绕过黑名单过滤。  在浏览器访问1.php%0A,即可看到文件被当做php解析。  如果我们在上传的1.php中写入一句话木马
<?php phpinfo();?>
 phpinfo执行成功,利用该漏洞即可get shell。
漏洞原理
此漏洞的出现是由于apache在修复第一个后缀名解析漏洞时,用正则来匹配后缀。在解析php时xxx.php\x0A将被按照php后缀进行解析,导致绕过一些服务器的安全策略。
漏洞分析
漏洞的成因就是apache中的配置文件中,如图
查看容器列表 sudo docker ps -a 在容器中执行命令 sudo docker exec -it <容器> 命令

\ .php$ 中的$ 表示配置匹配后缀名文件的防盗链,而这个解析漏洞根本原因就是$ 这个符号,这个符号在正则表达式中是匹配字符串中结尾的位置,也就是说可以利用换行符使$ 与其匹配从而绕过黑名单机制实现文件上传,验证逻辑又是先会对上传的文件正则匹配验证后缀名是否包含了php,因为解析漏洞的存在,这里不会过滤php%0a,后续的黑名单机制也就如同摆设了
Apache配置FilesMatch访问控制
<FilesMatch "\.(txt|doc|php)"> //凡是匹配到以txt/php/doc结尾的进行下面的策略匹配
SetHandler application/x-httpd-php
</FilesMatch>
参考文章: https://blog.csdn.net/m0_37711941/article/details/88684515 https://blog.csdn.net/qq_43571759/article/details/105617122 https://blog.csdn.net/sj349781478/article/details/84718409 https://github.com/vulhub/vulhub
|