3939from lib .core .settings import INFERENCE_BLANK_BREAK
4040from lib .core .settings import INFERENCE_UNKNOWN_CHAR
4141from lib .core .settings import INFERENCE_GREATER_CHAR
42+ from lib .core .settings import INFERENCE_GREATER_EQUALS_CHAR
4243from lib .core .settings import INFERENCE_EQUALS_CHAR
44+ from lib .core .settings import INFERENCE_MARKER
4345from lib .core .settings import INFERENCE_NOT_EQUALS_CHAR
4446from lib .core .settings import MAX_BISECTION_LENGTH
4547from lib .core .settings import MAX_REVALIDATION_STEPS
@@ -67,7 +69,12 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
6769 partialValue = u""
6870 finalValue = None
6971 retrievedLength = 0
70- asciiTbl = getCharset (charsetType )
72+
73+ if charsetType is None and conf .charset :
74+ asciiTbl = sorted (set (ord (_ ) for _ in conf .charset ))
75+ else :
76+ asciiTbl = getCharset (charsetType )
77+
7178 threadData = getCurrentThreadData ()
7279 timeBasedCompare = (kb .technique in (PAYLOAD .TECHNIQUE .TIME , PAYLOAD .TECHNIQUE .STACKED ))
7380 retVal = hashDBRetrieve (expression , checkConf = True )
@@ -109,7 +116,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
109116 elif (kb .fileReadMode or dump ) and conf .firstChar is not None and (isinstance (conf .firstChar , int ) or (isinstance (conf .firstChar , basestring ) and conf .firstChar .isdigit ())):
110117 firstChar = int (conf .firstChar ) - 1
111118 if kb .fileReadMode :
112- firstChar *= 2
119+ firstChar <<= 1
113120 elif isinstance (firstChar , basestring ) and firstChar .isdigit () or isinstance (firstChar , int ):
114121 firstChar = int (firstChar ) - 1
115122 else :
@@ -271,7 +278,7 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
271278 lastCheck = False
272279 unexpectedCode = False
273280
274- while len (charTbl ) != 1 :
281+ while len (charTbl ) > 1 :
275282 position = None
276283
277284 if charsetType is None :
@@ -444,23 +451,22 @@ def blindThread():
444451
445452 if threadData .shared .index [0 ] - firstChar >= length :
446453 kb .locks .index .release ()
447-
448454 return
449455
450456 threadData .shared .index [0 ] += 1
451- curidx = threadData .shared .index [0 ]
457+ currentCharIndex = threadData .shared .index [0 ]
452458 kb .locks .index .release ()
453459
454460 if kb .threadContinue :
455461 charStart = time .time ()
456- val = getChar (curidx )
462+ val = getChar (currentCharIndex , asciiTbl , not ( charsetType is None and conf . charset ) )
457463 if val is None :
458464 val = INFERENCE_UNKNOWN_CHAR
459465 else :
460466 break
461467
462468 with kb .locks .value :
463- threadData .shared .value [curidx - 1 - firstChar ] = val
469+ threadData .shared .value [currentCharIndex - 1 - firstChar ] = val
464470 currentValue = list (threadData .shared .value )
465471
466472 if kb .threadContinue :
@@ -488,10 +494,10 @@ def blindThread():
488494 count += 1 if currentValue [i ] is not None else 0
489495
490496 if startCharIndex > 0 :
491- output = '..' + output [2 :]
497+ output = ".." + output [2 :]
492498
493499 if (endCharIndex - startCharIndex == conf .progressWidth ) and (endCharIndex < length - 1 ):
494- output = output [:- 2 ] + '..'
500+ output = output [:- 2 ] + ".."
495501
496502 if conf .verbose in (1 , 2 ) and not showEta and not conf .api :
497503 _ = count - firstChar
@@ -549,7 +555,7 @@ def blindThread():
549555 testValue = unescaper .escape ("'%s'" % commonValue ) if "'" not in commonValue else unescaper .escape ("%s" % commonValue , quote = False )
550556
551557 query = kb .injection .data [kb .technique ].vector
552- query = agent .prefixQuery (query .replace ("[INFERENCE]" , "(%s)=%s " % (expressionUnescaped , testValue )))
558+ query = agent .prefixQuery (query .replace (INFERENCE_MARKER , "(%s)%s%s " % (expressionUnescaped , INFERENCE_EQUALS_CHAR , testValue )))
553559 query = agent .suffixQuery (query )
554560
555561 result = Request .queryPage (agent .payload (newValue = query ), timeBasedCompare = timeBasedCompare , raise404 = False )
@@ -573,7 +579,7 @@ def blindThread():
573579 testValue = unescaper .escape ("'%s'" % commonPattern ) if "'" not in commonPattern else unescaper .escape ("%s" % commonPattern , quote = False )
574580
575581 query = kb .injection .data [kb .technique ].vector
576- query = agent .prefixQuery (query .replace ("[INFERENCE]" , "(%s)=%s" % (subquery , testValue )))
582+ query = agent .prefixQuery (query .replace (INFERENCE_MARKER , "(%s)=%s" % (subquery , testValue )))
577583 query = agent .suffixQuery (query )
578584
579585 result = Request .queryPage (agent .payload (newValue = query ), timeBasedCompare = timeBasedCompare , raise404 = False )
@@ -594,9 +600,9 @@ def blindThread():
594600 # If we had no luck with commonValue and common charset,
595601 # use the returned other charset
596602 if not val :
597- val = getChar (index , otherCharset , otherCharset == asciiTbl )
603+ val = getChar (index , otherCharset , otherCharset == asciiTbl )
598604 else :
599- val = getChar (index , asciiTbl )
605+ val = getChar (index , asciiTbl , not ( charsetType is None and conf . charset ) )
600606
601607 if val is None :
602608 finalValue = partialValue
0 commit comments