From 68354be45a5510058e57d5781b2a6f06ae7e99d5 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Thu, 18 Dec 2008 22:49:35 +0000 Subject: [PATCH] Ahead with enhancements on comparison algorithm: implemented content-length technique --- lib/controller/checks.py | 17 +++++++++++------ lib/controller/controller.py | 5 +---- lib/request/comparison.py | 6 +++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 6e2b98d48..597b3a6b3 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -320,15 +320,16 @@ def checkStability(): contentLengths.append(int(clHeader.group(1))) if contentLengths: - clSum = 0 + conf.contentLengths = ( min(contentLengths), max(contentLengths) ) - for cl in contentLengths: - clSum += cl + warnMsg = "url is not stable, sqlmap inspected the headers " + warnMsg += "and identified that Content-Length can be used " + warnMsg += "in the comparison algorithm" + logger.warn(warnMsg) - clAverage = clSum / len(contentLengths) + kb.defaultResult = True - # TODO: go ahead here with the technique to compare True/False - # based upon clAverage discard (conf.contentLengths) + return True # Prepare for the comparison algorithm based on page content's # stable lines subset @@ -356,6 +357,10 @@ def checkStability(): return True + if condition == True: + logMsg = "url is stable" + logger.info(logMsg) + return condition diff --git a/lib/controller/controller.py b/lib/controller/controller.py index b734b9d66..f53b67ea2 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -175,10 +175,7 @@ def start(): if not kb.injPlace or not kb.injParameter or not kb.injType: if not conf.string and not conf.regexp and not conf.eRegexp: - if checkStability(): - logMsg = "url is stable" - logger.info(logMsg) - else: + if not checkStability(): errMsg = "url is not stable, try with --string or " errMsg += "--regexp options, refer to the user's manual " errMsg += "paragraph 'Page comparison' for details" diff --git a/lib/request/comparison.py b/lib/request/comparison.py index 3c7ad6847..dc60e66c3 100644 --- a/lib/request/comparison.py +++ b/lib/request/comparison.py @@ -75,7 +75,11 @@ def comparison(page, headers=None, content=False): # Comparison algorithm based on Content-Length header value elif conf.contentLengths: - pass + minValue = conf.contentLengths[0] - 10 + maxValue = conf.contentLengths[1] + 10 + + if len(page) >= minValue and len(page) <= maxValue: + return True # Comparison algorithm based on page content's stable lines subset elif conf.equalLines: