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

Skip to content

Commit 33b42a1

Browse files
committed
Fixes #3622
1 parent 9bb4930 commit 33b42a1

37 files changed

Lines changed: 127 additions & 97 deletions

lib/controller/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from lib.core.common import getPublicTypeMembers
3030
from lib.core.common import getSafeExString
3131
from lib.core.common import getSortedInjectionTests
32-
from lib.core.common import getUnicode
3332
from lib.core.common import hashDBRetrieve
3433
from lib.core.common import hashDBWrite
3534
from lib.core.common import intersect
@@ -49,6 +48,7 @@
4948
from lib.core.common import wasLastResponseDBMSError
5049
from lib.core.common import wasLastResponseHTTPError
5150
from lib.core.compat import xrange
51+
from lib.core.convert import getUnicode
5252
from lib.core.defaults import defaults
5353
from lib.core.data import conf
5454
from lib.core.data import kb

lib/core/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from lib.core.common import extractRegexResult
1313
from lib.core.common import filterNone
1414
from lib.core.common import getSQLSnippet
15-
from lib.core.common import getUnicode
1615
from lib.core.common import isDBMSVersionAtLeast
1716
from lib.core.common import isNumber
1817
from lib.core.common import isTechniqueAvailable
@@ -26,6 +25,7 @@
2625
from lib.core.common import urlencode
2726
from lib.core.common import zeroDepthSearch
2827
from lib.core.compat import xrange
28+
from lib.core.convert import getUnicode
2929
from lib.core.data import conf
3030
from lib.core.data import kb
3131
from lib.core.data import queries

lib/core/common.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from lib.core.convert import decodeHex
5757
from lib.core.convert import getBytes
5858
from lib.core.convert import getText
59+
from lib.core.convert import getUnicode
5960
from lib.core.convert import htmlunescape
6061
from lib.core.convert import stdoutencode
6162
from lib.core.data import conf
@@ -2418,50 +2419,6 @@ def getPartRun(alias=True):
24182419
else:
24192420
return retVal
24202421

