code refactoring

This commit is contained in:
Miroslav Stampar 2010-12-07 13:34:06 +00:00
parent 4f01d4c109
commit 0dc630203f
4 changed files with 10 additions and 15 deletions

View File

@ -95,7 +95,7 @@ def checkSqlInjection(place, parameter, value):
injection = injectionDict() injection = injectionDict()
# Clear cookies after each query page attempt # Clear cookies after each query page attempt
kb.flushCookies = True kb.testMode = True
for test in conf.tests: for test in conf.tests:
title = test.title title = test.title
@ -269,7 +269,6 @@ def checkSqlInjection(place, parameter, value):
# as we are changing parameters value, which will result # as we are changing parameters value, which will result
# most definitely with a different content # most definitely with a different content
kb.pageTemplate, _ = Request.queryPage(agent.payload(place, parameter, value, origValue), place, content=True) kb.pageTemplate, _ = Request.queryPage(agent.payload(place, parameter, value, origValue), place, content=True)
kb.testCount += 1
elif where == 3: elif where == 3:
origValue = "" origValue = ""
kb.pageTemplate = kb.originalPage kb.pageTemplate = kb.originalPage
@ -307,15 +306,12 @@ def checkSqlInjection(place, parameter, value):
# the False response content # the False response content
conf.matchRatio = None conf.matchRatio = None
_ = Request.queryPage(cmpPayload, place) _ = Request.queryPage(cmpPayload, place)
kb.testCount += 1
# Compare True and False response contents # Compare True and False response contents
trueResult = Request.queryPage(reqPayload, place) trueResult = Request.queryPage(reqPayload, place)
kb.testCount += 1
if trueResult: if trueResult:
falseResult = Request.queryPage(cmpPayload, place) falseResult = Request.queryPage(cmpPayload, place)
kb.testCount += 1
if not falseResult: if not falseResult:
infoMsg = "%s parameter '%s' is '%s' injectable " % (place, parameter, title) infoMsg = "%s parameter '%s' is '%s' injectable " % (place, parameter, title)
@ -329,7 +325,6 @@ def checkSqlInjection(place, parameter, value):
# Perform the test's request and grep the response # Perform the test's request and grep the response
# body for the test's <grep> regular expression # body for the test's <grep> regular expression
reqBody, _ = Request.queryPage(reqPayload, place, content=True) reqBody, _ = Request.queryPage(reqPayload, place, content=True)
kb.testCount += 1
output = extractRegexResult(check, reqBody, re.DOTALL | re.IGNORECASE) output = extractRegexResult(check, reqBody, re.DOTALL | re.IGNORECASE)
if output: if output:
@ -354,9 +349,7 @@ def checkSqlInjection(place, parameter, value):
# Perform the test's request and check how long # Perform the test's request and check how long
# it takes to get the response back # it takes to get the response back
start = time.time() start = time.time()
_ = Request.queryPage(reqPayload, place) _ = Request.queryPage(reqPayload, place)
kb.testCount += 1
duration = calculateDeltaSeconds(start) duration = calculateDeltaSeconds(start)
# Threat sleep and delayed (heavy query) differently # Threat sleep and delayed (heavy query) differently
@ -429,7 +422,7 @@ def checkSqlInjection(place, parameter, value):
break break
# Flush the flag # Flush the flag
kb.flushCookies = False kb.testMode = False
# Return the injection object # Return the injection object
if injection.place is not None and injection.parameter is not None: if injection.place is not None and injection.parameter is not None:

View File

@ -115,7 +115,7 @@ def __formatInjection(inj):
def __showInjections(): def __showInjections():
header = "sqlmap identified the following injection points " header = "sqlmap identified the following injection points "
header += "with %d HTTP(s) requests" % kb.testCount header += "with %d HTTP(s) requests" % kb.testQueryCount
data = "" data = ""
for inj in kb.injections: for inj in kb.injections:

View File

@ -1117,7 +1117,6 @@ def __setKnowledgeBaseAttributes():
kb.cache.content = {} kb.cache.content = {}
kb.cache.regex = {} kb.cache.regex = {}
kb.flushCookies = False
kb.commonOutputs = None kb.commonOutputs = None
kb.data = advancedDict() kb.data = advancedDict()
@ -1172,6 +1171,7 @@ def __setKnowledgeBaseAttributes():
kb.partRun = None kb.partRun = None
kb.proxyAuthHeader = None kb.proxyAuthHeader = None
kb.queryCounter = 0 kb.queryCounter = 0
kb.redirectSetCookie = None
kb.responseTime = 0 kb.responseTime = 0
kb.resumedQueries = {} kb.resumedQueries = {}
kb.retriesCount = 0 kb.retriesCount = 0
@ -1179,14 +1179,14 @@ def __setKnowledgeBaseAttributes():
kb.targetUrls = set() kb.targetUrls = set()
kb.testedParams = set() kb.testedParams = set()
kb.technique = None kb.technique = None
kb.testMode = False
kb.testQueryCount = 0
kb.unionComment = "" kb.unionComment = ""
kb.unionCount = None kb.unionCount = None
kb.unionPosition = None kb.unionPosition = None
kb.unionNegative = False kb.unionNegative = False
kb.userAgents = None kb.userAgents = None
kb.valueStack = [] kb.valueStack = []
kb.redirectSetCookie = None
kb.testCount = 0
def __saveCmdline(): def __saveCmdline():
""" """

View File

@ -407,7 +407,9 @@ class Connect:
if conf.textOnly: if conf.textOnly:
page = getFilteredPageContent(page) page = getFilteredPageContent(page)
if kb.flushCookies and conf.cj: if kb.testMode:
kb.testQueryCount += 1
if conf.cj:
conf.cj.clear() conf.cj.clear()
if content or response: if content or response: