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

Skip to content

Commit da15701

Browse files
committed
Minor DREI updates
1 parent 6b063e7 commit da15701

8 files changed

Lines changed: 57 additions & 102 deletions

File tree

lib/controller/checks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
from lib.core.common import wasLastResponseDBMSError
5050
from lib.core.common import wasLastResponseHTTPError
5151
from lib.core.compat import xrange
52-
from lib.core.convert import unicodeencode
5352
from lib.core.defaults import defaults
5453
from lib.core.data import conf
5554
from lib.core.data import kb
@@ -1611,7 +1610,7 @@ def checkConnection(suppressOutput=False):
16111610
kb.errorIsNone = True
16121611

16131612
if kb.redirectChoice == REDIRECTION.YES and threadData.lastRedirectURL and threadData.lastRedirectURL[0] == threadData.lastRequestUID:
1614-
if (threadData.lastRedirectURL[1] or "").startswith("https://") and unicodeencode(conf.hostname) in threadData.lastRedirectURL[1]:
1613+
if (threadData.lastRedirectURL[1] or "").startswith("https://") and conf.hostname in getUnicode(threadData.lastRedirectURL[1]):
16151614
conf.url = re.sub(r"https?://", "https://", conf.url)
16161615
match = re.search(r":(\d+)", threadData.lastRedirectURL[1])
16171616
port = match.group(1) if match else 443

lib/core/common.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
from lib.core.convert import hexdecode
5353
from lib.core.convert import htmlunescape
5454
from lib.core.convert import stdoutencode
55-
from lib.core.convert import unicodeencode
5655
from lib.core.convert import utf8encode
5756
from lib.core.data import conf
5857
from lib.core.data import kb
@@ -894,14 +893,14 @@ def setColor(message, color=None, bold=False, level=None):
894893
retVal = message
895894
level = level or extractRegexResult(r"\[(?P<result>%s)\]" % '|'.join(_[0] for _ in getPublicTypeMembers(LOGGING_LEVELS)), message)
896895

897-
if isinstance(level, unicode):
898-
level = unicodeencode(level)
899-
900896
if message and getattr(LOGGER_HANDLER, "is_tty", False): # colorizing handler
901897
if bold or color:
902898
retVal = colored(message, color=color, on_color=None, attrs=("bold",) if bold else None)
903899
elif level:
904-
level = getattr(logging, level, None) if isinstance(level, six.string_types) else level
900+
try:
901+
level = getattr(logging, level, None)
902+
except UnicodeError:
903+
level = None
905904
retVal = LOGGER_HANDLER.colorize(message, level)
906905

907906
return retVal
@@ -989,7 +988,7 @@ def dataToOutFile(filename, data):
989988

990989
try:
991990
with open(retVal, "w+b") as f: # has to stay as non-codecs because data is raw ASCII encoded data
992-
f.write(unicodeencode(data))
991+
f.write(getBytes(data))
993992
except UnicodeEncodeError as ex:
994993
_ = normalizeUnicode(filename)
995994
if filename != _:
@@ -2431,7 +2430,7 @@ def getUnicode(value, encoding=None, noneToNull=False):
24312430
except UnicodeDecodeError:
24322431
return six.text_type(str(value), errors="ignore") # encoding ignored for non-basestring instances
24332432

