Skip to content

Commit 09aba3b

Browse files
committed
More DREI updates
1 parent 1241a02 commit 09aba3b

File tree

16 files changed

+65
-36
lines changed

16 files changed

+65
-36
lines changed

extra/shutils/drei.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# Stress test against Python3
77

88
export SQLMAP_DREI=1
9-
for i in $(find . -iname "*.py" | grep -v __init__); do python3 -c 'import '`echo $i | cut -d '.' -f 2 | cut -d '/' -f 2- | sed 's/\//./g'`''; done
9+
#for i in $(find . -iname "*.py" | grep -v __init__); do python3 -c 'import '`echo $i | cut -d '.' -f 2 | cut -d '/' -f 2- | sed 's/\//./g'`''; done
10+
for i in $(find . -iname "*.py" | grep -v __init__); do PYTHONWARNINGS=all python3.7 -m compileall $i; done
1011
unset SQLMAP_DREI
1112
source `dirname "$0"`"/junk.sh"
1213

lib/controller/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ def checkConnection(suppressOutput=False):
16141614
conf.url = re.sub(r"https?://", "https://", conf.url)
16151615
match = re.search(r":(\d+)", threadData.lastRedirectURL[1])
16161616
port = match.group(1) if match else 443
1617-
conf.url = re.sub(r":\d+(/|\Z)", ":%s\g<1>" % port, conf.url)
1617+
conf.url = re.sub(r":\d+(/|\Z)", r":%s\g<1>" % port, conf.url)
16181618

16191619
except SqlmapConnectionException as ex:
16201620
if conf.ipv6:

lib/core/common.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ def expandAsteriskForColumns(expression):
16351635
if expression != conf.sqlQuery:
16361636
conf.db = db
16371637
else:
1638-
expression = re.sub(r"([^\w])%s" % re.escape(conf.tbl), "\g<1>%s.%s" % (conf.db, conf.tbl), expression)
1638+
expression = re.sub(r"([^\w])%s" % re.escape(conf.tbl), r"\g<1>%s.%s" % (conf.db, conf.tbl), expression)
16391639
else:
16401640
conf.db = db
16411641

@@ -1795,12 +1795,24 @@ def getFileType(filePath):
17951795
17961796
>>> getFileType(__file__)
17971797
'text'
1798+
>>> getFileType(sys.executable)
1799+
'binary'
17981800
"""
17991801

18001802
try:
18011803
desc = getUnicode(magic.from_file(filePath) or "")
18021804
except:
1803-
return "unknown"
1805+
desc = magic.MAGIC_UNKNOWN_FILETYPE
1806+
1807+
if desc == magic.MAGIC_UNKNOWN_FILETYPE:
1808+
content = openFile(filePath, "rb", encoding=None).read()
1809+
1810+
try:
1811+
content.decode()
1812+
except:
1813+
pass
1814+
else:
1815+
desc = "ascii"
18041816

18051817
return "text" if any(_ in desc.lower() for _ in ("ascii", "text")) else "binary"
18061818

@@ -2053,8 +2065,8 @@ def isWindowsDriveLetterPath(filepath):
20532065

20542066
def posixToNtSlashes(filepath):
20552067
"""
2056-
Replaces all occurrences of Posix slashes (/) in provided
2057-
filepath with NT ones (\)
2068+
Replaces all occurrences of Posix slashes in provided
2069+
filepath with NT backslashes
20582070
20592071
>>> posixToNtSlashes('C:/Windows')
20602072
'C:\\\\Windows'
@@ -2064,8 +2076,8 @@ def posixToNtSlashes(filepath):
20642076

