题目
http://123.206.87.240:8006/test1/
查看源码
代码大概讲的是
需要get传递三个值:
txt,file,password
并且
$user的文件内容为
welcome to the bugkuctf
$file为hint.php
password暂时还没用到
file_get_contents(
u
s
e
r
,
′
r
′
)
函
数
作
用
是
将
user,'r')函数作用是将
user,′r′)函数作用是将user的文件内容写到字符串里
这里涉及到php伪协议(php://input)
这个是有关于php伪协议的解释https://blog.csdn.net/qq_27682041/article/details/73326435
接下来使用我们的bp工具进行抓包
构造txt=php://input,并且post传值welcome to the bugkuctf
我们可以看到页面变化
接下来
include($file)还涉及到php://filter协议
这是关于php://filter协议的解释
https://blog.csdn.net/wy_97/article/details/77432002
构造一个
file=php://filter/read=convert.base64-encode/resource=hint.php
得到hint.php网页的base64编码后的源代码
解密后得到
继续同样的方法
file=php://filter/read=convert.base64-encode/resource=index.php
获取index.php网页base64编码后的源代码
解密后得到
hint.php中提示flag.php,且index.php有对关键词flag进行了preg_match
hint.php中定义了一个类Flag,中间有个 __tostring 方法,将这个类作为字符串执行时会自动执行的一个函数
__tostring 方法执行时,将变量$file作为文件名输出文件内容,结合提示flag.php,猜测flag.php文件在此打开
在index.php源码中看到了$password的作用
将hint.php中的Flag当做字符串执行时,会自动执行 __tostring方法,只有echo,只能输出一个或多个字符串,所以构造password为Flag类型,其中的string变量flie=flag.php
由于存在password=unserialize(password);
执行该脚本得到
<?php
class Flag{//flag.php
public $file;
}
$a = new Flag();
$a->file = "flag.php";
$a = serialize($a);
print_r($a);
?>
需要构造序列化对象payload为
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}