2421-
def getUnicode(value, encoding=None, noneToNull=False):
2422-
"""
2423-
Return the unicode representation of the supplied value:
2424-
2425-
>>> getUnicode('test') == u'test'
2426-
True
2427-
>>> getUnicode(1) == u'1'
2428-
True
2429-
"""
2430-
2431-
if noneToNull and value is None:
2432-
return NULL
2433-
2434-
if isinstance(value, six.text_type):
2435-
return value
2436-
elif isinstance(value, six.binary_type):
2437-
# Heuristics (if encoding not explicitly specified)
2438-
candidates = filterNone((encoding, kb.get("pageEncoding") if kb.get("originalPage") else None, conf.get("encoding"), UNICODE_ENCODING, sys.getfilesystemencoding()))
2439-
if all(_ in value for _ in (b'<', b'>')):
2440-
pass
2441-
elif any(_ in value for _ in (b":\\", b'/', b'.')) and b'\n' not in value:
2442-
candidates = filterNone((encoding, sys.getfilesystemencoding(), kb.get("pageEncoding") if kb.get("originalPage") else None, UNICODE_ENCODING, conf.get("encoding")))
2443-
elif conf.get("encoding") and b'\n' not in value:
2444-
candidates = filterNone((encoding, conf.get("encoding"), kb.get("pageEncoding") if kb.get("originalPage") else None, sys.getfilesystemencoding(), UNICODE_ENCODING))
2445-
2446-
for candidate in candidates:
2447-
try:
2448-
return six.text_type(value, candidate)
2449-
except UnicodeDecodeError:
2450-
pass
2451-
2452-
try:
2453-
return six.text_type(value, encoding or (kb.get("pageEncoding") if kb.get("originalPage") else None) or UNICODE_ENCODING)
2454-
except UnicodeDecodeError:
2455-
return six.text_type(value, UNICODE_ENCODING, errors="reversible")
2456-
elif isListLike(value):
2457-
value = list(getUnicode(_, encoding, noneToNull) for _ in value)
2458-
return value
2459-
else:
2460-
try:
2461-
return six.text_type(value)
2462-
except UnicodeDecodeError:
2463-
return six.text_type(str(value), errors="ignore") # encoding ignored for non-basestring instances
2464-
24652422
def longestCommonPrefix(*sequences):
24662423
"""
24672424
Returns longest common prefix occuring in given sequences

lib/core/convert.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import re
1717
import sys
1818

19+
from lib.core.data import conf
20+
from lib.core.data import kb
1921
from lib.core.settings import INVALID_UNICODE_PRIVATE_AREA
2022
from lib.core.settings import IS_WIN
23+
from lib.core.settings import NULL
2124
from lib.core.settings import PICKLE_PROTOCOL
2225
from lib.core.settings import SAFE_HEX_MARKER
2326
from lib.core.settings import UNICODE_ENCODING
@@ -89,6 +92,12 @@ def singleTimeWarnMessage(message): # Cross-referenced function
8992
sys.stdout.write("\n")
9093
sys.stdout.flush()
9194

95+
def filterNone(values): # Cross-referenced function
96+
raise NotImplementedError
97+
98+
def isListLike(value): # Cross-referenced function
99+
raise NotImplementedError
100+
92101
def stdoutencode(data):
93102
retVal = data
94103

@@ -146,7 +155,7 @@ def decodeHex(value, binary=True):
146155
retVal = value
147156

148157
if isinstance(value, six.binary_type):
149-
value = value.decode(UNICODE_ENCODING)
158+
value = getText(value)
150159

151160
if value.lower().startswith("0x"):
152161
value = value[2:]
@@ -250,6 +259,50 @@ def getOrds(value):
250259

251260
return [_ if isinstance(_, int) else ord(_) for _ in value]
252261

262+
def getUnicode(value, encoding=None, noneToNull=False):
263+
"""
264+
Return the unicode representation of the supplied value:
265+
266+
>>> getUnicode('test') == u'test'
267+
True
268+
>>> getUnicode(1) == u'1'
269+
True
270+
"""
271+
272+
if noneToNull and value is None:
273+
return NULL
274+
275+
if isinstance(value, six.text_type):
276+
return value
277+
elif isinstance(value, six.binary_type):
278+
# Heuristics (if encoding not explicitly specified)
279+
candidates = filterNone((encoding, kb.get("pageEncoding") if kb.get("originalPage") else None, conf.get("encoding"), UNICODE_ENCODING, sys.getfilesystemencoding()))
280+
if all(_ in value for _ in (b'<', b'>')):
281+
pass
282+
elif any(_ in value for _ in (b":\\", b'/', b'.')) and b'\n' not in value:
283+
candidates = filterNone((encoding, sys.getfilesystemencoding(), kb.get("pageEncoding") if kb.get("originalPage") else None, UNICODE_ENCODING, conf.get("encoding")))
284+
elif conf.get("encoding") and b'\n' not in value:
285+
candidates = filterNone((encoding, conf.get("encoding"), kb.get("pageEncoding") if kb.get("originalPage") else None, sys.getfilesystemencoding(), UNICODE_ENCODING))
286+
287+
for candidate in candidates:
288+
try:
289+
return six.text_type(value, candidate)
290+
except UnicodeDecodeError:
291+
pass
292+
293+
try:
294+
return six.text_type(value, encoding or (kb.get("pageEncoding") if kb.get("originalPage") else None) or UNICODE_ENCODING)
295+
except UnicodeDecodeError:
296+
return six.text_type(value, UNICODE_ENCODING, errors="reversible")
297+
elif isListLike(value):
298+
value = list(getUnicode(_, encoding, noneToNull) for _ in value)
299+
return value
300+
else:
301+
try:
302+
return six.text_type(value)
303+
except UnicodeDecodeError:
304+
return six.text_type(str(value), errors="ignore") # encoding ignored for non-basestring instances
305+
253306
def getText(value):
254307
"""
255308
Returns textual value of a given value (Note: not necessary Unicode on Python2)
@@ -263,7 +316,7 @@ def getText(value):
263316
retVal = value
264317

265318
if isinstance(value, six.binary_type):
266-
retVal = value.decode(UNICODE_ENCODING)
319+
retVal = getUnicode(value)
267320

268321
if six.PY2:
269322
try:

lib/core/dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from lib.core.common import dataToDumpFile
1919
from lib.core.common import dataToStdout
2020
from lib.core.common import getSafeExString
21-
from lib.core.common import getUnicode
2221
from lib.core.common import isListLike
2322
from lib.core.common import isMultiThreadMode
2423
from lib.core.common import normalizeUnicode
@@ -29,6 +28,7 @@
2928
from lib.core.common import unsafeSQLIdentificatorNaming
3029
from lib.core.compat import xrange
3130
from lib.core.convert import getBytes
31+
from lib.core.convert import getUnicode
3232
from lib.core.data import conf
3333
from lib.core.data import kb
3434
from lib.core.data import logger

lib/core/option.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
import threading
1818
import time
1919

