模板技术

形态引入

模板技术:格式形如:

<html>
<head>
<title>{Title}</title>
</head>
</html>
获取{Title}并且进行替换。

介绍

html专门做视图
php代码专门做模板替换 => 调用数据库数据,按模板填充数据并且替换到html当中

新闻列表

1、数据库创建新闻存储
2、代码连接数据库读取
3、页面进行自定义显示

自写模版引用

1、页面显示样式编排
2、显示数据插入页面
3、引用模版调用触发

Smarty模版引用

下载:https://github.com/smarty-php/smarty/releases
使用:
1、创建一个文件夹,命名为smarty-demo。
2、下载Smarty对应版本并解压缩到该文件夹中。
3、创建一个PHP文件,命名为index.php,并在文件中添加以下代码:

<?php
// 引入 Smarty 类文件
require('smarty-demo/libs/Smarty.class.php');
// 创建 Smarty 实例
$smarty = new Smarty;
// 设置 Smarty 相关属性
$smarty->template_dir = 'smarty-demo/templates/';
$smarty->compile_dir = 'smarty-demo/templates_c/';
$smarty->cache_dir = 'smarty-demo/cache/';
$smarty->config_dir = 'smarty-demo/configs/';
// 赋值变量到模板中
$smarty->assign('title', '欢迎使用 Smarty');
// 显示模板
$smarty->display('index.tpl');
?>

4、创建一个名为index.tpl的模板文件,并将以下代码复制到上述点定义文件夹中

<!DOCTYPE html>
<html>
<head>
<title>{$title}</title>
</head>
<body>
<h1>{$title}</h1>
<p>这是一个使用 Smarty 的例子。</p>
</body>
</html>

安全问题

1、自写模板 rce安全问题
2、第三方模板 没有直接rce安全问题,但也有漏洞

1,本身的代码逻辑漏洞
2,第三方插件(ueditor)
3,第三方模板(smarty)
4,第三方组件(java居多,shiro,fastjson等)

意味着代码审计什么都要审,审代码,审模板,审组件,审插件等。
重点:开发角度看待漏洞挖掘。

关键字

cnvd查漏洞,水平越权,垂直越权,逻辑越权

框架-组件-模板

框架 :核心开发,代码逻辑核心(核心功能的实现)
组件 :第三方功能开发 => 必须考虑的是:是不是涉及敏感函数,操作敏感不? => 敏感操作造成漏洞
模板 :负责页面美观(用于丰富功能)

框架是核心,组件和模板负责修饰。
黑盒:端口扫描 数据包特征 识别插件工具等。=> 识别出框架-组件-模板