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

Skip to content

Commit b1dc928

Browse files
committed
implemented validation for time-based inference
1 parent 25463bc commit b1dc928

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
# character used for operation "equals" in inference
8787
INFERENCE_EQUALS_CHAR = "="
8888

89+
# character used for operation "not-equals" in inference
90+
INFERENCE_NOT_EQUALS_CHAR = "!="
91+
8992
# string used for representation of unknown dbms version
9093
UNKNOWN_DBMS_VERSION = "Unknown"
9194

lib/techniques/blind/inference.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from lib.core.settings import INFERENCE_UNKNOWN_CHAR
4141
from lib.core.settings import INFERENCE_GREATER_CHAR
4242
from lib.core.settings import INFERENCE_EQUALS_CHAR
43+
from lib.core.settings import INFERENCE_NOT_EQUALS_CHAR
4344
from lib.core.unescaper import unescaper
4445
from lib.request.connect import Connect as Request
4546

@@ -144,6 +145,16 @@ def tryHint(idx):
144145

145146
return None
146147

148+
def validateChar(idx, value):
149+
"""
150+
used in time based inferences (in case of delay compared values are not equal)
151+
"""
152+
forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_NOT_EQUALS_CHAR), (expressionUnescaped, idx, value))
153+
queriesCount[0] += 1
154+
result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False)
155+
156+
return not result
157+
147158
def getChar(idx, charTbl=asciiTbl, continuousOrder=True, expand=charsetType is None):
148159
"""
149160
continuousOrder means that distance between each two neighbour's
@@ -171,7 +182,7 @@ def getChar(idx, charTbl=asciiTbl, continuousOrder=True, expand=charsetType is N
171182

172183
if result:
173184
return chr(charTbl[0]) if charTbl[0] < 128 else decodeIntToUnicode(charTbl[0])
174-
else:
185+
else:
175186
return None
176187

177188
maxChar = maxValue = charTbl[-1]
@@ -230,7 +241,11 @@ def getChar(idx, charTbl=asciiTbl, continuousOrder=True, expand=charsetType is N
230241
else:
231242
retVal = minValue + 1
232243
if retVal in originalTbl or (retVal == ord('\n') and CHAR_INFERENCE_MARK in payload):
233-
return chr(retVal) if retVal < 128 else decodeIntToUnicode(retVal)
244+
if timeBasedCompare and not validateChar(idx, retVal):
245+
logger.error("invalid character detected. retrying...")
246+
return getChar(idx, originalTbl, continuousOrder, expand)
247+
else:
248+
return chr(retVal) if retVal < 128 else decodeIntToUnicode(retVal)
234249
else:
235250
return None
236251
else:

0 commit comments

Comments
 (0)