modified error handle #1198

This commit is contained in:
ricterz 2015-03-24 18:21:50 +08:00
parent 78dbe080d7
commit 9b5dcbbbb2

View File

@ -367,21 +367,12 @@ class Connect(object):
post = unicodeencode(post, kb.pageEncoding) post = unicodeencode(post, kb.pageEncoding)
if is_websocket: if is_websocket:
try: ws = websocket.WebSocket()
ws = websocket.WebSocket() ws.connect(url)
ws.connect(url) ws.send(urldecode(post) if post else '')
ws.send(urldecode(post) if post else '') response = ws.recv()
response = ws.recv() ws.close()
ws.close() return response, {}, 101
return response, {}, 101
except websocket.WebSocketConnectionClosedException:
# TODO: more exception to handle
warnMsg = "connection was forcibly closed by the target URL"
logger.critical(warnMsg)
return Connect._retryProxy(**kwargs)
except Exception:
return None, None, None
elif method and method not in (HTTPMETHOD.GET, HTTPMETHOD.POST): elif method and method not in (HTTPMETHOD.GET, HTTPMETHOD.POST):
method = unicodeencode(method) method = unicodeencode(method)
@ -557,7 +548,7 @@ class Connect(object):
debugMsg = "got HTTP error code: %d (%s)" % (code, status) debugMsg = "got HTTP error code: %d (%s)" % (code, status)
logger.debug(debugMsg) logger.debug(debugMsg)
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, struct.error, ProxyError, SqlmapCompressionException), e: except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, struct.error, ProxyError, SqlmapCompressionException, websocket.WebSocketException), e:
tbMsg = traceback.format_exc() tbMsg = traceback.format_exc()
if "no host given" in tbMsg: if "no host given" in tbMsg:
@ -582,6 +573,10 @@ class Connect(object):
elif "IncompleteRead" in tbMsg: elif "IncompleteRead" in tbMsg:
warnMsg = "there was an incomplete read error while retrieving data " warnMsg = "there was an incomplete read error while retrieving data "
warnMsg += "from the target URL" warnMsg += "from the target URL"
elif "Handshake status" in tbMsg:
status = re.search("Handshake status ([\d]{3})", tbMsg)
errMsg = "websocket handshake status %s" % status.group(1) if status else 'unknown'
raise SqlmapConnectionException(errMsg)
else: else:
warnMsg = "unable to connect to the target URL" warnMsg = "unable to connect to the target URL"