20652077
def ntToPosixSlashes(filepath):
20662078
"""
2067-
Replaces all occurrences of NT slashes (\) in provided
2068-
filepath with Posix ones (/)
2079+
Replaces all occurrences of NT backslashes in provided
2080+
filepath with Posix slashes
20692081
20702082
>>> ntToPosixSlashes('C:\\Windows')
20712083
'C:/Windows'
@@ -2954,7 +2966,7 @@ def findDynamicContent(firstPage, secondPage):
29542966
infoMsg = "searching for dynamic content"
29552967
singleTimeLogMessage(infoMsg)
29562968

2957-
blocks = SequenceMatcher(None, firstPage, secondPage).get_matching_blocks()
2969+
blocks = list(SequenceMatcher(None, firstPage, secondPage).get_matching_blocks())
29582970
kb.dynamicMarkings = []
29592971

29602972
# Removing too small matching blocks
@@ -4654,8 +4666,8 @@ def decloakToTemp(filename):
46544666

46554667
content = decloak(filename)
46564668

4657-
parts = getBytes(os.path.split(filename[:-1])[-1]).split(b'.')
4658-
prefix, suffix = parts[0], b".%s" % parts[-1]
4669+
parts = os.path.split(filename[:-1])[-1].split('.')
4670+
prefix, suffix = parts[0], '.' + parts[-1]
46594671
handle, filename = tempfile.mkstemp(prefix=prefix, suffix=suffix)
46604672
os.close(handle)
46614673

@@ -4692,7 +4704,7 @@ def getRequestHeader(request, name):
46924704

46934705
if request and request.headers and name:
46944706
_ = name.upper()
4695-
retVal = max(value if _ == key.upper() else type(value)() for key, value in request.header_items()) or None
4707+
retVal = max(getBytes(value if _ == key.upper() else "") for key, value in request.header_items()) or None
46964708

46974709
return retVal
46984710

lib/core/convert.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pickle
1212

1313
import base64
14+
import binascii
1415
import codecs
1516
import json
1617
import re
@@ -160,7 +161,10 @@ def decodeHex(value, binary=True):
160161
if value.lower().startswith("0x"):
161162
value = value[2:]
162163

163-
retVal = codecs.decode(value, "hex")
164+
try:
165+
retVal = codecs.decode(value, "hex")
166+
except LookupError:
167+
retVal = binascii.unhexlify(value)
164168

165169
if not binary:
166170
retVal = getText(retVal)
@@ -180,7 +184,10 @@ def encodeHex(value, binary=True):
180184
if isinstance(value, six.text_type):
181185
value = value.encode(UNICODE_ENCODING)
182186

183-
retVal = codecs.encode(value, "hex")
187+
try:
188+
retVal = codecs.encode(value, "hex")
189+
except LookupError:
190+
retVal = binascii.hexlify(value)
184191

185192
if not binary:
186193
retVal = getText(retVal)

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.49"
21+
VERSION = "1.3.5.50"
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/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def replaceVars(item, vars_):
410410
retVal = item
411411

412412
if item and vars_:
413-
for var in re.findall("\$\{([^}]+)\}", item):
413+
for var in re.findall(r"\$\{([^}]+)\}", item):
414414
if var in vars_:
415415
retVal = retVal.replace("${%s}" % var, vars_[var])
416416

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ def cmdLineParser(argv=None):
697697
parser.add_option("--murphy-rate", dest="murphyRate", type="int",
698698
help=SUPPRESS_HELP)
699699

700+
parser.add_option("--debug", dest="debug", action="store_true",
701+
help=SUPPRESS_HELP)
702+
700703
parser.add_option("--disable-precon", dest="disablePrecon", action="store_true",
701704
help=SUPPRESS_HELP)
702705

lib/request/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def decodePage(page, contentEncoding, contentType):
323323
# e.g. &#x9;&#195;&#235;&#224;&#226;&#224;
324324
if b"&#" in page:
325325
page = re.sub(b"&#x([0-9a-f]{1,2});", lambda _: decodeHex(_.group(1) if len(_.group(1)) == 2 else "0%s" % _.group(1)), page)
326-
page = re.sub(b"&#(\d{1,3});", lambda _: six.int2byte(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)
326+
page = re.sub(b"&#(\\d{1,3});", lambda _: six.int2byte(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)
327327

328328
# e.g. %20%28%29
329329
if b"%" in page:

lib/request/connect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ class _(dict):
674674
except (_urllib.error.URLError, socket.error, socket.timeout, _http_client.HTTPException, struct.error, binascii.Error, ProxyError, SqlmapCompressionException, WebSocketException, TypeError, ValueError, OverflowError):
675675
tbMsg = traceback.format_exc()
676676

677+
if conf.debug:
678+
dataToStdout(tbMsg)
679+
677680
if checking:
678681
return None, None, None
679682
elif "no host given" in tbMsg:

lib/takeover/metasploit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def _controlMsfCmd(self, proc, func):
573573
timeout = time.time() - start_time > METASPLOIT_SESSION_TIMEOUT
574574

575575
if not initialized:
576-
match = re.search(b"Meterpreter session ([\d]+) opened", out)
576+
match = re.search(b"Meterpreter session ([\\d]+) opened", out)
577577

578578
if match:
579579
self._loadMetExtensions(proc, match.group(1))
@@ -625,7 +625,7 @@ def createMsfShellcode(self, exitfunc, format, extra, encode):
625625
pollProcess(process)
626626
payloadStderr = process.communicate()[1]
627627

628-
match = re.search(b"(Total size:|Length:|succeeded with size|Final size of exe file:) ([\d]+)", payloadStderr)
628+
match = re.search(b"(Total size:|Length:|succeeded with size|Final size of exe file:) ([\\d]+)", payloadStderr)
629629

630630
if match:
631631
payloadSize = int(match.group(2))

lib/utils/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
737737
DataStore.password = password
738738

739739
dbgMsg = "Example client access from command line:"
740-
dbgMsg += "\n\t$ taskid=$(curl http://%s:%d/task/new 2>1 | grep -o -I '[a-f0-9]\{16\}') && echo $taskid" % (host, port)
740+
dbgMsg += "\n\t$ taskid=$(curl http://%s:%d/task/new 2>1 | grep -o -I '[a-f0-9]\\{16\\}') && echo $taskid" % (host, port)
741741
dbgMsg += "\n\t$ curl -H \"Content-Type: application/json\" -X POST -d '{\"url\": \"http://testphp.vulnweb.com/artists.php?artist=1\"}' http://%s:%d/scan/$taskid/start" % (host, port)
742742
dbgMsg += "\n\t$ curl http://%s:%d/scan/$taskid/data" % (host, port)
743743
dbgMsg += "\n\t$ curl http://%s:%d/scan/$taskid/log" % (host, port)

lib/utils/crawler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from lib.core.common import safeCSValue
2121
from lib.core.common import urldecode
2222
from lib.core.compat import xrange
23+
from lib.core.convert import htmlunescape
2324
from lib.core.data import conf
2425
from lib.core.data import kb
2526
from lib.core.data import logger
@@ -90,15 +91,15 @@ def crawlThread():
9091
tags = soup('a')
9192

9293
if not tags:
93-
tags = re.finditer(r'(?i)<a[^>]+href="(?P<href>[^>"]+)"', content)
94+
tags = re.finditer(r'(?i)<a[^>]+href=["\'](?P<href>[^>"\']+)', content)
9495

9596
for tag in tags:
9697
href = tag.get("href") if hasattr(tag, "get") else tag.group("href")
9798

9899
if href:
99100
if threadData.lastRedirectURL and threadData.lastRedirectURL[0] == threadData.lastRequestUID:
100101
current = threadData.lastRedirectURL[1]
101-
url = _urllib.parse.urljoin(current, href)
102+
url = _urllib.parse.urljoin(current, htmlunescape(href))
102103

103104
# flag to know if we are dealing with the same target host
104105
_ = checkSameHost(url, target)

lib/utils/hash.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def mssql_passwd(password, salt, uppercase=False):
162162
"""
163163

