当前位置:网站首页>Secure Code Warrlor学习记录(四)
Secure Code Warrlor学习记录(四)
2022-07-19 05:14:00 【Mauro_K】
文章目录
前言
Secure Code Warrlor是一个代码审计的练习平台,本次练习对象包含Spring框架和Spring Data Jpa框架。
一、SQL注入练习(6)
1.漏洞点为:
2.解决方案:
二、SQL注入练习(7)
1.漏洞点为:
2.解决方案:
三、SQL注入练习(8)
1.漏洞点为:
2.解决方案:
四、总结
1.Spring Data Jpa框架简介
Spring Data JPA 是spring在基于ORM框架、JPA规范的基础上封装的一套JPA框架,可以令开发者使用极简的代码实现对数据的访问和操作。其简化了对DAO层代码的编写,开发人员在DAO层中只需要写接口,就自动具有了增删改查、分页查询等方法。
存在下面代码就说明存在Spring Data Jpa框架:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
2.常见SQL注入场景
1)注意 Order By 因为采用预编译执行SQL语句传入的参数不能作为SQL语句的一部分,那么Order By后的字段名、或者是desc\asc也不能预编译处理,也就是说Order By场景的业务实现还是只能使用拼接。
2)注意 EntityManager,因为spring-data-jpa对复杂的动态的多表达语句支持不好需要引入EntityManager来完成,如果存在SQL语句拼接的话,就会存在注入的风险。
先引入EntityManager,然后使用entityManager.createNativeQuery()来执行原生的SQL语句:
Pageable pageable = PageUtils.getPageable(pageIndex,pageSize);
StringBuilder sql = new StringBuilder();
sql.append(" select ep.name,MAX(r.sign) from mnt_emp_rel_meeting as e ");
sql.append(" left join mnt_sign_record as r on(r.employee_id=e.employee_id) ");
sql.append(" left join mnt_employee as ep on(ep.id = e.employee_id) ");
sql.append(" where e.meeting_id ='"+meetingId"'");
sql.append(" order by r.sign desc,r.create_date asc ");
Query query = entityManager.createNativeQuery(sql.toString());
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
List<Object[]> list = query.getResultList();
可以看到这里meetingId是通过SQL拼接的方式进行查询,若meetingId用户可控的话,会存在SQL注入风险。
3.SQL注入防御
1)在执行数据库查询之前清除用户输入。此解决方案使用Spring数据存储库,提供数据访问。Spring数据存储库自动对传递给它们的任何参数执行清理,能防止SQL注入。
2)Spring Data JPA为创建安全的SQL查询提供了安全的参数清理,从而防止从用户控制的输入中包含恶意查询参数。
边栏推荐
- Ktor2.0很多新特性,我们一年前就想到了,并已落实在项目中
- FreeRTOS线程安全、中断安全的printf实现方式
- 全志T507去掉IO扩展芯片,保留扩展引脚功能
- Ktor 2.0? Half fragrant embarrassment
- Qingdao Weifang becomes a rich man
- Vivado2018.2 error reporting and solution records
- Ktor 2.0?半香不香的尴尬
- i.MX8MP开发板移植USBWIFI RTL8192EU驱动
- Interpretation of CO correcting: noise tolerant medical image classification via mutual label correction
- 电脑快捷方式变白原因及解决方法——血的教训呜呜呜
猜你喜欢
【HAL库】串口通信
用LS1028A开发板输出PWM方波
[mindspore] [Lite end-to-side training reasoning] mindspore lit runs the lenet training example code according to the instructions and reports an error
vivado2018.2版本带PS侧配置(bd)调用modelsim仿真时:(vlog-13006) Could not find the package (sc_util_v1_0_3_pkg)
【Markdown】关于Markdown我想说这些~
Interpretation of semi supervised semantic segmentation with error localization network
i.MX8MP开发板移植USBWIFI RTL8192EU驱动
RTOS——RT-Thread快速入门
瑞芯微RK3568开发板深度评测
Definition, calculation method and relationship among linear convolution, cyclic convolution and periodic convolution
随机推荐
iMX8M开发板UBOOT添加新的显示支持
UltraEdit自动换行/制表符设置
SSH协议中隧道与代理的用法详解
Differences between types any, void, unknown, and never in typescript
[BOM] first knowledge of BOM~
vivado2018.2报错及解决方法记录
Connaissance de la technologie des tunnels d'infiltration Intranet
皮尔逊相关系数及代码实现(C语言+MATLAB)
TypeScript 中类型 any,void,unknown,never之间的区别
First hand evaluation of Reza g2l core board and development board
xilinx中的复位
Generics of typescript
Let foreigners my brother him
vulnhub 靶机 GOLDENEYE: 1
Add directory navigation to personal blog website articles
Detailed explanation of the principle of triode series linear voltage stabilizing circuit and Multisim Simulation
Vivado2018.2 version with PS side configuration (BD) when calling Modelsim simulation: (vlog-13006) could not find the package (sc_util_v1_0_3_pkg)
Reset in Xilinx
Intelligent gateway based on Ruixin micro 3568 core board
Redux main knowledge learning summary