Exemple #1
0
 def on_received(endpoint, data, from_):
     id_ = address2uuid(*from_)
     tunnel = Delegation.get_tunnel(id_)
     if tunnel is None:
         tunnel = Tunnel(connect_to=via)
         tunnel.set_on_payload(Delegation.on_payload)
         tunnel.set_on_closed(Delegation.on_closed)
         tunnel.set_on_ready_to_send(Delegation.set_on_ready_to_send)
         tunnel.set_on_send_buffer_full(Delegation.set_on_send_buffer_full)
         tunnel.initialize()
     if Delegation.query_endpoint(id_) is None:
         tunnel.send_udp_initial_data(id_, initial_data)
         Delegation.register(id_, tunnel, endpoint)
     tunnel.send_payload(id_, data)
Exemple #2
0
    def connect_side_multiplex(tun_device, _, packet):
        if need_restore(from_addr, packet):
            restore_dst(packet)
            if packet.is_rst():
                _logger.info('%s has been reset', packet.get_source_ip())

            addr_list, id_, domain = try_parse_dns_result(packet)
            if addr_list is not None:
                if packet.get_raw_source_ip() == TEST_DNS_SERVER:
                    _logger.error('POISONED DOMAIN: %s', domain)
                    update_poisoned_domain(domain)
                    return True
                else:
                    normal_address.update(addr_list)
                    try_restore_dns(packet, id_)
            tun_device.send(packet.get_packet())
            return True

        through_tunnel, dns_query = is_through_tunnel(packet, to_addr)
        if not through_tunnel:
            if dns_query is True:
                test_domain_poisoned(tun_device, packet)
            change_src(packet)
            tun_device.send(packet.get_packet())
            return True

        id_ = address2uuid(packet.get_raw_source_ip(), packet.get_source_port())
        key = id_.int % TUNNEL_SIZE
        tunnel = None
        if key in key_to_tunnels:
            tunnel = key_to_tunnels[key]
        if tunnel is None or tunnel.is_closed():
            tunnel = Tunnel(connect_to=via)
            tunnel.set_on_payload(on_tunnel_received)
            tunnel.initialize()
            key_to_tunnels[key] = tunnel
        # if proto == 'tcp':
        #     data = data * 2
        tunnel.send_tun_initial_data(id_, packet.get_packet())
        return True
Exemple #3
0
def server_side_on_accepted(sock, _):
    tunnel = Tunnel(connection=sock)
    tunnel.initialize()