Skip to content

Commit c028fb9

Browse files
committed
Patch for websocket (with multiple recv requirement)
1 parent 1bfb9ef commit c028fb9

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
20062006
kb.uChar = NULL
20072007
kb.udfFail = False
20082008
kb.unionDuplicates = False
2009+
kb.webSocketRecvCount = None
20092010
kb.wizardMode = False
20102011
kb.xpCmdshellAvailable = False
20112012

lib/core/settings.py

Lines changed: 4 additions & 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.3.11.112"
21+
VERSION = "1.3.11.113"
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)
@@ -232,6 +232,9 @@
232232
# URL used in dummy runs
233233
DUMMY_URL = "http://foo/bar?id=1"
234234

235+
# Timeout used during initial websocket (pull) testing
236+
WEBSOCKET_INITIAL_TIMEOUT = 3
237+
235238
# The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'
236239
PLATFORM = os.name
237240
PYVERSION = sys.version.split()[0]

lib/request/connect.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class WebSocketException(Exception):
119119
from lib.core.settings import UNICODE_ENCODING
120120
from lib.core.settings import URI_HTTP_HEADER
121121
from lib.core.settings import WARN_TIME_STDEV
122+
from lib.core.settings import WEBSOCKET_INITIAL_TIMEOUT
122123
from lib.request.basic import decodePage
123124
from lib.request.basic import forgeHeaders
124125
from lib.request.basic import processResponse
@@ -451,10 +452,25 @@ def getPage(**kwargs):
451452

452453
if webSocket:
453454
ws = websocket.WebSocket()
454-
ws.settimeout(timeout)
455+
ws.settimeout(WEBSOCKET_INITIAL_TIMEOUT if kb.webSocketRecvCount is None else timeout)
455456
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
456457
ws.send(urldecode(post or ""))
457-
page = ws.recv()
458+
459+
_page = []
460+
461+
if kb.webSocketRecvCount is None:
462+
while True:
463+
try:
464+
_page.append(ws.recv())
465+
except websocket.WebSocketTimeoutException:
466+
kb.webSocketRecvCount = len(_page)
467+
break
468+
else:
469+
for i in xrange(max(1, kb.webSocketRecvCount)):
470+
_page.append(ws.recv())
471+
472+
page = "\n".join(_page)
473+
458474
ws.close()
459475
code = ws.status
460476
status = _http_client.responses[code]

0 commit comments

Comments
 (0)