20-
import lib.controller.checks
21-
import lib.core.common
22-
import lib.core.threads
23-
import lib.core.convert
24-
import lib.request.connect
25-
import lib.utils.search
26-
2720
from lib.controller.checks import checkConnection
2821
from lib.core.common import Backend
2922
from lib.core.common import boldifyMessage
@@ -32,7 +25,6 @@
3225
from lib.core.common import decodeStringEscape
3326
from lib.core.common import getPublicTypeMembers
3427
from lib.core.common import getSafeExString
35-
from lib.core.common import getUnicode
3628
from lib.core.common import filterNone
3729
from lib.core.common import findLocalPort
3830
from lib.core.common import findPageForms
@@ -61,6 +53,7 @@
6153
from lib.core.common import urldecode
6254
from lib.core.compat import round
6355
from lib.core.compat import xrange
56+
from lib.core.convert import getUnicode
6457
from lib.core.data import conf
6558
from lib.core.data import kb
6659
from lib.core.data import logger
@@ -2621,15 +2614,6 @@ def _basicOptionValidation():
26212614
errMsg = "cookies file '%s' does not exist" % conf.loadCookies
26222615
raise SqlmapFilePathException(errMsg)
26232616

2624-
def _resolveCrossReferences():
2625-
lib.core.threads.readInput = readInput
2626-
lib.core.common.getPageTemplate = getPageTemplate
2627-
lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage
2628-
lib.request.connect.setHTTPHandlers = _setHTTPHandlers
2629-
lib.utils.search.setHTTPHandlers = _setHTTPHandlers
2630-
lib.controller.checks.setVerbosity = setVerbosity
2631-
lib.controller.checks.setWafFunctions = _setWafFunctions
2632-
26332617
def initOptions(inputOptions=AttribDict(), overrideOptions=False):
26342618
_setConfAttributes()
26352619
_setKnowledgeBaseAttributes()
@@ -2663,7 +2647,6 @@ def init():
26632647
_setWafFunctions()
26642648
_setTrafficOutputFP()
26652649
_setupHTTPCollector()
2666-
_resolveCrossReferences()
26672650
_setHttpChunked()
26682651
_checkWebSocket()
26692652

lib/core/patch.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@
77

88
import codecs
99

10+
import lib.controller.checks
11+
import lib.core.common
12+
import lib.core.threads
13+
import lib.core.convert
14+
import lib.request.connect
15+
import lib.utils.search
16+
import thirdparty.ansistrm.ansistrm
17+
18+
from lib.request.templates import getPageTemplate
19+
20+
from lib.core.common import filterNone
21+
from lib.core.common import isListLike
22+
from lib.core.common import singleTimeWarnMessage
23+
from lib.core.common import readInput
24+
from lib.core.convert import stdoutencode
25+
from lib.core.option import _setHTTPHandlers
26+
from lib.core.option import setVerbosity
27+
from lib.core.option import _setWafFunctions
1028
from lib.core.settings import IS_WIN
1129
from thirdparty.six.moves import http_client as _http_client
1230

@@ -32,3 +50,19 @@ def _(self, *args):
3250

3351
_http_client.LineAndFileWrapper._readline = _http_client.LineAndFileWrapper.readline
3452
_http_client.LineAndFileWrapper.readline = _
53+
54+
def resolveCrossReferences():
55+
"""
56+
Place for cross-reference resolution
57+
"""
58+
59+
lib.core.threads.readInput = readInput
60+
lib.core.common.getPageTemplate = getPageTemplate
61+
lib.core.convert.filterNone = filterNone
62+
lib.core.convert.isListLike = isListLike
63+
lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage
64+
lib.request.connect.setHTTPHandlers = _setHTTPHandlers
65+
lib.utils.search.setHTTPHandlers = _setHTTPHandlers
66+
lib.controller.checks.setVerbosity = setVerbosity
67+
lib.controller.checks.setWafFunctions = _setWafFunctions
68+
thirdparty.ansistrm.ansistrm.stdoutencode = stdoutencode

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty import six
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.5.21"
21+
VERSION = "1.3.5.22"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/core/target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from lib.core.common import Backend
1717
from lib.core.common import getSafeExString
18-
from lib.core.common import getUnicode
1918
from lib.core.common import hashDBRetrieve
2019
from lib.core.common import intersect
2120
from lib.core.common import isNumPosStrValue
@@ -27,6 +26,7 @@
2726
from lib.core.common import resetCookieJar
2827
from lib.core.common import urldecode
2928
from lib.core.compat import xrange
29+
from lib.core.convert import getUnicode
3030
from lib.core.data import conf
3131
from lib.core.data import kb
3232
from lib.core.data import logger

lib/core/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
from lib.controller.controller import start
2323
from lib.core.common import clearConsoleLine
2424
from lib.core.common import dataToStdout
25-
from lib.core.common import getUnicode
2625
from lib.core.common import randomStr
2726
from lib.core.common import readXmlFile
2827
from lib.core.common import shellExec
2928
from lib.core.compat import round
3029
from lib.core.compat import xrange
30+
from lib.core.convert import getUnicode
3131
from lib.core.data import conf
3232
from lib.core.data import logger
3333
from lib.core.data import paths

0 commit comments

Comments
 (0)