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

Skip to content

Commit 585ebca

Browse files
committed
Couple of DREI updates
1 parent 74148e1 commit 585ebca

8 files changed

Lines changed: 37 additions & 35 deletions

File tree

lib/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,8 +4108,8 @@ def asciifyUrl(url, forceQuote=False):
41084108
41094109
# Reference: http://blog.elsdoerfer.name/2008/12/12/opening-iris-in-python/
41104110
4111-
>>> asciifyUrl(u'http://www.\\u0161u\\u0107uraj.com') == u'http://www.xn--uuraj-gxa24d.com'
4112-
True
4111+
>>> asciifyUrl(u'http://www.\\u0161u\\u0107uraj.com')
4112+
'http://www.xn--uuraj-gxa24d.com'
41134113
"""
41144114

41154115
parts = _urllib.parse.urlsplit(url)

lib/core/compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,7 @@ def round(x, d=0):
204204

205205
if sys.version_info >= (3, 0):
206206
xrange = range
207+
buffer = memoryview
207208
else:
208209
xrange = xrange
210+
buffer = buffer

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.13"
21+
VERSION = "1.3.5.14"
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/subprocessng.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import time
1212

13+
from lib.core.compat import buffer
1314
from lib.core.settings import IS_WIN
1415

1516
if IS_WIN:
@@ -26,7 +27,7 @@
2627
def blockingReadFromFD(fd):
2728
# Quick twist around original Twisted function
2829
# Blocking read from a non-blocking file descriptor
29-
output = ""
30+
output = b""
3031

3132
while True:
3233
try:
@@ -183,7 +184,7 @@ def recv_some(p, t=.1, e=1, tr=5, stderr=0):
183184
y.append(r)
184185
else:
185186
time.sleep(max((x - time.time()) / tr, 0))
186-
return ''.join(y)
187+
return b''.join(y)
187188

188189
def send_all(p, data):
189190
if not data:
@@ -193,4 +194,4 @@ def send_all(p, data):
193194
sent = p.send(data)
194195
if not isinstance(sent, int):
195196
break
196-
data = buffer(data, sent)
197+
data = buffer(data[sent:])

lib/request/connect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ def getPage(**kwargs):
420420
value = re.sub(r"(%s)([^ \t])" % char, r"\g<1>\t\g<2>", value)
421421
headers[getBytes(key)] = getBytes(value.strip("\r\n"))
422422

423+
url = getBytes(url)
423424
post = getBytes(post)
424425

425426
if websocket_:
@@ -671,6 +672,7 @@ class _(dict):
671672
except (_urllib.error.URLError, socket.error, socket.timeout, _http_client.HTTPException, struct.error, binascii.Error, ProxyError, SqlmapCompressionException, WebSocketException, TypeError, ValueError, OverflowError):
672673
tbMsg = traceback.format_exc()
673674

675+
print(tbMsg)
674676
if checking:
675677
return None, None, None
676678
elif "no host given" in tbMsg:

lib/takeover/metasploit.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from lib.core.common import randomRange
2929
from lib.core.common import randomStr
3030
from lib.core.common import readInput
31+
from lib.core.convert import getBytes
32+
from lib.core.convert import getText
3133
from lib.core.data import conf
3234
from lib.core.data import kb
3335
from lib.core.data import logger
@@ -555,22 +557,22 @@ def _controlMsfCmd(self, proc, func):
555557
pass
556558

557559
out = recv_some(proc, t=.1, e=0)
558-
blockingWriteToFD(sys.stdout.fileno(), out)
560+
blockingWriteToFD(sys.stdout.fileno(), getBytes(out))
559561

560562
# For --os-pwn and --os-bof
561563
pwnBofCond = self.connectionStr.startswith("reverse")
562-
pwnBofCond &= any(_ in out for _ in ("Starting the payload handler", "Started reverse"))
564+
pwnBofCond &= any(_ in out for _ in (b"Starting the payload handler", b"Started reverse"))
563565

564566
# For --os-smbrelay
565-
smbRelayCond = "Server started" in out
567+
smbRelayCond = b"Server started" in out
566568

567569
if pwnBofCond or smbRelayCond:
568570
func()
569571

570572
timeout = time.time() - start_time > METASPLOIT_SESSION_TIMEOUT
571573

572574
if not initialized:
573-
match = re.search(r"Meterpreter session ([\d]+) opened", out)
575+
match = re.search(b"Meterpreter session ([\d]+) opened", out)
574576

575577
if match:
576578
self._loadMetExtensions(proc, match.group(1))
@@ -616,7 +618,7 @@ def createMsfShellcode(self, exitfunc, format, extra, encode):
616618
pollProcess(process)
617619
payloadStderr = process.communicate()[1]
618620

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

621623
if match:
622624
payloadSize = int(match.group(2))
@@ -627,7 +629,7 @@ def createMsfShellcode(self, exitfunc, format, extra, encode):
627629
debugMsg = "the shellcode size is %d bytes" % payloadSize
628630
logger.debug(debugMsg)
629631
else:
630-
errMsg = "failed to create the shellcode (%s)" % payloadStderr.replace("\n", " ").replace("\r", "")
632+
errMsg = "failed to create the shellcode ('%s')" % getText(payloadStderr).replace("\n", " ").replace("\r", "")
631633
raise SqlmapFilePathException(errMsg)
632634

633635
self._shellcodeFP = open(self._shellcodeFilePath, "rb")

lib/takeover/web.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ def webUpload(self, destFileName, directory, stream=None, content=None, filepath
9696
if filepath.endswith('_'):
9797
content = decloak(filepath) # cloaked file
9898
else:
99-
with open(filepath, "rb") as f:
99+
with openFile(filepath, "rb", encoding=None) as f:
100100
content = f.read()
101101

102102
if content is not None:
103-
stream = io.BytesIO(content) # string content
103+
stream = io.BytesIO(getBytes(content)) # string content
104104

105105
# Reference: https://github.com/sqlmapproject/sqlmap/issues/3560
106106
# Reference: https://stackoverflow.com/a/4677542
@@ -131,7 +131,7 @@ def _webFileStreamUpload(self, stream, destFileName, directory):
131131

132132
page, _, _ = Request.getPage(url=self.webStagerUrl, multipart=multipartParams, raise404=False)
133133

134-
if "File uploaded" not in page:
134+
if "File uploaded" not in (page or ""):
135135
warnMsg = "unable to upload the file through the web file "
136136
warnMsg += "stager to '%s'" % directory
137137
logger.warn(warnMsg)

thirdparty/multipart/multipartpost.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828

2929
from lib.core.compat import choose_boundary
3030
from lib.core.convert import getBytes
31+
from lib.core.convert import getText
3132
from lib.core.exception import SqlmapDataException
3233
from thirdparty.six.moves import urllib as _urllib
3334

34-
class Callable:
35-
def __init__(self, anycallable):
36-
self.__call__ = anycallable
37-
3835
# Controls how sequences are uncoded. If true, elements may be given
3936
# multiple values by assigning a sequence.
4037
doseq = 1
@@ -72,40 +69,38 @@ def http_request(self, request):
7269
request.data = data
7370
return request
7471

75-
def multipart_encode(vars, files, boundary=None, buf=None):
72+
def multipart_encode(self, vars, files, boundary=None, buf=None):
7673
if boundary is None:
7774
boundary = choose_boundary()
7875

7976
if buf is None:
80-
buf = ""
77+
buf = b""
8178

8279
for (key, value) in vars:
8380
if key is not None and value is not None:
84-
buf += "--%s\r\n" % boundary
85-
buf += "Content-Disposition: form-data; name=\"%s\"" % key
86-
buf += "\r\n\r\n" + value + "\r\n"
81+
buf += b"--%s\r\n" % getBytes(boundary)
82+
buf += b"Content-Disposition: form-data; name=\"%s\"" % getBytes(key)
83+
buf += b"\r\n\r\n" + getBytes(value) + b"\r\n"
8784

8885
for (key, fd) in files:
89-
file_size = os.fstat(fd.fileno())[stat.ST_SIZE] if hasattr(fd, "fileno") else fd.len
86+
file_size = fd.len if hasattr(fd, "len") else os.fstat(fd.fileno())[stat.ST_SIZE]
9087
filename = fd.name.split("/")[-1] if "/" in fd.name else fd.name.split("\\")[-1]
9188
try:
92-
contenttype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
89+
contenttype = mimetypes.guess_type(filename)[0] or b"application/octet-stream"
9390
except:
9491
# Reference: http://bugs.python.org/issue9291
95-
contenttype = "application/octet-stream"
96-
buf += "--%s\r\n" % boundary
97-
buf += "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n" % (key, filename)
98-
buf += "Content-Type: %s\r\n" % contenttype
99-
# buf += "Content-Length: %s\r\n" % file_size
92+
contenttype = b"application/octet-stream"
93+
buf += b"--%s\r\n" % getBytes(boundary)
94+
buf += b"Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n" % (getBytes(key), getBytes(filename))
95+
buf += b"Content-Type: %s\r\n" % getBytes(contenttype)
96+
# buf += b"Content-Length: %s\r\n" % file_size
10097
fd.seek(0)
10198

102-
buf = getBytes(buf)
10399
buf += b"\r\n%s\r\n" % fd.read()
104100

105-
buf += "--%s--\r\n\r\n" % boundary
101+
buf += b"--%s--\r\n\r\n" % getBytes(boundary)
102+
buf = getBytes(buf)
106103

107104
return boundary, buf
108105

109-
multipart_encode = Callable(multipart_encode)
110-
111106
https_request = http_request

0 commit comments

Comments
 (0)