From c028fb900385b06951f2aa1354b671a1a54a2d0c Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 28 Nov 2019 13:53:47 +0100 Subject: [PATCH] Patch for websocket (with multiple recv requirement) --- lib/core/option.py | 1 + lib/core/settings.py | 5 ++++- lib/request/connect.py | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 7d11c809f..bc7e8572e 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2006,6 +2006,7 @@ def _setKnowledgeBaseAttributes(flushAll=True): kb.uChar = NULL kb.udfFail = False kb.unionDuplicates = False + kb.webSocketRecvCount = None kb.wizardMode = False kb.xpCmdshellAvailable = False diff --git a/lib/core/settings.py b/lib/core/settings.py index 6670291c9..07f78bb7d 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.3.11.112" +VERSION = "1.3.11.113" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) @@ -232,6 +232,9 @@ STDIN_PIPE_DASH = '-' # URL used in dummy runs DUMMY_URL = "http://foo/bar?id=1" +# Timeout used during initial websocket (pull) testing +WEBSOCKET_INITIAL_TIMEOUT = 3 + # The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos' PLATFORM = os.name PYVERSION = sys.version.split()[0] diff --git a/lib/request/connect.py b/lib/request/connect.py index 649fe5fc8..f8bed48a6 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -119,6 +119,7 @@ from lib.core.settings import UNENCODED_ORIGINAL_VALUE from lib.core.settings import UNICODE_ENCODING from lib.core.settings import URI_HTTP_HEADER from lib.core.settings import WARN_TIME_STDEV +from lib.core.settings import WEBSOCKET_INITIAL_TIMEOUT from lib.request.basic import decodePage from lib.request.basic import forgeHeaders from lib.request.basic import processResponse @@ -451,10 +452,25 @@ class Connect(object): if webSocket: ws = websocket.WebSocket() - ws.settimeout(timeout) + ws.settimeout(WEBSOCKET_INITIAL_TIMEOUT if kb.webSocketRecvCount is None else timeout) ws.connect(url, header=("%s: %s" % _ for _ in headers.items() if _[0] not in ("Host",)), cookie=cookie) # WebSocket will add Host field of headers automatically ws.send(urldecode(post or "")) - page = ws.recv() + + _page = [] + + if kb.webSocketRecvCount is None: + while True: + try: + _page.append(ws.recv()) + except websocket.WebSocketTimeoutException: + kb.webSocketRecvCount = len(_page) + break + else: + for i in xrange(max(1, kb.webSocketRecvCount)): + _page.append(ws.recv()) + + page = "\n".join(_page) + ws.close() code = ws.status status = _http_client.responses[code]