164164
binsalt = decodeHex(salt)
165-
unistr = b"".join(b"%s\0" % _.encode(UNICODE_ENCODING) if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in password)
165+
unistr = b"".join((_.encode(UNICODE_ENCODING) + b"\0") if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in password)
166166

167167
retVal = "0100%s%s" % (salt, sha1(unistr + binsalt).hexdigest())
168168

@@ -180,7 +180,7 @@ def mssql_old_passwd(password, salt, uppercase=True): # prior to version '2005'
180180
"""
181181

182182
binsalt = decodeHex(salt)
183-
unistr = b"".join(b"%s\0" % _.encode(UNICODE_ENCODING) if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in password)
183+
unistr = b"".join((_.encode(UNICODE_ENCODING) + b"\0") if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in password)
184184

185185
retVal = "0100%s%s%s" % (salt, sha1(unistr + binsalt).hexdigest(), sha1(unistr.upper() + binsalt).hexdigest())
186186

@@ -196,7 +196,7 @@ def mssql_new_passwd(password, salt, uppercase=False):
196196
"""
197197

198198
binsalt = decodeHex(salt)
199-
unistr = b"".join(b"%s\0" % _.encode(UNICODE_ENCODING) if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in password)
199+
unistr = b"".join((_.encode(UNICODE_ENCODING) + b"\0") if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in password)
200200

