From 065d5b02ecbed86f7ea11ffa0df105b54b169b5b Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 25 May 2010 13:51:03 +0000 Subject: [PATCH] added singleValue parameter for good samaritan (same thing Bernardo wanted :) --- lib/core/common.py | 13 +++++++++---- lib/techniques/blind/inference.py | 12 +++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 152ccbe9b..672bbd2db 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1219,16 +1219,17 @@ def initCommonOutputs(): cfile.close() -def getGoodSamaritanCharsets(part, prevValue, originalCharset): +def getGoodSamaritanParameters(part, prevValue, originalCharset): ###wild card . (dot) is supported for compatibility with threading if kb.commonOutputs is None: initCommonOutputs() if not part or not prevValue: #is not None and != "" - return None, originalCharset + return None, None, originalCharset predictionSet = set() wildIndexes = [] + singleValue = None if prevValue[-1] != '.': prevValue += '.' @@ -1244,6 +1245,7 @@ def getGoodSamaritanCharsets(part, prevValue, originalCharset): if part in kb.commonOutputs: for item in kb.commonOutputs[part]: if re.search('\A%s' % prevValue, item): + singleValue = item for index in wildIndexes: char = item[index] @@ -1260,10 +1262,13 @@ def getGoodSamaritanCharsets(part, prevValue, originalCharset): predictedCharset.append(ordChar) predictedCharset.sort() + + if len(predictedCharset) > 1: + singleValue = None - return predictedCharset, otherCharset + return singleValue, predictedCharset, otherCharset else: - return None, originalCharset + return None, None, originalCharset def getCompiledRegex(regex): if regex in __compiledRegularExpressions: diff --git a/lib/techniques/blind/inference.py b/lib/techniques/blind/inference.py index b7a8d977e..ab4ac3d27 100644 --- a/lib/techniques/blind/inference.py +++ b/lib/techniques/blind/inference.py @@ -30,7 +30,7 @@ from lib.core.agent import agent from lib.core.common import dataToSessionFile from lib.core.common import dataToStdout from lib.core.common import getCharset -from lib.core.common import getGoodSamaritanCharsets +from lib.core.common import getGoodSamaritanParameters from lib.core.common import replaceNewlineTabs from lib.core.common import safeStringFormat from lib.core.convert import urlencode @@ -370,8 +370,14 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None charStart = time.time() if conf.useCommonPrediction: - predictedCharset, otherCharset = getGoodSamaritanCharsets(kb.partRun, finalValue, asciiTbl) - val = getChar(index, predictedCharset, False) if predictedCharset else None + singleValue, predictedCharset, otherCharset = getGoodSamaritanParameters(kb.partRun, finalValue, asciiTbl) + if singleValue is None: + val = getChar(index, predictedCharset, False) if predictedCharset else None + else: + ##check if that's the value + #finalValue = singleValue + #break + pass if not val: val = getChar(index, otherCharset) else: