Skip to content

Commit afe497a

Browse files
committed
Dealing with basesting (one baby step closer to Py3 salvation)
1 parent 915bc1f commit afe497a

File tree

25 files changed

+112
-98
lines changed

25 files changed

+112
-98
lines changed

lib/controller/checks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
from lib.request.templates import getPageTemplate
106106
from lib.techniques.union.test import unionTest
107107
from lib.techniques.union.use import configUnion
108+
from thirdparty import six
108109
from thirdparty.six.moves import http_client as _http_client
109110

110111
def checkSqlInjection(place, parameter, value):
@@ -692,7 +693,7 @@ def genCmpPayload():
692693
# Test for UNION query SQL injection
693694
reqPayload, vector = unionTest(comment, place, parameter, value, prefix, suffix)
694695

695-
if isinstance(reqPayload, basestring):
696+
if isinstance(reqPayload, six.string_types):
696697
infoMsg = "%s parameter '%s' is '%s' injectable" % (paramType, parameter, title)
697698
logger.info(infoMsg)
698699

lib/core/common.py

Lines changed: 42 additions & 41 deletions
Large diffs are not rendered by default.

lib/core/convert.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from lib.core.settings import IS_WIN
1919
from lib.core.settings import UNICODE_ENCODING
20+
from thirdparty import six
2021

2122
def base64decode(value):
2223
"""
@@ -145,7 +146,7 @@ def htmlunescape(value):
145146
"""
146147

147148
retVal = value
148-
if value and isinstance(value, basestring):
149+
if value and isinstance(value, six.string_types):
149150
codes = (("&lt;", '<'), ("&gt;", '>'), ("&quot;", '"'), ("&nbsp;", ' '), ("&amp;", '&'), ("&apos;", "'"))
150151
retVal = reduce(lambda x, y: x.replace(y[0], y[1]), codes, retVal)
151152
try:

lib/core/dump.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def string(self, header, data, content_type=None, sort=True):
133133
if "\n" in _:
134134
self._write("%s:\n---\n%s\n---" % (header, _))
135135
else:
136-
self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, basestring) else _))
136+
self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, six.string_types) else _))
137137
else:
138138
self._write("%s:\tNone" % header)
139139

@@ -142,7 +142,7 @@ def lister(self, header, elements, content_type=None, sort=True):
142142
try:
143143
elements = set(elements)
144144
elements = list(elements)
145-
elements.sort(key=lambda _: _.lower() if isinstance(_, basestring) else _)
145+
elements.sort(key=lambda _: _.lower() if hasattr(_, "lower") else _)
146146
except:
147147
pass
148148

@@ -154,7 +154,7 @@ def lister(self, header, elements, content_type=None, sort=True):
154154
self._write("%s [%d]:" % (header, len(elements)))
155155

156156
for element in elements:
157-
if isinstance(element, basestring):
157+
if isinstance(element, six.string_types):
158158
self._write("[*] %s" % element)
159159
elif isListLike(element):
160160
self._write("[*] " + ", ".join(getUnicode(e) for e in element))
@@ -193,7 +193,7 @@ def userSettings(self, header, userSettings, subHeader, content_type=None):
193193
userSettings = userSettings[0]
194194

195195
users = userSettings.keys()
196-
users.sort(key=lambda _: _.lower() if isinstance(_, basestring) else _)
196+
users.sort(key=lambda _: _.lower() if hasattr(_, "lower") else _)
197197

198198
if conf.api:
199199
self._write(userSettings, content_type=content_type)
@@ -287,7 +287,7 @@ def dbTableColumns(self, tableColumns, content_type=None):
287287
colType = None
288288

289289
colList = columns.keys()
290-
colList.sort(key=lambda _: _.lower() if isinstance(_, basestring) else _)
290+
colList.sort(key=lambda _: _.lower() if hasattr(_, "lower") else _)
291291

292292
for column in colList:
293293
colType = columns[column]
@@ -379,7 +379,7 @@ def dbTablesCount(self, dbTables):
379379
if count is None:
380380
count = "Unknown"
381381

382-
tables.sort(key=lambda _: _.lower() if isinstance(_, basestring) else _)
382+
tables.sort(key=lambda _: _.lower() if hasattr(_, "lower") else _)
383383

384384
for table in tables:
385385
blank1 = " " * (maxlength1 - len(normalizeUnicode(table) or unicode(table)))

lib/core/option.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
from lib.utils.deps import checkDependencies
148148
from lib.utils.search import search
149149
from lib.utils.purge import purge
150+
from thirdparty import six
150151
from thirdparty.keepalive import keepalive
151152
from thirdparty.multipart import multipartpost
152153
from thirdparty.six.moves import http_client as _http_client
@@ -658,7 +659,7 @@ def _setTechnique():
658659
validTechniques = sorted(getPublicTypeMembers(PAYLOAD.TECHNIQUE), key=lambda x: x[1])
659660
validLetters = [_[0][0].upper() for _ in validTechniques]
660661

661-
if conf.tech and isinstance(conf.tech, basestring):
662+
if conf.tech and isinstance(conf.tech, six.string_types):
662663
_ = []
663664

664665
for letter in conf.tech.upper():
@@ -1737,7 +1738,7 @@ class _(unicode):
17371738
if conf.csvDel:
17381739
conf.csvDel = decodeStringEscape(conf.csvDel)
17391740

1740-
if conf.torPort and isinstance(conf.torPort, basestring) and conf.torPort.isdigit():
1741+
if conf.torPort and hasattr(conf.torPort, "isdigit") and conf.torPort.isdigit():
17411742
conf.torPort = int(conf.torPort)
17421743

