-- 正常查询
select * from tablename
where id = '1'
and (status = '1' or status = '2' or status = '3')
-- 成功注入
and (1 = 2 or (status = '1' or status = '2' or status = 3 or 1=1))
-- 安全防注入
and (1 = 2 or (status = '1' or status = '2' or status = '3'))
and (status = '1' or status = '2' or status = '3 or 1=1')
如上当使用or语句,并且接收参数的话,就可能存在sql注入的风险。
原文
原因:
- or语句特性->1个条件为true,则整个为true,所以当通过参数传入一个为true的条件时,整个条件都为true。
- 转入的参数未转换成字符串
防止注入:
- 将参数转成字符串,如:status = ‘3 or 1=1’
- 将整个or语句作为另一个or语句的子句(再套一层),并且外层默认值为false(1=2)