Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be443c6

Browse files
committed
refactoring regarding __START__,...
1 parent 2668c95 commit be443c6

6 files changed

Lines changed: 44 additions & 27 deletions

File tree

lib/core/common.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@
6161
from lib.core.settings import SQLITE_ALIASES
6262
from lib.core.settings import ACCESS_ALIASES
6363
from lib.core.settings import FIREBIRD_ALIASES
64-
64+
from lib.core.settings import DUMP_NEWLINE_MARKER
65+
from lib.core.settings import DUMP_DEL_MARKER
66+
from lib.core.settings import DUMP_TAB_MARKER
67+
from lib.core.settings import DUMP_START_MARKER
68+
from lib.core.settings import DUMP_STOP_MARKER
6569

6670
class UnicodeRawConfigParser(RawConfigParser):
6771
"""
@@ -558,9 +562,20 @@ def replaceNewlineTabs(inpStr, stdout=False):
558562
if stdout:
559563
replacedString = inpStr.replace("\n", " ").replace("\t", " ")
560564
else:
561-
replacedString = inpStr.replace("\n", "__NEWLINE__").replace("\t", "__TAB__")
565+
replacedString = inpStr.replace("\n", DUMP_NEWLINE_MARKER).replace("\t", DUMP_TAB_MARKER)
566+
567+
replacedString = replacedString.replace(kb.misc.delimiter, DUMP_DEL_MARKER)
568+
569+
return replacedString
570+
571+
def restoreDumpMarkedChars(inpStr, onlyNewlineTab=False):
572+
replacedString = inpStr
562573

563-
replacedString = replacedString.replace(kb.misc.delimiter, "__DEL__")
574+
if isinstance(replacedString, basestring):
575+
replacedString = replacedString.replace(DUMP_NEWLINE_MARKER, "\n").replace(DUMP_TAB_MARKER, "\t")
576+
if not onlyNewlineTab:
577+
replacedString = replacedString.replace(DUMP_START_MARKER, "").replace(DUMP_STOP_MARKER, "")
578+
replacedString = replacedString.replace(DUMP_DEL_MARKER, ", ")
564579

565580
return replacedString
566581

@@ -838,13 +853,13 @@ def parseUnionPage(output, expression, partial=False, condition=None, sort=True)
838853
data = []
839854

840855
outCond1 = ( output.startswith(kb.misc.start) and output.endswith(kb.misc.stop) )
841-
outCond2 = ( output.startswith("__START__") and output.endswith("__STOP__") )
856+
outCond2 = ( output.startswith(DUMP_START_MARKER) and output.endswith(DUMP_STOP_MARKER) )
842857

843858
if outCond1 or outCond2:
844859
if outCond1:
845860
regExpr = '%s(.*?)%s' % (kb.misc.start, kb.misc.stop)
846861
elif outCond2:
847-
regExpr = '__START__(.*?)__STOP__'
862+
regExpr = '%s(.*?)%s' % (DUMP_START_MARKER, DUMP_STOP_MARKER)
848863

849864
output = re.findall(regExpr, output, re.S)
850865

@@ -855,7 +870,7 @@ def parseUnionPage(output, expression, partial=False, condition=None, sort=True)
855870
)
856871

857872
if partial or not condition:
858-
logOutput = "".join(["__START__%s__STOP__" % replaceNewlineTabs(value) for value in output])
873+
logOutput = "".join(["%s%s%s" % (DUMP_START_MARKER, replaceNewlineTabs(value), DUMP_STOP_MARKER) for value in output])
859874
dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injPlace, conf.parameters[kb.injPlace], expression, logOutput))
860875

861876
if sort:
@@ -864,8 +879,8 @@ def parseUnionPage(output, expression, partial=False, condition=None, sort=True)
864879
for entry in output:
865880
info = []
866881

867-
if "__DEL__" in entry:
868-
entry = entry.split("__DEL__")
882+
if DUMP_DEL_MARKER in entry:
883+
entry = entry.split(DUMP_DEL_MARKER)
869884
else:
870885
entry = entry.split(kb.misc.delimiter)
871886

lib/core/dump.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from lib.core.common import dataToDumpFile
1515
from lib.core.common import dataToStdout
1616
from lib.core.common import getUnicode
17+
from lib.core.common import restoreDumpMarkedChars
1718
from lib.core.data import conf
1819
from lib.core.data import kb
1920
from lib.core.data import logger
@@ -39,13 +40,8 @@ def __write(self, data, n=True):
3940

4041
conf.loggedToOut = True
4142

42-
def __formatString(self, string):
43-
string = getUnicode(string)
44-
string = string.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
45-
string = string.replace("__START__", "").replace("__STOP__", "")
46-
string = string.replace("__DEL__", ", ")
47-
48-
return string
43+
def __formatString(self, inpStr):
44+
return restoreDumpMarkedChars(getUnicode(inpStr))
4945

5046
def setOutputFile(self):
5147
self.__outputFile = "%s%slog" % (conf.outputPath, os.sep)

lib/core/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333
LOGGER.addHandler(LOGGER_HANDLER)
3434
LOGGER.setLevel(logging.WARN)
3535

36-
# error based injection
36+
# dump markers
37+
DUMP_NEWLINE_MARKER = "__NEWLINE__"
38+
DUMP_DEL_MARKER = "__DEL__"
39+
DUMP_TAB_MARKER = "__TAB__"
40+
DUMP_START_MARKER = "__START__"
41+
DUMP_STOP_MARKER = "__STOP__"
42+
43+
# error based injection markers
3744
ERROR_SPACE = ":_:"
3845
ERROR_EMPTY_CHAR = ":x:"
3946
ERROR_START_CHAR = ":s:"

lib/core/xmldump.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from extra.prettyprint import prettyprint
1414
from lib.core.common import getUnicode
15+
from lib.core.common import restoreDumpMarkedChars
1516
from lib.core.data import conf
1617
from lib.core.data import logger
1718
from lib.core.exception import sqlmapFilePathException
@@ -137,12 +138,8 @@ def __createAttribute(self,attrName,attrValue):
137138
attr.nodeValue = getUnicode(attrValue)
138139
return attr
139140

140-
def __formatString(self, string):
141-
string = getUnicode(string)
142-
string = string.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
143-
string = string.replace("__START__", "").replace("__STOP__", "")
144-
string = string.replace("__DEL__", ", ")
145-
return string
141+
def __formatString(self, inpStr):
142+
return restoreDumpMarkedChars(getUnicode(inpStr))
146143

147144
def string(self, header, data, sort=True):
148145
'''

lib/request/inject.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from lib.core.common import pushValue
2222
from lib.core.common import randomInt
2323
from lib.core.common import readInput
24-
from lib.core.common import replaceNewlineTabs
2524
from lib.core.common import safeStringFormat
2625
from lib.core.convert import urlencode
2726
from lib.core.data import conf

lib/utils/resume.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
from lib.core.common import dataToSessionFile
1515
from lib.core.common import safeStringFormat
1616
from lib.core.common import randomStr
17-
from lib.core.common import replaceNewlineTabs
17+
from lib.core.common import restoreDumpMarkedChars
1818
from lib.core.data import conf
1919
from lib.core.data import kb
2020
from lib.core.data import logger
2121
from lib.core.data import queries
2222
from lib.core.unescaper import unescaper
2323
from lib.techniques.blind.inference import bisection
24+
from lib.core.settings import DUMP_START_MARKER
25+
from lib.core.settings import DUMP_STOP_MARKER
26+
from lib.core.settings import DUMP_DEL_MARKER
2427

2528
def queryOutputLength(expression, payload):
2629
"""
@@ -105,16 +108,16 @@ def resume(expression, payload):
105108
if not resumedValue:
106109
return None
107110

108-
resumedValue = resumedValue.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
111+
resumedValue = restoreDumpMarkedChars(resumedValue, True)
109112

110113
if resumedValue[-1] == "]":
111114
resumedValue = resumedValue[:-1]
112115

113116
infoMsg = "read from file '%s': " % conf.sessionFile
114-
logValue = re.findall("__START__(.*?)__STOP__", resumedValue, re.S)
117+
logValue = re.findall("%s(.*?)%s" % (DUMP_START_MARKER, DUMP_STOP_MARKER), resumedValue, re.S)
115118

116119
if logValue:
117-
logValue = ", ".join([value.replace("__DEL__", ", ") for value in logValue])
120+
logValue = ", ".join([value.replace(DUMP_DEL_MARKER, ", ") for value in logValue])
118121
else:
119122
logValue = resumedValue
120123

0 commit comments

Comments
 (0)