|
@ -160,6 +160,10 @@ class TCPRelayHandler(object): |
|
|
self._forbidden_iplist = config['forbidden_ip'] |
|
|
self._forbidden_iplist = config['forbidden_ip'] |
|
|
else: |
|
|
else: |
|
|
self._forbidden_iplist = None |
|
|
self._forbidden_iplist = None |
|
|
|
|
|
if 'forbidden_port' in config: |
|
|
|
|
|
self._forbidden_portset = config['forbidden_port'] |
|
|
|
|
|
else: |
|
|
|
|
|
self._forbidden_portset = None |
|
|
if is_local: |
|
|
if is_local: |
|
|
self._chosen_server = self._get_a_server() |
|
|
self._chosen_server = self._get_a_server() |
|
|
fd_to_handlers[local_sock.fileno()] = self |
|
|
fd_to_handlers[local_sock.fileno()] = self |
|
@ -511,10 +515,15 @@ class TCPRelayHandler(object): |
|
|
if len(addrs) == 0: |
|
|
if len(addrs) == 0: |
|
|
raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) |
|
|
raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) |
|
|
af, socktype, proto, canonname, sa = addrs[0] |
|
|
af, socktype, proto, canonname, sa = addrs[0] |
|
|
if not self._remote_udp and self._forbidden_iplist: |
|
|
if not self._remote_udp: |
|
|
if common.to_str(sa[0]) in self._forbidden_iplist: |
|
|
if self._forbidden_iplist: |
|
|
raise Exception('IP %s is in forbidden list, reject' % |
|
|
if common.to_str(sa[0]) in self._forbidden_iplist: |
|
|
common.to_str(sa[0])) |
|
|
raise Exception('IP %s is in forbidden list, reject' % |
|
|
|
|
|
common.to_str(sa[0])) |
|
|
|
|
|
if self._forbidden_portset: |
|
|
|
|
|
if sa[1] in self._forbidden_portset: |
|
|
|
|
|
raise Exception('Port %d is in forbidden list, reject' % |
|
|
|
|
|
sa[1]) |
|
|
remote_sock = socket.socket(af, socktype, proto) |
|
|
remote_sock = socket.socket(af, socktype, proto) |
|
|
self._remote_sock = remote_sock |
|
|
self._remote_sock = remote_sock |
|
|
self._fd_to_handlers[remote_sock.fileno()] = self |
|
|
self._fd_to_handlers[remote_sock.fileno()] = self |
|
@ -652,7 +661,21 @@ class TCPRelayHandler(object): |
|
|
else: |
|
|
else: |
|
|
data = obfs_decode[0] |
|
|
data = obfs_decode[0] |
|
|
try: |
|
|
try: |
|
|
data = self._protocol.server_post_decrypt(data) |
|
|
newdata = self._protocol.server_post_decrypt(data) |
|
|
|
|
|
if data and not newdata: |
|
|
|
|
|
data = self._protocol.server_pre_encrypt(data) |
|
|
|
|
|
data = self._encryptor.encrypt(data) |
|
|
|
|
|
data = self._obfs.server_encode(data) |
|
|
|
|
|
try: |
|
|
|
|
|
self._write_to_sock(data, self._local_sock) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
shell.print_exception(e) |
|
|
|
|
|
if self._config['verbose']: |
|
|
|
|
|
traceback.print_exc() |
|
|
|
|
|
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1])) |
|
|
|
|
|
self.destroy() |
|
|
|
|
|
return |
|
|
|
|
|
data = newdata |
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
shell.print_exception(e) |
|
|
shell.print_exception(e) |
|
|
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1])) |
|
|
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1])) |
|
|