201201
retVal = "0200%s%s" % (salt, sha512(unistr + binsalt).hexdigest())
202202

@@ -231,7 +231,7 @@ def oracle_old_passwd(password, username, uppercase=True): # prior to version '
231231

232232
IV, pad = "\0" * 8, "\0"
233233

234-
unistr = b"".join(b"\0%s" % _.encode(UNICODE_ENCODING) if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in (username + password).upper())
234+
unistr = b"".join((b"\0" + _.encode(UNICODE_ENCODING)) if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in (username + password).upper())
235235

236236
cipher = des(decodeHex("0123456789ABCDEF"), CBC, IV, pad)
237237
encrypted = cipher.encrypt(unistr)
@@ -434,7 +434,7 @@ def _encode64(value, count):
434434
hash_ = hash_ + _encode64((int(ord(final[4:5])) << 16) | (int(ord(final[10:11])) << 8) | (int(ord(final[5:6]))), 4)
435435
hash_ = hash_ + _encode64((int(ord(final[11:12]))), 2)
436436

437-
return getText(b"%s%s$%s" % (magic, salt, getBytes(hash_)))
437+
return getText(magic + salt + b'$' + getBytes(hash_))
438438

439439
def joomla_passwd(password, salt, **kwargs):
440440
"""
@@ -444,7 +444,7 @@ def joomla_passwd(password, salt, **kwargs):
444444
'e3d5794da74e917637332e0d21b76328:6GGlnaquVXI80b3HRmSyE3K1wEFFaBIf'
445445
"""
446446

447-
return "%s:%s" % (md5(b"%s%s" % (getBytes(password), getBytes(salt))).hexdigest(), salt)
447+
return "%s:%s" % (md5(getBytes(password) + getBytes(salt)).hexdigest(), salt)
448448

449449
def django_md5_passwd(password, salt, **kwargs):
450450
"""
@@ -454,7 +454,7 @@ def django_md5_passwd(password, salt, **kwargs):
454454
'md5$salt$972141bcbcb6a0acc96e92309175b3c5'
455455
"""
456456

457-
return "md5$%s$%s" % (salt, md5(b"%s%s" % (getBytes(salt), getBytes(password))).hexdigest())
457+
return "md5$%s$%s" % (salt, md5(getBytes(salt) + getBytes(password)).hexdigest())
458458

459459
def django_sha1_passwd(password, salt, **kwargs):
460460
"""
@@ -464,7 +464,7 @@ def django_sha1_passwd(password, salt, **kwargs):
464464
'sha1$salt$6ce0e522aba69d8baa873f01420fccd0250fc5b2'
465465
"""
466466

