前言
参考 @s31k3 师傅的 java SpringBoot框架代码审计 ,本文仅复现这位师傅的教程,用于学习springboot代码审计,特此笔记,原文请关注 @s31k3
环境搭建
审计的项目是github上 9.5k start的开源项目 newbee-mall。由于最新版的项目已修复多个漏洞,本文使用的是 Oct 17, 2019 的版本,项目地址 https://github.com/newbee-ltd/newbee-mall/tree/36807c87d13ee9ca08aff75197063b8836d8711d
基础配置
使用IntelliJ IDEA打开项目文件夹,配置好SDK后IDEA会以maven项目打开并自动下载依赖包。
Spring属性文件路径:
/src/main/resources/application.properties
,其中可修改端口和mysql数据库地址
server.port=8089
spring.datasource.url=jdbc:mysql://localhost:3306/newbee_mall_db?...
配置文件路径:
/src/main/java/ltd/newbee/mall/config/NeeBeeMallWebMvcConfigurer.java
,其中配置了图片路径
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/upload/**").addResourceLocations("file:" + Constants.FILE_UPLOAD_DIC);
registry.addResourceHandler("/goods-img/**").addResourceLocations("file:" + Constants.FILE_UPLOAD_DIC);
}
public class Constants {
//上传文件的默认url前缀,根据部署设置自行修改
public final static String FILE_UPLOAD_DIC = "/some_path/src/main/resources/upload/";
//public final static String FILE_UPLOAD_DIC = "D:\\upload\\";//上传文件的默认url前缀,根据部署设置自行修改
}
数据库配置
/src/main/resources
目录下有数据库文件
newbee_mall_schema.sql
。利用该文件创建数据库。
docker cp ./newbee_mall_schema.sql container_id:/root
root:/# mysql -u root -p
mysql> create database newbee_mall_db;
mysql> exit
root:/# mysql -u root -p newbee_mall_db</root/newbee_mall_schema.sql
启动项目
springboot项目结构
参考 https://s31k31.github.io/2020/04/26/JavaSpringBootCodeAudit-2-SpringBoot/
SQL注入
该项目GitHub中的第一个issue就是有关 SQL 注入的漏洞的 https://github.com/newbee-ltd/newbee-mall/issues/1
项目的搜索框中输入
1'
发现报错
回到IDEA中查看报错信息
### The error may involve ltd.newbee.mall.dao.NewBeeMallGoodsMapper.findNewBeeMallGoodsListBySearch-Inline
### The error occurred while setting parameters
### SQL: select goods_id, goods_name, goods_intro,goods_category_id, goods_cover_img, goods_carousel, original_price, selling_price, stock_num, tag, goods_sell_status, create_user, create_time, update_user, update_time from tb_newbee_mall_goods_info WHERE (goods_name like CONCAT('%','1'','%') or goods_intro like CONCAT('%','1'','%')) limit ?,?
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1'','%'))
limit 0,10' at line 8
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1'','%'))
limit 0,10' at line 8] with root cause
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1'','%'))