4141from lib .core .settings import INFERENCE_EQUALS_CHAR
4242from lib .core .settings import INFERENCE_NOT_EQUALS_CHAR
4343from lib .core .settings import MAX_BISECTION_LENGTH
44- from lib .core .settings import MAX_TIME_REVALIDATION_STEPS
44+ from lib .core .settings import MAX_REVALIDATION_STEPS
4545from lib .core .settings import NULL
4646from lib .core .settings import PARTIAL_HEX_VALUE_MARKER
4747from lib .core .settings import PARTIAL_VALUE_MARKER
@@ -198,8 +198,7 @@ def tryHint(idx):
198198
199199 def validateChar (idx , value ):
200200 """
201- Used in time-based inference (in case that original and retrieved
202- value are not equal there will be a deliberate delay).
201+ Used in inference - in time-based SQLi if original and retrieved value are not equal there will be a deliberate delay
203202 """
204203
205204 if "'%s'" % CHAR_INFERENCE_MARK not in payload :
@@ -264,6 +263,7 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
264263 minChar = minValue = charTbl [0 ]
265264 firstCheck = False
266265 lastCheck = False
266+ unexpectedCode = False
267267
268268 while len (charTbl ) != 1 :
269269 position = None
@@ -321,6 +321,12 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
321321 result = Request .queryPage (forgedPayload , timeBasedCompare = timeBasedCompare , raise404 = False )
322322 incrementCounter (kb .technique )
323323
324+ if not timeBasedCompare :
325+ unexpectedCode |= threadData .lastCode not in (kb .injection .data [kb .technique ].falseCode , kb .injection .data [kb .technique ].trueCode )
326+ if unexpectedCode :
327+ warnMsg = "unexpected HTTP code '%d' detected. Will use (extra) validation step in similar cases" % threadData .lastCode
328+ singleTimeWarnMessage (warnMsg )
329+
324330 if result :
325331 minValue = posValue
326332
@@ -360,24 +366,25 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
360366 retVal = minValue + 1
361367
362368 if retVal in originalTbl or (retVal == ord ('\n ' ) and CHAR_INFERENCE_MARK in payload ):
363- if timeBasedCompare and not validateChar (idx , retVal ):
369+ if ( timeBasedCompare or unexpectedCode ) and not validateChar (idx , retVal ):
364370 if not kb .originalTimeDelay :
365371 kb .originalTimeDelay = conf .timeSec
366372
367- kb . timeValidCharsRun = 0
368- if retried < MAX_TIME_REVALIDATION_STEPS :
373+ threadData . validationRun = 0
374+ if retried < MAX_REVALIDATION_STEPS :
369375 errMsg = "invalid character detected. retrying.."
370376 logger .error (errMsg )
371377
372- if kb .adjustTimeDelay is not ADJUST_TIME_DELAY .DISABLE :
373- conf .timeSec += 1
374- warnMsg = "increasing time delay to %d second%s " % (conf .timeSec , 's' if conf .timeSec > 1 else '' )
375- logger .warn (warnMsg )
378+ if timeBasedCompare :
379+ if kb .adjustTimeDelay is not ADJUST_TIME_DELAY .DISABLE :
380+ conf .timeSec += 1
381+ warnMsg = "increasing time delay to %d second%s " % (conf .timeSec , 's' if conf .timeSec > 1 else '' )
382+ logger .warn (warnMsg )
376383
377- if kb .adjustTimeDelay is ADJUST_TIME_DELAY .YES :
378- dbgMsg = "turning off time auto-adjustment mechanism"
379- logger .debug (dbgMsg )
380- kb .adjustTimeDelay = ADJUST_TIME_DELAY .NO
384+ if kb .adjustTimeDelay is ADJUST_TIME_DELAY .YES :
385+ dbgMsg = "turning off time auto-adjustment mechanism"
386+ logger .debug (dbgMsg )
387+ kb .adjustTimeDelay = ADJUST_TIME_DELAY .NO
381388
382389 return getChar (idx , originalTbl , continuousOrder , expand , shiftTable , (retried or 0 ) + 1 )
383390 else :
@@ -387,8 +394,8 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
387394 return decodeIntToUnicode (retVal )
388395 else :
389396 if timeBasedCompare :
390- kb . timeValidCharsRun += 1
391- if kb .adjustTimeDelay is ADJUST_TIME_DELAY .NO and kb . timeValidCharsRun > VALID_TIME_CHARS_RUN_THRESHOLD :
397+ threadData . validationRun += 1
398+ if kb .adjustTimeDelay is ADJUST_TIME_DELAY .NO and threadData . validationRun > VALID_TIME_CHARS_RUN_THRESHOLD :
392399 dbgMsg = "turning back on time auto-adjustment mechanism"
393400 logger .debug (dbgMsg )
394401 kb .adjustTimeDelay = ADJUST_TIME_DELAY .YES
0 commit comments