def connectionLost(self, reason): super().connectionLost(reason) log.debug("%s - Client disconnected", self.peer_str) # callback self.on_disconnect()
def connectionLost(self, reason): if self.otherConn: self.otherConn.transport.loseConnection() log.debug("%s - Client disconnected", self.peer_str) # callback self.on_disconnect()
def connectionMade(self): peer = self.transport.getPeer() self.addr_client = peer self.peer_str = "{} {}:{}".format(peer.type, peer.host, peer.port) log.debug("%s - Client connected", self.peer_str) self._buf = MyByteArray() self.otherConn = None # callback self.on_connect()
def connectionMade(self): super().connectionMade() peer = self.transport.getPeer() self.addr_client = peer self.peer_str = "{} {}:{}".format(peer.type, peer.host, peer.port) log.debug("%s - Client connected", self.peer_str) # callback self.on_connect()
def reply(self, reply, addr_type=EnumSOCKS.ATYP_IPV4, server="127.0.0.1", port=8888, msg=None): svr_int = struct.unpack("!I", socket.inet_aton(server))[0] self.transport.write(struct.pack("!4BIH", EnumSOCKS.VERSION, reply, 0, addr_type, svr_int, port)) if reply == EnumReply.SUCCEEDED: log.debug("%s - SOCKS established", self.peer_str) self._state = EnumState.DONE # callback self.on_socks_established() else: self._die(msg)
def makeReply(self, reply, version=0, port=0, ip="0.0.0.0"): if reply == 90: log.debug("%s - SOCKS established", self.peer_str) # callback self.on_socks_established() else: # callback self.on_socks_failed() super().makeReply(reply, version, port, ip)
def sslpeek_cb(self, sni, client_socks, server_socks): # Callback of sslpeek. Start TLS context for both side if sni: log.debug("%s - SSL SNI: %s", client_socks.peer_str, sni) server_socks.transport.startTLS(self.cert_store.root_ctx()) client_socks.transport.startTLS(self.cert_store.dummy_ctx(sni)) else: raise Exception("Unknown error, expect sni") # release them back to reactor and procuder client_socks.transport.socket.setblocking(0) server_socks.transport.socket.setblocking(0) client_socks.transport.resumeProducing() server_socks.transport.resumeProducing()
def _auth_rfc1929(self): buf = self._buf if len(buf) < 2: return ver, u_len = buf.unpackN("!BB", 2) if ver != 1: self._die("Version mismatch") return if u_len == 0: self._reply_rfc1929(EnumSOCKS.AUTH_FAILED, "Invalid username length") return if u_len >= len(buf): return u_name = bytes(buf.getN(u_len)) p_len = buf.getb() if p_len > len(buf): return if p_len == 0: self._reply_rfc1929(EnumSOCKS.AUTH_FAILED, "Invalid password length") return pwd = bytes(buf.getN(p_len)) # check now if self.factory.users[u_name] == pwd: log.debug("%s - Authenticated", self.peer_str) self._reply_rfc1929(EnumSOCKS.AUTH_SUCCESS) self._state = EnumState.REQUEST else: self._reply_rfc1929(EnumSOCKS.AUTH_FAILED, "Wrong username or password") self._buf = buf