467-
return "sha1$%s$%s" % (salt, sha1(b"%s%s" % (getBytes(salt), getBytes(password))).hexdigest())
467+
return "sha1$%s$%s" % (salt, sha1(getBytes(salt) + getBytes(password)).hexdigest())
468468

469469
def vbulletin_passwd(password, salt, **kwargs):
470470
"""
@@ -474,7 +474,7 @@ def vbulletin_passwd(password, salt, **kwargs):
474474
'85c4d8ea77ebef2236fb7e9d24ba9482:salt'
475475
"""
476476

477-
return "%s:%s" % (md5(b"%s%s" % (binascii.hexlify(md5(getBytes(password)).digest()), getBytes(salt))).hexdigest(), salt)
477+
return "%s:%s" % (md5(binascii.hexlify(md5(getBytes(password)).digest()) + getBytes(salt)).hexdigest(), salt)
478478

479479
def wordpress_passwd(password, salt, count, prefix, **kwargs):
480480
"""

thirdparty/beautifulsoup/beautifulsoup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
xrange = range
9494
text_type = str
9595
binary_type = bytes
96+
basestring = str
9697
else:
9798
text_type = unicode
9899
binary_type = str
@@ -673,7 +674,7 @@ def __call__(self, *args, **kwargs):
673674
"""Calling a tag like a function is the same as calling its
674675
findAll() method. Eg. tag('a') returns a list of all the A tags
675676
found within this tag."""
676-
return apply(self.findAll, args, kwargs)
677+
return self.findAll(*args, **kwargs)
677678

678679
def __getattr__(self, tag):
679680
#print "Getattr %s.%s" % (self.__class__, tag)
@@ -1332,7 +1333,7 @@ def _smartPop(self, name):
13321333
if (nestingResetTriggers is not None
13331334
and p.name in nestingResetTriggers) \
13341335
or (nestingResetTriggers is None and isResetNesting
1335-
and self.RESET_NESTING_TAGS.has_key(p.name)):
1336+
and p.name in self.RESET_NESTING_TAGS):
13361337

13371338
#If we encounter one of the nesting reset triggers
13381339
#peculiar to this tag, or we encounter another tag

thirdparty/fcrypt/fcrypt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def _PERM_OP(a,b,n,m):
455455
def _set_key(password):
456456
"""Generate DES key schedule from ASCII password."""
457457

458-
c,d = struct.unpack('<ii', password)
458+
c,d = struct.unpack('<ii', password.encode("utf8") if not isinstance(password, bytes) else password)
459459
c = (c & 0x7f7f7f7f) << 1
460460
d = (d & 0x7f7f7f7f) << 1
461461

@@ -606,7 +606,7 @@ def crypt(password, salt):
606606
# Convert to characters.
607607
for i in xrange(len(r)):
608608
r[i] = _cov_2char[r[i]]
609-
return salt[:2] + string.join(r, '')
609+
return salt[:2] + ''.join(r)
610610

611611
def _test():
612612
"""Run doctest on fcrypt module."""

thirdparty/magic/magic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def magic_load(cookie, filename):
200200
magic_compile.argtypes = [magic_t, c_char_p]
201201

202202
except (ImportError, OSError):
203-
from_file = from_buffer = lambda *args, **kwargs: "unknown"
203+
from_file = from_buffer = lambda *args, **kwargs: MAGIC_UNKNOWN_FILETYPE
204204

205205
MAGIC_NONE = 0x000000 # No flags
206206
MAGIC_DEBUG = 0x000001 # Turn on debugging
@@ -223,3 +223,4 @@ def magic_load(cookie, filename):
223223
MAGIC_NO_CHECK_TROFF = 0x040000 # Don't check ascii/troff
224224
MAGIC_NO_CHECK_FORTRAN = 0x080000 # Don't check ascii/fortran
225225
MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens
226+
MAGIC_UNKNOWN_FILETYPE = "unknown"

0 commit comments

Comments
 (0)