mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2026-11-20 15:10:23 +00:00
Keep WebSocket responses on normal closure (#6173)
Co-authored-by: cuteNBD <206630735+bingdongni@users.noreply.github.com>
This commit is contained in:
parent
74f50122fb
commit
b333a14d8b
3 changed files with 136 additions and 4 deletions
|
|
@ -619,17 +619,17 @@ class Connect(object):
|
|||
warnMsg = "too large websocket response detected. Automatically trimming it"
|
||||
singleTimeWarnMessage(warnMsg)
|
||||
break
|
||||
except websocket.WebSocketTimeoutException:
|
||||
except (websocket.WebSocketTimeoutException, websocket.WebSocketNormalClosureException):
|
||||
kb.webSocketRecvCount = len(_page)
|
||||
break
|
||||
else:
|
||||
for i in xrange(max(1, kb.webSocketRecvCount)):
|
||||
# Note: a later response may carry fewer frames than the calibration one
|
||||
# (e.g. a FALSE boolean-blind reply); stop on timeout instead of letting it
|
||||
# bubble up as a failed request, mirroring the initial recv loop above
|
||||
# (e.g. a FALSE boolean-blind reply); stop on timeout or normal closure,
|
||||
# mirroring the initial recv loop above
|
||||
try:
|
||||
_page.append(ws.recv())
|
||||
except websocket.WebSocketTimeoutException:
|
||||
except (websocket.WebSocketTimeoutException, websocket.WebSocketNormalClosureException):
|
||||
break
|
||||
|
||||
page = "\n".join(_page)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ class WebSocketTimeoutException(WebSocketException):
|
|||
class WebSocketConnectionClosedException(WebSocketException):
|
||||
pass
|
||||
|
||||
class WebSocketNormalClosureException(WebSocketConnectionClosedException):
|
||||
pass
|
||||
|
||||
class WebSocket(object):
|
||||
"""
|
||||
Minimal RFC 6455 client exposing the websocket-client subset used by sqlmap: settimeout(), connect(),
|
||||
|
|
@ -159,10 +162,14 @@ class WebSocket(object):
|
|||
|
||||
def recv(self):
|
||||
data = bytearray()
|
||||
receivedFragment = False
|
||||
while True:
|
||||
fin, opcode, payload = self._recvFrame()
|
||||
if opcode == OPCODE_CLOSE:
|
||||
self._closed = True
|
||||
normal = not payload or (len(payload) >= 2 and struct.unpack("!H", bytes(payload[:2]))[0] in (1000, 1001))
|
||||
if normal and not receivedFragment:
|
||||
raise WebSocketNormalClosureException("WebSocket connection closed")
|
||||
raise WebSocketConnectionClosedException("WebSocket connection closed")
|
||||
elif opcode == OPCODE_PING:
|
||||
self._sendFrame(bytes(payload), OPCODE_PONG)
|
||||
|
|
@ -171,6 +178,7 @@ class WebSocket(object):
|
|||
continue
|
||||
|
||||
data += payload
|
||||
receivedFragment = True
|
||||
if fin:
|
||||
break
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue