|
|
@ -160,6 +160,10 @@ class TCPRelayHandler(object): |
|
|
|
self._forbidden_iplist = config['forbidden_ip'] |
|
|
|
else: |
|
|
|
self._forbidden_iplist = None |
|
|
|
if 'forbidden_port' in config: |
|
|
|
self._forbidden_portset = config['forbidden_port'] |
|
|
|
else: |
|
|
|
self._forbidden_portset = None |
|
|
|
if is_local: |
|
|
|
self._chosen_server = self._get_a_server() |
|
|
|
fd_to_handlers[local_sock.fileno()] = self |
|
|
@ -511,10 +515,15 @@ class TCPRelayHandler(object): |
|
|
|
if len(addrs) == 0: |
|
|
|
raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) |
|
|
|
af, socktype, proto, canonname, sa = addrs[0] |
|
|
|
if not self._remote_udp and self._forbidden_iplist: |
|
|
|
if not self._remote_udp: |
|
|
|
if self._forbidden_iplist: |
|
|
|
if common.to_str(sa[0]) in self._forbidden_iplist: |
|
|
|
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) |
|
|
|
self._remote_sock = remote_sock |
|
|
|
self._fd_to_handlers[remote_sock.fileno()] = self |
|
|
@ -652,7 +661,21 @@ class TCPRelayHandler(object): |
|
|
|
else: |
|
|
|
data = obfs_decode[0] |
|
|
|
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: |
|
|
|
shell.print_exception(e) |
|
|
|
logging.error("exception from %s:%d" % (self._client_address[0], self._client_address[1])) |
|
|
|