Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a8ebbf

Browse files
committed
Minor refactoring
1 parent fb7fe55 commit 1a8ebbf

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

lib/techniques/blind/inference.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
8181

8282
if partialValue:
8383
firstChar = len(partialValue)
84-
elif "LENGTH(" in expression or "LEN(" in expression:
84+
elif "LENGTH(" in expression.upper() or "LEN(" in expression.upper():
8585
firstChar = 0
8686
elif dump and conf.firstChar is not None and ( isinstance(conf.firstChar, int) or ( isinstance(conf.firstChar, basestring) and conf.firstChar.isdigit() ) ):
8787
firstChar = int(conf.firstChar) - 1
@@ -90,7 +90,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
9090
elif ( isinstance(firstChar, basestring) and firstChar.isdigit() ) or isinstance(firstChar, int):
9191
firstChar = int(firstChar) - 1
9292

93-
if "LENGTH(" in expression or "LEN(" in expression:
93+
if "LENGTH(" in expression.upper() or "LEN(" in expression.upper():
9494
lastChar = 0
9595
elif dump and conf.lastChar is not None and ( isinstance(conf.lastChar, int) or ( isinstance(conf.lastChar, basestring) and conf.lastChar.isdigit() ) ):
9696
lastChar = int(conf.lastChar)
@@ -342,7 +342,6 @@ def etaProgressUpdate(charTime, index):
342342

343343
# Go multi-threading (--threads > 1)
344344
if conf.threads > 1 and isinstance(length, int) and length > 1:
345-
value = []
346345
threadData = getCurrentThreadData()
347346

348347
threadData.shared.value = [ None ] * length
@@ -560,30 +559,29 @@ def queryOutputLength(expression, payload):
560559
selectDistinctExpr = re.search("\ASELECT\s+DISTINCT\((.+?)\)\s+FROM", expression, re.I)
561560
selectFromExpr = re.search("\ASELECT\s+(.+?)\s+FROM", expression, re.I)
562561
selectExpr = re.search("\ASELECT\s+(.+)$", expression, re.I)
563-
miscExpr = re.search("\A(.+)", expression, re.I)
564562

565-
if selectTopExpr or selectDistinctExpr or selectFromExpr or selectExpr:
563+
if any((selectTopExpr, selectDistinctExpr, selectFromExpr, selectExpr)):
566564
if selectTopExpr:
567-
regExpr = selectTopExpr.groups()[0]
565+
query = selectTopExpr.group(1)
568566
elif selectDistinctExpr:
569-
regExpr = selectDistinctExpr.groups()[0]
567+
query = selectDistinctExpr.group(1)
570568
elif selectFromExpr:
571-
regExpr = selectFromExpr.groups()[0]
569+
query = selectFromExpr.group(1)
572570
elif selectExpr:
573-
regExpr = selectExpr.groups()[0]
574-
elif miscExpr:
575-
regExpr = miscExpr.groups()[0]
571+
query = selectExpr.group(1)
572+
else:
573+
query = expression
576574

577-
if ( select and re.search("\A(COUNT|LTRIM)\(", regExpr, re.I) ) or len(regExpr) <= 1:
575+
if ( select and re.search("\A(COUNT|LTRIM)\(", query, re.I) ) or len(query) <= 1:
578576
return None, None, None
579577

580578
if selectDistinctExpr:
581-
lengthExpr = "SELECT %s FROM (%s)" % (lengthQuery % regExpr, expression)
579+
lengthExpr = "SELECT %s FROM (%s)" % (lengthQuery % query, expression)
582580

583581
if Backend.getIdentifiedDbms() in ( DBMS.MYSQL, DBMS.PGSQL ):
584582
lengthExpr += " AS %s" % randomStr(lowercase=True)
585583
elif select:
586-
lengthExpr = expression.replace(regExpr, lengthQuery % regExpr, 1)
584+
lengthExpr = expression.replace(query, lengthQuery % query, 1)
587585
else:
588586
lengthExpr = lengthQuery % expression
589587

@@ -600,4 +598,4 @@ def queryOutputLength(expression, payload):
600598
if length == " ":
601599
length = 0
602600

603-
return count, length, regExpr
601+
return count, length, query

0 commit comments

Comments
 (0)