文件上传-apache解析漏洞
原理
-
Apache 是从右到左开始判断解析,如果为不可识别解析,就再往左判断。 -
比如xxx.php.rar对apache来说 -
- rar是不可解析的,所以就会解析成xxx.php。
-
Apache并不认识rar后缀名,对它来说会看成test.php。解析成功。 -
其实漏洞的关键就是apache的"合法后缀",不是"合法后缀"的都可以被非法利用
实验内容
1、访问靶场出现如下界面。进入长传作业界面。

2、该页面发现存在上传点,但是好像是只能传docx。 
3、先尝试长传一个木马。

4、发现服务器禁止上传一句话木马。 
5、通过页面探测可以发现中间件是apache。那么我们尝试通过apache的解析漏洞来绕过。
-
直接在后面加上.docx。 -
因为apache是从后往前解析后缀名的, -
当docx无法解析是自然会解析php。

6、直接上传可以上传成功。

7、回到首页,直接点击上传的webshell,复制链接到蚁剑。
   
漏洞防御
解决方案一
在httpd.conf或httpd-vhosts.conf中加入以下语句,从而禁止文件名格式为*.php.*的访问权限:
<FilesMatch ".(php.|php3.|php4.|php5.)">
Order Deny,Allow
Deny from all
</FilesMatch>
解决方案二
如果需要保留文件名,可以修改程序源代码,替换上传文件名中的“.”为“_”:
$filename = str_replace('.', '_', $filename);
如果不需要保留文件名,可以修改程序源代码,将上传文件名重命名为时间戳+随机数的格式。
使用module模式与php结合的所有版本 apache存在未知扩展名解析漏洞,使用fastcig模式与php结合的所有版本apache不存在此漏洞。并且,想利用此漏洞必须保证文件扩展名中 至少带有一个“.php”,否则将默认被作为txt/html文档处理
解析漏洞,使用fastcig模式与php结合的所有版本apache不存在此漏洞。并且,想利用此漏洞必须保证文件扩展名中 至少带有一个“.php”,否则将默认被作为txt/html文档处理
免责声明
本文档供学习,请使用者注意使用环境并遵守国家相关法律法规! 由于使用不当造成的后果上传者概不负责!
|