2434-
def getBytes(value):
2433+
def getBytes(value, encoding=UNICODE_ENCODING):
24352434
"""
24362435
Returns byte representation of provided Unicode value
24372436
@@ -2446,11 +2445,11 @@ def getBytes(value):
24462445
for char in xrange(0xF0000, 0xF00FF + 1):
24472446
value = value.replace(unichr(char), "%s%02x" % (SAFE_HEX_MARKER, char - 0xF0000))
24482447

2449-
retVal = value.encode(UNICODE_ENCODING)
2448+
retVal = value.encode(encoding)
24502449

24512450
retVal = re.sub(r"%s([0-9a-f]{2})" % SAFE_HEX_MARKER, lambda _: _.group(1).decode("hex"), retVal)
24522451
else:
2453-
retVal = value.encode(UNICODE_ENCODING)
2452+
retVal = value.encode(encoding)
24542453
retVal = re.sub(r"\\x([0-9a-f]{2})", lambda _: _.group(1).decode("hex"), retVal)
24552454

24562455
return retVal
@@ -4171,7 +4170,7 @@ def findPageForms(content, url, raise_=False, addToTargets=False):
41714170

41724171
class _(io.BytesIO):
41734172
def __init__(self, content, url):
4174-
io.BytesIO.__init__(self, unicodeencode(content, kb.pageEncoding) if isinstance(content, unicode) else content)
4173+
io.BytesIO.__init__(self, getBytes(content, kb.pageEncoding))
41754174
self._url = url
41764175

41774176
def geturl(self):

lib/core/dump.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from lib.core.common import checkFile
1818
from lib.core.common import dataToDumpFile
1919
from lib.core.common import dataToStdout
20+
from lib.core.common import getBytes
2021
from lib.core.common import getSafeExString
2122
from lib.core.common import getUnicode
2223
from lib.core.common import isListLike
@@ -26,7 +27,6 @@
2627
from lib.core.common import prioritySortColumns
2728
from lib.core.common import randomInt
2829
from lib.core.common import safeCSValue
29-
from lib.core.common import unicodeencode
3030
from lib.core.common import unsafeSQLIdentificatorNaming
3131
from lib.core.compat import xrange
3232
from lib.core.data import conf
@@ -422,8 +422,8 @@ def dbTableValues(self, tableValues):
422422
except:
423423
warnFile = True
424424

425-
_ = unicodeencode(re.sub(r"[^\w]", UNSAFE_DUMP_FILEPATH_REPLACEMENT, unsafeSQLIdentificatorNaming(db)))
426-
dumpDbPath = os.path.join(conf.dumpPath, "%s-%s" % (_, hashlib.md5(unicodeencode(db)).hexdigest()[:8]))
425+
_ = re.sub(r"[^\w]", UNSAFE_DUMP_FILEPATH_REPLACEMENT, unsafeSQLIdentificatorNaming(db))
426+
dumpDbPath = os.path.join(conf.dumpPath, "%s-%s" % (_, hashlib.md5(getBytes(db)).hexdigest()[:8]))
427427

428428
if not os.path.isdir(dumpDbPath):
429429
try:
@@ -456,8 +456,8 @@ def dbTableValues(self, tableValues):
456456

457457
_ = re.sub(r"[^\w]", UNSAFE_DUMP_FILEPATH_REPLACEMENT, normalizeUnicode(unsafeSQLIdentificatorNaming(table)))
458458
if len(_) < len(table) or IS_WIN and table.upper() in WINDOWS_RESERVED_NAMES:
459-
_ = unicodeencode(re.sub(r"[^\w]", UNSAFE_DUMP_FILEPATH_REPLACEMENT, unsafeSQLIdentificatorNaming(table)))
460-
dumpFileName = os.path.join(dumpDbPath, "%s-%s.%s" % (_, hashlib.md5(unicodeencode(table)).hexdigest()[:8], conf.dumpFormat.lower()))
459+
_ = re.sub(r"[^\w]", UNSAFE_DUMP_FILEPATH_REPLACEMENT, unsafeSQLIdentificatorNaming(table))
460+
dumpFileName = os.path.join(dumpDbPath, "%s-%s.%s" % (_, hashlib.md5(getBytes(table)).hexdigest()[:8], conf.dumpFormat.lower()))
461461
else:
462462
dumpFileName = os.path.join(dumpDbPath, "%s.%s" % (_, conf.dumpFormat.lower()))
463463
else:

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.4.27"
20+
VERSION = "1.3.4.28"
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/request/connect.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class WebSocketException(Exception):
5555
from lib.core.common import singleTimeWarnMessage
5656
from lib.core.common import stdev
5757
from lib.core.common import wasLastResponseDelayed
58-
from lib.core.common import unicodeencode
5958
from lib.core.common import unsafeVariableNaming
6059
from lib.core.common import urldecode
6160
from lib.core.common import urlencode
@@ -416,10 +415,9 @@ def getPage(**kwargs):
416415

417416
for key, value in headers.items():
418417
del headers[key]
419-
value = unicodeencode(value, kb.pageEncoding)
420418
for char in (r"\r", r"\n"):
421419
value = re.sub(r"(%s)([^ \t])" % char, r"\g<1>\t\g<2>", value)
422-
headers[unicodeencode(key, kb.pageEncoding)] = value.strip("\r\n")
420+
headers[getBytes(key)] = getBytes(value.strip("\r\n"))
423421

424422
url = getBytes(url)
425423
post = getBytes(post)
@@ -1134,7 +1132,7 @@ def _randomizeParameter(paramString, randomParameter):
11341132

11351133
while True:
11361134
try:
1137-
compile(unicodeencode(conf.evalCode.replace(';', '\n')), "", "exec")
1135+
compile(getBytes(conf.evalCode.replace(';', '\n')), "", "exec")
11381136
except SyntaxError as ex:
11391137
if ex.text:
11401138
original = replacement = ex.text.strip()

lib/techniques/union/use.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from lib.core.common import extractRegexResult
2222
from lib.core.common import firstNotNone
2323
from lib.core.common import flattenValue
24+
from lib.core.common import safeStringFormat
25+
from lib.core.common import getBytes
2426
from lib.core.common import getConsoleWidth
2527
from lib.core.common import getPartRun
2628
from lib.core.common import getUnicode
@@ -54,7 +56,6 @@
5456
from lib.core.settings import NULL
5557
from lib.core.settings import SQL_SCALAR_REGEX
5658
from lib.core.settings import TURN_OFF_RESUME_INFO_LIMIT
57-
from lib.core.settings import UNICODE_ENCODING
5859
from lib.core.threads import getCurrentThreadData
5960
from lib.core.threads import runThreads
6061
from lib.core.unescaper import unescaper
@@ -109,7 +110,7 @@ def _(regex):
109110
output = extractRegexResult(r"(?P<result>(<row.+?/>)+)", page)
110111
if output:
111112
try:
112-
root = xml.etree.ElementTree.fromstring("<root>%s</root>" % output.encode(UNICODE_ENCODING))
113+
root = xml.etree.ElementTree.fromstring(safeStringFormat("<root>%s</root>", getBytes(output)))
113114
retVal = ""
114115
for column in kb.dumpColumns:
115116
base64 = True

0 commit comments

Comments
 (0)