Esempio n. 1
0
def scan_vpns(directory, auth_file):
    """For each VPN, check if there are experiments and scan with it if
    necessary

    Note: the expected directory structure is
    args.directory
    -----vpns (contains the OpenVPN config files
    -----configs (contains the Centinel config files)
    -----exps (contains the experiments directories)

    """

    logging.info("Starting to run the experiments for each VPN")

    # iterate over each VPN
    vpn_dir = return_abs_path(directory, "vpns")
    conf_dir = return_abs_path(directory, "configs")
    auth_file = return_abs_path(".", auth_file)
    for filename in os.listdir(conf_dir):
        logging.info("Moving onto %s" % (filename))
        vpn_config = os.path.join(vpn_dir, filename)
        centinel_config = os.path.join(conf_dir, filename)

        # before starting the VPN, check if there are any experiments
        # to run
        config = centinel.config.Configuration()
        config.parse_config(centinel_config)
        if not centinel.backend.experiments_available(config.params):
            logging.info("No experiments available for %s" % (filename))
            continue

        logging.info("Starting VPN for %s" % (filename))
        vpn = openvpn.OpenVPN(timeout=30,
                              auth_file=auth_file,
                              config_file=vpn_config)
        vpn.start()
        if not vpn.started:
            vpn.stop()
            continue
        client = centinel.client.Client(config.params)
        client.setup_logging()
        client.run()
        centinel.backend.sync(config.params)
        vpn.stop()
Esempio n. 2
0
def scan_vpns(directory, auth_file):
    """For each VPN, check if there are experiments and scan with it if
    necessary

    Note: the expected directory structure is
    args.directory
    -----vpns (contains the OpenVPN config files
    -----configs (contains the Centinel config files)
    -----exps (contains the experiments directories)

    """

    logging.info("Starting to run the experiments for each VPN")

    # iterate over each VPN
    vpn_dir = return_abs_path(directory, "vpns")
    conf_dir = return_abs_path(directory, "configs")
    auth_file = return_abs_path(".", auth_file)
    for filename in os.listdir(conf_dir):
        logging.info("Moving onto %s" % (filename))
        vpn_config = os.path.join(vpn_dir, filename)
        centinel_config = os.path.join(conf_dir, filename)

        # before starting the VPN, check if there are any experiments
        # to run
        config = centinel.config.Configuration()
        config.parse_config(centinel_config)
        if not centinel.backend.experiments_available(config.params):
            logging.info("No experiments available for %s" % (filename))
            continue

        logging.info("Starting VPN for %s" % (filename))
        vpn = openvpn.OpenVPN(timeout=30, auth_file=auth_file,
                                       config_file=vpn_config)
        vpn.start()
        if not vpn.started:
            vpn.stop()
            continue
        client = centinel.client.Client(config.params)
        client.setup_logging()
        client.run()
        centinel.backend.sync(config.params)
        vpn.stop()
Esempio n. 3
0
def scan_vpns(directory, auth_file, exclude_list, shuffle_lists=False):
    """For each VPN, check if there are experiments and scan with it if
    necessary

    Note: the expected directory structure is
    args.directory
    -----vpns (contains the OpenVPN config files
    -----configs (contains the Centinel config files)
    -----exps (contains the experiments directories)

    """

    logging.info("Starting to run the experiments for each VPN")
    logging.warn("Excluding vantage points from: %s" % (exclude_list))

    # iterate over each VPN
    vpn_dir = return_abs_path(directory, "vpns")
    conf_dir = return_abs_path(directory, "configs")
    auth_file = return_abs_path(".", auth_file)
    conf_list = os.listdir(conf_dir)

    if shuffle_lists:
        shuffle(conf_list)

    number = 1
    total = len(conf_list)

    for filename in conf_list:
        logging.info("Moving onto (%d/%d) %s" % (number, total, filename))
        print "(%d/%d) %s" % (number, total, filename)

        number = number + 1
        vpn_config = os.path.join(vpn_dir, filename)
        centinel_config = os.path.join(conf_dir, filename)

        # before starting the VPN, check if there are any experiments
        # to run
        config = centinel.config.Configuration()
        config.parse_config(centinel_config)

        # assuming that each VPN config file has a name like:
        # [ip-address].ovpn, we can extract IP address from filename
        # and use it to geolocate and fetch experiments before connecting
        # to VPN.
        vpn_address, extension = os.path.splitext(filename)
        country = None
        try:
            meta = centinel.backend.get_meta(config.params,
                                             vpn_address)
            if 'country' in meta:
                country = meta['country']
        except Exception as exp:
            logging.error("%s: Failed to geolocate "
                          "%s: %s" % (filename, vpn_address, exp))

        if country and exclude_list and country in exclude_list:
            logging.info("%s: Skipping this server (%s)" % (filename, country))
            continue

        # try setting the VPN info (IP and country) to get appropriate
        # experiemnts and input data.
        try:
            centinel.backend.set_vpn_info(config.params, vpn_address, country)
        except Exception as exp:
            logging.error("%s: Failed to set VPN info: %s" % (filename, exp))

        logging.info("%s: Synchronizing." % (filename))
        try:
            centinel.backend.sync(config.params)
        except Exception as exp:
            logging.error("%s: Failed to sync: %s" % (filename, exp))

        if not centinel.backend.experiments_available(config.params):
            logging.info("%s: No experiments available." % (filename))
            try:
                centinel.backend.set_vpn_info(config.params, vpn_address, country)
            except Exception as exp:
                logging.error("Failed to set VPN info: %s" % (exp))
            continue

        logging.info("%s: Starting VPN." % (filename))
        vpn = openvpn.OpenVPN(timeout=30, auth_file=auth_file,
                                       config_file=vpn_config)
        vpn.start()
        if not vpn.started:
            vpn.stop()
            logging.error("%s: Failed to start VPN!" % (filename))
            continue

        logging.info("%s: Running Centinel." % (filename))
        try:
            client = centinel.client.Client(config.params)
            client.setup_logging()
            client.run()
        except Exception as exp:
            logging.error("%s: Error running Centinel: %s" % (filename, exp))

        logging.info("%s: Stopping VPN." % (filename))
        vpn.stop()

        logging.info("%s: Synchronizing." % (filename))
        try:
            centinel.backend.sync(config.params)
        except Exception as exp:
            logging.error("%s: Failed to sync: %s" % (filename, exp))

        # try setting the VPN info (IP and country) to the correct address
        # after sync is over.
        try:
            centinel.backend.set_vpn_info(config.params, vpn_address, country)
        except Exception as exp:
            logging.error("Failed to set VPN info: %s" % (exp))