Browse Source

log TCP header if parse error

dev
breakwa11 9 years ago
parent
commit
56af51b43c
  1. 10
      shadowsocks/tcprelay.py

10
shadowsocks/tcprelay.py

@ -319,7 +319,7 @@ class TCPRelayHandler(object):
traceback.print_exc() traceback.print_exc()
self.destroy() self.destroy()
def _handle_stage_addr(self, data): def _handle_stage_addr(self, ogn_data, data):
try: try:
if self._is_local: if self._is_local:
cmd = common.ord(data[1]) cmd = common.ord(data[1])
@ -345,13 +345,18 @@ class TCPRelayHandler(object):
logging.error('unknown command %d', cmd) logging.error('unknown command %d', cmd)
self.destroy() self.destroy()
return return
before_parse_data = data
if FORCE_NEW_PROTOCOL and ord(data[0]) != 0x88: if FORCE_NEW_PROTOCOL and ord(data[0]) != 0x88:
logging.warn("TCP data %s decrypt %s" % (binascii.hexlify(ogn_data), binascii.hexlify(before_parse_data)))
raise Exception('can not parse header') raise Exception('can not parse header')
data = pre_parse_header(data) data = pre_parse_header(data)
if data is None: if data is None:
logging.warn("TCP data %s decrypt %s" % (binascii.hexlify(ogn_data), binascii.hexlify(before_parse_data)))
raise Exception('can not parse header') raise Exception('can not parse header')
header_result = parse_header(data) header_result = parse_header(data)
if header_result is None: if header_result is None:
logging.warn("TCP data %s decrypt %s" % (binascii.hexlify(ogn_data), binascii.hexlify(before_parse_data)))
raise Exception('can not parse header') raise Exception('can not parse header')
connecttype, remote_addr, remote_port, header_length = header_result connecttype, remote_addr, remote_port, header_length = header_result
logging.info('%s connecting %s:%d from %s:%d' % logging.info('%s connecting %s:%d from %s:%d' %
@ -497,6 +502,7 @@ class TCPRelayHandler(object):
if not data: if not data:
self.destroy() self.destroy()
return return
ogn_data = data
self._update_activity(len(data)) self._update_activity(len(data))
if not is_local: if not is_local:
data = self._encryptor.decrypt(data) data = self._encryptor.decrypt(data)
@ -517,7 +523,7 @@ class TCPRelayHandler(object):
self._handle_stage_connecting(data) self._handle_stage_connecting(data)
elif (is_local and self._stage == STAGE_ADDR) or \ elif (is_local and self._stage == STAGE_ADDR) or \
(not is_local and self._stage == STAGE_INIT): (not is_local and self._stage == STAGE_INIT):
self._handle_stage_addr(data) self._handle_stage_addr(ogn_data, data)
def _on_remote_read(self, is_remote_sock): def _on_remote_read(self, is_remote_sock):
# handle all remote read events # handle all remote read events

Loading…
Cancel
Save