NiZhuanSiWei
看代码,有三个参数,即text,file,password。看满足条件:
-
text不为空,且 file_get_contents() 读取的返回值为 welcome to the zjctf,file_get_contents()函数的功能是读取文件内容到一个字符串,但这里没有一个文件,而是读取的text变量。直接给text赋值 text=welcome to the zjctf 的话,没有回显说明没成功。很明显,需要用伪协议绕过,可以用php://input和data://伪协议,这里使用data://,构造:
?text=data://text/plain,welcome to the zjctf
data://伪协议: 条件:allow_url_fopen:on allow_url_include :on 作用:自PHP>=5.2.0起,可以使用data://数据流封装器,以传递相应格式的数据。通常可以用来执行PHP代码。 用法:data://text/plain, data://text/plain;base64, 示例:http://127.0.0.1/include.php?file=data://text/plain,<?php%20phpinfo();?> http://127.0.0.1/include.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b
-
看第二个if:首先是file不能有flag字符。提示了有一个
useless.php
,用PHP伪协议中的php://filter读取文件,构造file=php://filter/read=convert.base64-encode/resource=useless.php
php://伪协议 条件:allow_url_fopen:off/on allow_url_include :仅php://input php://stdin php://memory php://temp 需要on 作用:php:// 访问各个输入/输出流(I/O streams),在CTF中经常使用的是php://filter和php://input,php://filter用于读取源码,php://input用于执行php代码。 用法:1.php://filter/read=convert.base64-encode/resource=[文件名]读取文件源码(针对php文件需要base64编码)。 2.php://input + [POST DATA]执行php代码(用bp或HackBar) 实例:http://127.0.0.1/include.php?file=php://input [POST DATA部分] <?php phpinfo(); ?>
回到题目,最后构造出:?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-P7qXt1yw-1631540338537)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20210911141700231.png)]
进行解码
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PBkbFcDs-1631540338538)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20210911141754269.png)]
看到有一个 flag.php ,并且file不为空,将读取flag.php并显示。所以。构造一个序列化字符串。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-p12yQ4Ro-1631540338539)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20210911141904515.png)]
最后payload为:?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
,这里要注意如果file继续用前面伪协议读取的话,后面的 password 会无回显无法得到flag 。需修改为 useless.php。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1RIBg8TJ-1631540338540)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20210911142026019.png)]
ess.php。
[外链图片转存中…(img-1RIBg8TJ-1631540338540)]