17431744
if conf.torType:
@@ -2576,7 +2577,7 @@ def _basicOptionValidation():
25762577
errMsg = "option '--crack' should be used as a standalone"
25772578
raise SqlmapSyntaxException(errMsg)
25782579

2579-
if isinstance(conf.uCols, basestring):
2580+
if isinstance(conf.uCols, six.string_types):
25802581
if not conf.uCols.isdigit() and ("-" not in conf.uCols or len(conf.uCols.split("-")) != 2):
25812582
errMsg = "value for option '--union-cols' must be a range with hyphon "
25822583
errMsg += "(e.g. 1-10) or integer value (e.g. 5)"

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from lib.core.enums import OS
1818

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

lib/parse/payloads.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def cleanupVals(text, tag):
2424
if tag in ("clause", "where"):
2525
text = text.split(',')
2626

27-
if isinstance(text, basestring):
28-
text = int(text) if text.isdigit() else text
27+
if hasattr(text, "isdigit") and text.isdigit():
28+
text = int(text)
2929

3030
elif isinstance(text, list):
3131
count = 0

lib/request/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ def decodePage(page, contentEncoding, contentType):
257257
if not page or (conf.nullConnection and len(page) < 2):
258258
return getUnicode(page)
259259

260-
if isinstance(contentEncoding, basestring) and contentEncoding:
260+
if hasattr(contentEncoding, "lower"):
261261
contentEncoding = contentEncoding.lower()
262262
else:
263263
contentEncoding = ""
264264

265-
if isinstance(contentType, basestring) and contentType:
265+
if hasattr(contentType, "lower"):
266266
contentType = contentType.lower()
267267
else:
268268
contentType = ""

lib/request/connect.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class WebSocketException(Exception):
118118
from lib.request.direct import direct
119119
from lib.request.comparison import comparison
120120
from lib.request.methodrequest import MethodRequest
121+
from thirdparty import six
121122
from thirdparty.odict import OrderedDict
122123
from thirdparty.six.moves import http_client as _http_client
123124
from thirdparty.six.moves import urllib as _urllib
@@ -432,7 +433,7 @@ class _(dict):
432433
responseHeaders = _(ws.getheaders())
433434
responseHeaders.headers = ["%s: %s\r\n" % (_[0].capitalize(), _[1]) for _ in responseHeaders.items()]
434435

435-
requestHeaders += "\r\n".join(["%s: %s" % (getUnicode(key.capitalize() if isinstance(key, basestring) else key), getUnicode(value)) for (key, value) in responseHeaders.items()])
436+
requestHeaders += "\r\n".join(["%s: %s" % (getUnicode(key.capitalize() if hasattr(key, "capitalize") else key), getUnicode(value)) for (key, value) in responseHeaders.items()])
436437
requestMsg += "\r\n%s" % requestHeaders
437438

438439
if post is not None:
@@ -453,7 +454,7 @@ class _(dict):
453454
else:
454455
return None, None, None
455456

456-
requestHeaders += "\r\n".join(["%s: %s" % (getUnicode(key.capitalize() if isinstance(key, basestring) else key), getUnicode(value)) for (key, value) in req.header_items()])
457+
requestHeaders += "\r\n".join(["%s: %s" % (getUnicode(key.capitalize() if hasattr(key, "capitalize") else key), getUnicode(value)) for (key, value) in req.header_items()])
457458

458459
if not getRequestHeader(req, HTTP_HEADER.COOKIE) and conf.cj:
459460
conf.cj._policy._now = conf.cj._now = int(time.time())
@@ -745,7 +746,7 @@ class _(dict):
745746
raise SqlmapConnectionException(warnMsg)
746747

747748
finally:
748-
if isinstance(page, basestring) and not isinstance(page, unicode):
749+
if isinstance(six.binary_type):
749750
if HTTP_HEADER.CONTENT_TYPE in (responseHeaders or {}) and not re.search(TEXT_CONTENT_TYPE_REGEX, responseHeaders[HTTP_HEADER.CONTENT_TYPE]):
750751
page = unicode(page, errors="ignore")
751752
else:
@@ -858,7 +859,7 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
858859
errMsg += "function '%s' ('%s')" % (function.func_name, getSafeExString(ex))
859860
raise SqlmapGenericException(errMsg)
860861

861-
if not isinstance(payload, basestring):
862+
if not isinstance(payload, six.string_types):
862863
errMsg = "tamper function '%s' returns " % function.func_name
863864
errMsg += "invalid payload type ('%s')" % type(payload)
864865
raise SqlmapValueException(errMsg)
@@ -1156,7 +1157,7 @@ def _randomizeParameter(paramString, randomParameter):
11561157

11571158
for name, value in variables.items():
11581159
if name != "__builtins__" and originals.get(name, "") != value:
1159-
if isinstance(value, (basestring, int)):
1160+
if isinstance(value, (int, six.string_types)):
11601161
found = False
11611162
value = getUnicode(value, UNICODE_ENCODING)
11621163

lib/request/inject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from lib.techniques.dns.use import dnsUse
6060
from lib.techniques.error.use import errorUse
6161
from lib.techniques.union.use import unionUse
62+
from thirdparty import six
6263

6364
def _goDns(payload, expression):
6465
value = None
@@ -334,7 +335,7 @@ def _goUnion(expression, unpack=True, dump=False):
334335

335336
output = unionUse(expression, unpack=unpack, dump=dump)
336337

337-
if isinstance(output, basestring):
338+
if isinstance(output, six.string_types):
338339
output = parseUnionPage(output)
339340

340341
return output

0 commit comments

Comments
 (0)