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

Skip to content

Commit 09aba3b

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

16 files changed

Lines changed: 65 additions & 36 deletions

File tree

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))

0 commit comments

Comments
 (0)