welcome to the bugkuctf(php://input和php://filter伪协议)

题目

http://123.206.87.240:8006/test1/

解题思路

welcome to the bugkuctf(php://input和php://filter伪协议)_第1张图片
查看源代码
welcome to the bugkuctf(php://input和php://filter伪协议)_第2张图片
源码审计:
user存在,且是一个文件,通过file_get_contents()将文件读入字符串r==“welcome to the bugkuctf”
之后会打印输出“hello admin”,并且包含file文件。此处根据提示,file应该是hint.php
要想传入一个文件,可以利用php://input伪协议
构造payload:txt=php://input&file=hint.php
同时post参数:welcome to the bugkuctf
welcome to the bugkuctf(php://input和php://filter伪协议)_第3张图片
之后利用php://filter伪协议读出hint.php的内容
payload:txt=php://input&file=php://filter/read=convert.base64-encode/resource=hint.php
得到base64加密后的源代码
welcome to the bugkuctf(php://input和php://filter伪协议)_第4张图片
解密后hint.php:
welcome to the bugkuctf(php://input和php://filter伪协议)_第5张图片
代码审计:hint.php是定义了一个Flag类,其中有一个file变量和tostring()函数,会将file中的文件以字符形式读出

同理利用php://filter伪协议读出index.php源码,base64解密

welcome to the bugkuctf(php://input和php://filter伪协议)_第6张图片
welcome to the bugkuctf(php://input和php://filter伪协议)_第7张图片
preg_match()
返回 pattern 的匹配次数。 它的值将是0次(不匹配)或1次,因为preg_match()在第一次匹配后 将会停止搜索

可以发现$file会过滤flag,受于php://filter伪协议的限制,flag无法绕过,所以采用另外一种思路,通过$password得到flag.php
创建一个Flag对象,将file赋值为flag.php,当Flag对象当作字符串被执行时会自动执行toString方法,输出file中的字符串。我们将此对象以字符串形式传入$password(序列化后传入)
welcome to the bugkuctf(php://input和php://filter伪协议)_第8张图片
得到字符串:O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}

于是可以构造payload:

txt=php://input&file=hint.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} 

要明确Flag类是在hint.php中定义的,所以此处的file一定要是hint.php, 在index.php源码中,若file=hint.php 不含flag,则会echo $password 。我们是利用了Flag类中的特性传入了$password 使其打印出flag.php中的内容。
welcome to the bugkuctf(php://input和php://filter伪协议)_第9张图片
得到flag!

你可能感兴趣的:(ctf)