基于SpringBoot+SpringSecurity的RBAC管理系统
项目地址:
GitHub - witmy/my-springsecurity-plus: ☕基于SpringBoot+SpringSecurity的RBAC管理系统,易读易懂🔥
组件
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.codermy</groupId>
<artifactId>my-springsecurity-plus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>my-springsecurity-plus</name>
<description>my-springsecurity-plus-admin</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger ui-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.21</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- 验证码-->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
<!--jjwt-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<!--aop-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- UserAgentUtils -->
<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
<version>1.21</version>
</dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- 获取系统信息 -->
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>4.4.2</version>
</dependency>
<!--ip2region,这是根据ip查地址的工具,有兴趣自己可以了解-->
<!-- <dependency>-->
<!-- <groupId>org.lionsoul</groupId>-->
<!-- <artifactId>ip2region</artifactId>-->
<!-- <version>1.7.2</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
<!--hutool工具-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.7.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
常见的漏洞组件
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
fastjson 1.2.56 版本是存在漏洞版本的
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
mybatis 容易出现sql注入
fastjson
fastjson 主要搜索关键字:
JSON.toJSONString和JSON.parseObject/JSON.parse
都不存在,搜索了没啥可控的地方
项目实际并没有使用到parseObject
SQL注入
使用的mybatis
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
预编译了会使用#{
可以搜索关键字
${
order by
in
like
....
常用还是喜欢搜索${
直接搜索就能找到一个地方存在
参数是 dictName
跟踪一下
点击这个小箭头跳转或是搜索id都是可以的
点击箭头跳转会跳转到dao层
然后再点击getFuzzyDictByPage
跳转到service层
@Override
public Result<MyDict> getDictPage(Integer offectPosition, Integer limit, MyDict myDict) {
Page page = PageHelper.offsetPage(offectPosition,limit);
List<MyDict> fuzzyDictByPage = dictDao.getFuzzyDictByPage(myDict);
return Result.ok().count(page.getTotal()).data(fuzzyDictByPage).code(ResultCode.TABLE_SUCCESS);
}
@Override
public MyDict getDictByName(String dictName) {
return dictDao.getDictByName(dictName);
}
是一个分页查询数据的功能
点击getDictPage
跳转到Controller 层
@GetMapping
@ResponseBody
@ApiOperation(value = "字典列表")
@PreAuthorize("hasAnyAuthority('dict:list')")
@MyLog("查询字典列表")
public Result getDictAll(PageTableRequest pageTableRequest, MyDict myDict){
pageTableRequest.countOffset();
return dictService.getDictPage(pageTableRequest.getOffset(),pageTableRequest.getLimit(),myDict);
}
是一个查询字典列表 的功能去后台查看
点击查询字典抓包
找到SQL注入参数 :dictName
输入单引号会报错
闭合不了 ,直接拼接sql语句
使用延时注入测试
成功延迟3秒 ,存在注入 。
越权
越权的代码审计还不太会,先结合黑盒测试 ,然后再去看看代码
先添加一个低权限的用户
高权限用户查询人员
高权限的编辑接口
/api/user/edit/?userId=1
切换低用户
低权限用户啥都没有
使用接口看看
通过编辑的接口就可以查看所有人的信息
证明是存在垂直越权的
他这是存在一个是否为admin的判断的
但是这里还是有点逻辑没搞懂,可能因为sql哪里是没有做查询用户限制的 。
未授权
项目引入了SpringSecurity
SpringSecurity会配置一些放行的静态资源,有时错误的配置会将一些关键资源放行,造成未授权访问
搜索静态
有一个放行静态资源的接口
常见熟悉的就有
druid
actuator
swagger-ui.html
.....
配置里面也会写druid的账号密码