minor update regarding last commit (cleaner code)

This commit is contained in:
Miroslav Stampar 2011-07-24 20:44:17 +00:00
parent 3a3561fdaa
commit 2033a28ae7
3 changed files with 40 additions and 42 deletions

View File

@ -1334,53 +1334,49 @@ def parseUnionPage(output, expression, partial=False, condition=None, sort=True)
data = BigArray() data = BigArray()
if isinstance(output, list): outCond1 = ( output.startswith(kb.misc.start) and output.endswith(kb.misc.stop) )
for entry in output: outCond2 = ( output.startswith(DUMP_START_MARKER) and output.endswith(DUMP_STOP_MARKER) )
data.append(entry[0] if len(entry) == 1 else entry)
else:
outCond1 = ( output.startswith(kb.misc.start) and output.endswith(kb.misc.stop) )
outCond2 = ( output.startswith(DUMP_START_MARKER) and output.endswith(DUMP_STOP_MARKER) )
if outCond1 or outCond2: if outCond1 or outCond2:
if outCond1: if outCond1:
regExpr = '%s(.*?)%s' % (kb.misc.start, kb.misc.stop) regExpr = '%s(.*?)%s' % (kb.misc.start, kb.misc.stop)
elif outCond2: elif outCond2:
regExpr = '%s(.*?)%s' % (DUMP_START_MARKER, DUMP_STOP_MARKER) regExpr = '%s(.*?)%s' % (DUMP_START_MARKER, DUMP_STOP_MARKER)
output = re.findall(regExpr, output, re.DOTALL | re.IGNORECASE) output = re.findall(regExpr, output, re.DOTALL | re.IGNORECASE)
if condition is None: if condition is None:
condition = ( condition = (
kb.resumedQueries and conf.url in kb.resumedQueries.keys() kb.resumedQueries and conf.url in kb.resumedQueries.keys()
and expression in kb.resumedQueries[conf.url].keys() and expression in kb.resumedQueries[conf.url].keys()
) )
if partial or not condition: if partial or not condition:
logOutput = "".join(["%s%s%s" % (DUMP_START_MARKER, replaceNewlineTabs(value), DUMP_STOP_MARKER) for value in output]) logOutput = "".join(["%s%s%s" % (DUMP_START_MARKER, replaceNewlineTabs(value), DUMP_STOP_MARKER) for value in output])
dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression, logOutput)) dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression, logOutput))
if sort:
dict_ = {}
for entry in output:
dict_[entry.lower()] = entry
output = dict_.values()
if sort:
dict_ = {}
for entry in output: for entry in output:
info = [] dict_[entry.lower()] = entry
output = dict_.values()
if DUMP_DEL_MARKER in entry: for entry in output:
entry = entry.split(DUMP_DEL_MARKER) info = []
else:
entry = entry.split(kb.misc.delimiter)
if len(entry) == 1: if DUMP_DEL_MARKER in entry:
data.append(entry[0]) entry = entry.split(DUMP_DEL_MARKER)
else: else:
for value in entry: entry = entry.split(kb.misc.delimiter)
info.append(value)
data.append(info) if len(entry) == 1:
else: data.append(entry[0])
data = output else:
for value in entry:
info.append(value)
data.append(info)
else:
data = output
if len(data) == 1 and isinstance(data[0], basestring): if len(data) == 1 and isinstance(data[0], basestring):
data = data[0] data = data[0]

View File

@ -375,7 +375,7 @@ def __goInband(expression, expected=None, sort=True, resumeValue=True, unpack=Tr
output = None output = None
partial = False partial = False
data = [] data = None
if resumeValue: if resumeValue:
output = resume(expression, None) output = resume(expression, None)
@ -386,7 +386,9 @@ def __goInband(expression, expected=None, sort=True, resumeValue=True, unpack=Tr
if output is None: if output is None:
output = unionUse(expression, unpack=unpack, dump=dump) output = unionUse(expression, unpack=unpack, dump=dump)
if output: if isinstance(output, list):
data = output
else:
data = parseUnionPage(output, expression, partial, None, sort) data = parseUnionPage(output, expression, partial, None, sort)
return data return data

View File

@ -309,7 +309,7 @@ def unionUse(expression, unpack=True, dump=False):
if all(map(lambda x: x in output, [kb.misc.start, kb.misc.stop])): if all(map(lambda x: x in output, [kb.misc.start, kb.misc.stop])):
items = extractRegexResult(r'%s(?P<result>.*?)%s' % (kb.misc.start, kb.misc.stop), output, re.DOTALL | re.IGNORECASE).split(kb.misc.delimiter) items = extractRegexResult(r'%s(?P<result>.*?)%s' % (kb.misc.start, kb.misc.stop), output, re.DOTALL | re.IGNORECASE).split(kb.misc.delimiter)
kb.locks.value.acquire() kb.locks.value.acquire()
threadData.shared.value.append(items) threadData.shared.value.append(items[0] if len(items) == 1 else items)
kb.locks.value.release() kb.locks.value.release()
else: else:
items = output.replace(kb.misc.start, "").replace(kb.misc.stop, "").split(kb.misc.delimiter) items = output.replace(kb.misc.start, "").replace(kb.misc.stop, "").split(kb.misc.delimiter)