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

Skip to content

Commit 8c57b9c

Browse files
committed
Fixes Python3 support for --chunked (drei)
1 parent 4cf14c8 commit 8c57b9c

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

extra/vulnserver/vulnserver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ def do_POST(self):
193193
data = self.rfile.read(length)
194194
data = unquote_plus(data.decode(UNICODE_ENCODING, "ignore"))
195195
self.data = data
196+
elif self.headers.get("Transfer-encoding") == "chunked":
197+
data, line = b"", b""
198+
count = 0
199+
200+
while True:
201+
line += self.rfile.read(1)
202+
if line.endswith(b'\n'):
203+
if count % 2 == 1:
204+
current = line.rstrip(b"\r\n")
205+
if not current:
206+
break
207+
else:
208+
data += current
209+
210+
count += 1
211+
line = b""
212+
213+
self.data = data.decode(UNICODE_ENCODING, "ignore")
214+
196215
self.do_REQUEST()
197216

198217
def log_message(self, format, *args):

lib/core/patch.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
from lib.core.common import shellExec
2727
from lib.core.common import singleTimeWarnMessage
2828
from lib.core.convert import stdoutEncode
29+
from lib.core.data import conf
2930
from lib.core.option import _setHTTPHandlers
3031
from lib.core.option import setVerbosity
3132
from lib.core.settings import IS_WIN
3233
from lib.request.templates import getPageTemplate
34+
from thirdparty import six
3335
from thirdparty.six.moves import http_client as _http_client
3436

3537
def dirtyPatches():
@@ -40,6 +42,17 @@ def dirtyPatches():
4042
# accept overly long result lines (e.g. SQLi results in HTTP header responses)
4143
_http_client._MAXLINE = 1 * 1024 * 1024
4244

45+
# prevent double chunked encoding in case of sqlmap chunking (Note: Python3 does it automatically if 'Content-length' is missing)
46+
if six.PY3:
47+
if not hasattr(_http_client.HTTPConnection, "__send_output"):
48+
_http_client.HTTPConnection.__send_output = _http_client.HTTPConnection._send_output
49+
def _send_output(self, *args, **kwargs):
50+
if conf.chunked and "encode_chunked" in kwargs:
51+
kwargs["encode_chunked"] = False
52+
self.__send_output(*args, **kwargs)
53+
54+
_http_client.HTTPConnection._send_output = _send_output
55+
4356
# add support for inet_pton() on Windows OS
4457
if IS_WIN:
4558
from thirdparty.wininetpton import win_inet_pton

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.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.4.1.52"
21+
VERSION = "1.4.1.53"
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def vulnTest():
5252
("-l <log> --flush-session --keep-alive --skip-waf -v 5 --technique=U --union-from=users --banner --parse-errors", ("banner: '3.", "ORDER BY term out of range", "~xp_cmdshell", "Connection: keep-alive")),
5353
("-l <log> --offline --banner -v 5", ("banner: '3.", "~[TRAFFIC OUT]")),
5454
("-u <url> --flush-session --encoding=ascii --forms --crawl=2 --threads=2 --banner", ("total of 2 targets", "might be injectable", "Type: UNION query", "banner: '3.")),
55+
("-u <url> --flush-session --data='id=1' --banner --chunked -v 5", ("Parameter: id (POST)", "Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "banner: '3.", "Transfer-encoding: chunked")),
5556
("-u <url> --flush-session --data='{\"id\": 1}' --banner", ("might be injectable", "3 columns", "Payload: {\"id\"", "Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "banner: '3.")),
5657
("-u <url> --flush-session -H 'Foo: Bar' -H 'Sna: Fu' --data='<root><param name=\"id\" value=\"1*\"/></root>' --union-char=1 --mobile --answers='smartphone=3' --banner --smart -v 5", ("might be injectable", "Payload: <root><param name=\"id\" value=\"1", "Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "banner: '3.", "Nexus", "Sna: Fu", "Foo: Bar")),
5758
("-u <url> --flush-session --method=PUT --data='a=1&b=2&c=3&id=1' --skip-static --dump -T users --start=1 --stop=2", ("might be injectable", "Parameter: id (PUT)", "Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "2 entries")),

0 commit comments

Comments
 (0)