added checking of header values for GREP (error); still UNION to do

This commit is contained in:
Miroslav Stampar 2011-01-31 12:21:17 +00:00
parent a6f2cd56ff
commit 8ef47307db
3 changed files with 22 additions and 5 deletions

View File

@ -22,6 +22,7 @@ from lib.core.common import getComparePageRatio
from lib.core.common import getCompiledRegex from lib.core.common import getCompiledRegex
from lib.core.common import getSortedInjectionTests from lib.core.common import getSortedInjectionTests
from lib.core.common import getUnicode from lib.core.common import getUnicode
from lib.core.common import listToStrValue
from lib.core.common import popValue from lib.core.common import popValue
from lib.core.common import pushValue from lib.core.common import pushValue
from lib.core.common import randomInt from lib.core.common import randomInt
@ -320,8 +321,9 @@ def checkSqlInjection(place, parameter, value):
elif method == PAYLOAD.METHOD.GREP: elif method == PAYLOAD.METHOD.GREP:
# 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, raise404=False) page, headers = Request.queryPage(reqPayload, place, content=True, raise404=False)
output = extractRegexResult(check, reqBody, re.DOTALL | re.IGNORECASE) output = extractRegexResult(check, page, re.DOTALL | re.IGNORECASE)\
or extractRegexResult(check, listToStrValue(headers.headers if headers else None), re.DOTALL | re.IGNORECASE)
if output: if output:
result = output.replace(kb.misc.space, " ") == "1" result = output.replace(kb.misc.space, " ") == "1"

View File

@ -2292,3 +2292,16 @@ def unhandledExceptionMessage():
errMsg += "Technique: %s\n" % (enumValueToNameLookup(PAYLOAD.TECHNIQUE, kb.technique) if kb.technique else None) errMsg += "Technique: %s\n" % (enumValueToNameLookup(PAYLOAD.TECHNIQUE, kb.technique) if kb.technique else None)
errMsg += "Back-end DBMS: %s" % kb.dbms errMsg += "Back-end DBMS: %s" % kb.dbms
return errMsg return errMsg
def listToStrValue(value):
"""
Flattens list to a string value
>>> listToStrValue([1,2,3])
'1, 2, 3'
"""
if isinstance(value, list):
retValue = value.__str__().lstrip('[').rstrip(']')
else:
retValue = value
return retValue

View File

@ -11,12 +11,13 @@ import re
import time import time
from lib.core.agent import agent from lib.core.agent import agent
from lib.core.common import Backend
from lib.core.common import calculateDeltaSeconds from lib.core.common import calculateDeltaSeconds
from lib.core.common import dataToSessionFile from lib.core.common import dataToSessionFile
from lib.core.common import extractRegexResult from lib.core.common import extractRegexResult
from lib.core.common import Backend
from lib.core.common import initTechnique from lib.core.common import initTechnique
from lib.core.common import isNumPosStrValue from lib.core.common import isNumPosStrValue
from lib.core.common import listToStrValue
from lib.core.common import randomInt from lib.core.common import randomInt
from lib.core.common import replaceNewlineTabs from lib.core.common import replaceNewlineTabs
from lib.core.common import safeStringFormat from lib.core.common import safeStringFormat
@ -55,12 +56,13 @@ def __oneShotErrorUse(expression, field):
payload = agent.payload(newValue=injExpression) payload = agent.payload(newValue=injExpression)
# Perform the request # Perform the request
page, _ = Request.queryPage(payload, content=True) page, headers = Request.queryPage(payload, content=True)
reqCount += 1 reqCount += 1
# Parse the returned page to get the exact error-based # Parse the returned page to get the exact error-based
# sql injection output # sql injection output
output = extractRegexResult(check, page, re.DOTALL | re.IGNORECASE) output = extractRegexResult(check, page, re.DOTALL | re.IGNORECASE)\
or extractRegexResult(check, listToStrValue(headers.headers if headers else None), re.DOTALL | re.IGNORECASE)
dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression, replaceNewlineTabs(output))) dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression, replaceNewlineTabs(output)))