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

Skip to content

Commit eafab03

Browse files
committed
safe decoding values going into --replicate (as we should have a "replicate" and sqlite3 supports all chars)
1 parent 30bfefd commit eafab03

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

lib/core/convert.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from lib.core.data import conf
2424
from lib.core.data import logger
25+
from lib.core.settings import HEX_ENCODED_CHAR_REGEX
2526
from lib.core.settings import UNICODE_ENCODING
2627
from lib.core.settings import URLENCODE_CHAR_LIMIT
2728
from lib.core.settings import URLENCODE_FAILSAFE_CHARS
@@ -145,11 +146,39 @@ def safecharencode(value):
145146
"""
146147

147148
retVal = value
149+
148150
if isinstance(value, basestring):
149151
retVal = reduce(lambda x, y: x + (y if (y in string.printable or ord(y) > 255) else '\%02x' % ord(y)), value, unicode())
150152
for char in "\t\n\r\x0b\x0c":
151153
retVal = retVal.replace(char, repr(char).strip('\''))
154+
152155
elif isinstance(value, list):
153156
for i in xrange(len(value)):
154157
retVal[i] = safecharencode(value[i])
158+
159+
return retVal
160+
161+
def safechardecode(value):
162+
"""
163+
Reverse function to safecharencode
164+
"""
165+
166+
retVal = value
167+
if isinstance(value, basestring):
168+
for char in "\t\n\r\x0b\x0c":
169+
retVal = retVal.replace(repr(char).strip('\''), char)
170+
171+
regex = re.compile(HEX_ENCODED_CHAR_REGEX)
172+
173+
while True:
174+
match = regex.search(retVal)
175+
if match:
176+
retVal = retVal.replace(match.group("result"), unhexlify(value.lstrip('\\')))
177+
else:
178+
break
179+
180+
elif isinstance(value, list):
181+
for i in xrange(len(value)):
182+
retVal[i] = safechardecode(value[i])
183+
155184
return retVal

lib/core/replication.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
See the file 'doc/COPYING' for copying permission
88
"""
99

10+
from lib.core.convert import safechardecode
1011
from lib.core.exception import sqlmapMissingDependence
1112
from lib.core.exception import sqlmapValueException
1213

@@ -63,8 +64,9 @@ def insert(self, values):
6364
"""
6465
This function is used for inserting row(s) into current table.
6566
"""
67+
6668
if len(values) == len(self.columns):
67-
self.parent.cursor.execute('INSERT INTO %s VALUES (%s)' % (self.name, ','.join(['?']*len(values))), values)
69+
self.parent.cursor.execute('INSERT INTO %s VALUES (%s)' % (self.name, ','.join(['?']*len(values))), safechardecode(values))
6870
else:
6971
errMsg = "wrong number of columns used in replicating insert"
7072
raise sqlmapValueException, errMsg

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,6 @@
304304

305305
# Parameters to be ignored in detection phase (upper case)
306306
IGNORE_PARAMETERS = ("__VIEWSTATE", "__EVENTARGUMENT", "__EVENTTARGET", "__EVENTVALIDATION", "ASPSESSIONID", "ASP.NET_SESSIONID", "JSESSIONID", "CFID", "CFTOKEN")
307+
308+
# Regex used for recognition of hex encoded characters
309+
HEX_ENCODED_CHAR_REGEX = r"(?P<result>\\[0-9A-Fa-f]{2})"

0 commit comments

Comments
 (0)