思维导图
知识点:
1、JavaEE-SpringBoot-WebAPP&路由
2、JavaEE-SpringBoot-Mybatis&注入
3、JavaEE-SpringBoot-Thymeleaf&SSTI
章节点
3、Java:
功能:数据库操作,文件操作,序列化数据,身份验证,框架开发,第三方库使用等.
框架库:MyBatis,SpringMVC,SpringBoot,Shiro,Log4j,FastJson等
技术:Servlet,Listen,Filter,Interceptor,JWT,AOP,反射机制待补充
安全:SQL注入,RCE执行,反序列化,脆弱验证,未授权访问,待补充
安全:原生开发安全,第三方框架安全,第三方库安全等,待补充
演示案例: SpringBoot-Web应用-路由响应 SpringBoot-数据库应用-Mybatis SpringBoot-模版引擎-ThymeleafSpring Boot是由Pivotal团队提供的一套开源框架,可以简化spring应用的创建及部署。它提供了丰富的Spring模块化支持,可以帮助开发者更轻松快捷地构建出企业级应用。Spring Boot通过自动配置功能,降低了复杂性,同时支持基于JVM的多种开源框架,可以缩短开发时间,使开发更加简单和高效。
SpringBoot-Web应用-路由响应
参考:https://springdoc.cn/spring-boot/
1、路由映射@RequestMapping @GetMapping等
2、参数传递@RequestParam
3、数据响应@RestController @Controller@RestController注解相当于@ResponseBody+@Controller合在一起的作用。
@RestControllerpublicclassHelloController{//无参数访问响应@RequestMapping("/xiaodi")publicStringhello(){return"hello xiaodi";}//无参数指向GET方法访问响应@RequestMapping(value="/get",method=RequestMethod.GET)publicStringhelloGet(){return"hello get xiadi";}//有参数指向GET方法访问响应@RequestMapping(value="/getp",method=RequestMethod.GET)publicStringhellogetp(Stringname){return"hello get "+name;}//有参数指向POST方法访问响应@RequestMapping(value="/getpost",method=RequestMethod.POST)publicStringhelloGetParameters(Stringname){return"hello POST "+name;}}SpringBoot-数据库应用-Mybatis
操作步骤:
0、数据库先创建需操作的数据
1、项目添加Mybatis&数据库驱动
-pom.xml
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency>2、项目配置数据库连接信息
-application.yml
spring:datasource:url:jdbc:mysql://localhost:3306/demo01 username:root password:123456driver-class-name:com.mysql.cj.jdbc.Driver3、创建User类用来操作数据库数据
-com.example.demo.entity.User
set get toString方法4、创建Mapper动态接口代理类实现
-com.example.demo.mapper.UserMapper
@MapperpublicinterfaceUserMapper{@Select("select * from admin where id like '%${id}%'")//模糊查询,有安全危险publicList<User>findAll(Integerid);}5、创建Controller实现Web访问调用
-com.example.demo.controller.UserController
@RestControllerpublicclassUserController{@AutowiredprivateUserMapperuserMapper;@RequestMapping(value="/getdata",method=RequestMethod.GET)//@ResponseBodypublicList<User>getdata(Integerid){List<User>all=userMapper.findAll(id);System.out.println(all);returnall;}}可以在csdn搜索mybatis中SQL注入的文章,虽然有这种漏洞的可能性小,但是还是有可能
SpringBoot-模版引擎-Thymeleaf
- 不安全的模版版本
日常开发中:语言切换页面,主题更换等传参导致的SSTI注入安全问题(只有3.0.0到3.0.11版本有,后面就被修复了)
漏洞参考:https://mp.weixin.qq.com/s/NueP4ohS2vSeRCdx4A7yOg
配置application.properties指向模版页面
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
@RequestMapping(value="/")publicStringindex(Modelmodel){model.addAttribute("data","hello xiaodi");return"index";}@GetMapping("/path")publicStringthymeleaf(Stringlang){returnlang;}<?xml version="1.0"encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.springframework</groupId><artifactId>java-spring-thymeleaf</artifactId><version>1.0</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><!--latest--><version>2.2.0.RELEASE</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency></dependencies><properties><java.version>1.8</java.version></properties><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>