Example #1
0
    def start_sniffing(self, test_details):
        """ Start sniffing with Scapy. Exits if required privileges (root) are not
        available.
        """
        from ooni.utils.txscapy import ScapySniffer, ScapyFactory

        if config.scapyFactory is None:
            config.scapyFactory = ScapyFactory(config.advanced.interface)

        # XXX this is dumb option to have in the ooniprobe.conf. Drop it in
        # the future.
        prefix = config.reports.pcap
        if prefix is None:
            prefix = 'report'

        filename_pcap = config.global_options.get('pcapfile', None)
        if filename_pcap is None:
            filename_pcap = generate_filename(test_details,
                                              prefix=prefix,
                                              extension='pcap')
        if len(self.sniffers) > 0:
            pcap_filenames = set(sniffer.pcapwriter.filename for sniffer in self.sniffers.values())
            pcap_filenames.add(filename_pcap)
            log.msg("pcap files %s can be messed up because several netTests are being executed in parallel." %
                    ','.join(pcap_filenames))

        sniffer = ScapySniffer(filename_pcap)
        self.sniffers[test_details['test_name']] = sniffer
        config.scapyFactory.registerProtocol(sniffer)
        log.msg("Starting packet capture to: %s" % filename_pcap)
Example #2
0
    def start_sniffing(self, test_details):
        """ Start sniffing with Scapy. Exits if required privileges (root) are not
        available.
        """
        from ooni.utils.txscapy import ScapySniffer, ScapyFactory

        if config.scapyFactory is None:
            config.scapyFactory = ScapyFactory(config.advanced.interface)

        # XXX this is dumb option to have in the ooniprobe.conf. Drop it in
        # the future.
        prefix = config.reports.pcap
        if prefix is None:
            prefix = 'report'

        filename_pcap = config.global_options.get('pcapfile', None)
        if filename_pcap is None:
            filename_pcap = generate_filename(test_details,
                                              prefix=prefix,
                                              extension='pcap')
        if len(self.sniffers) > 0:
            pcap_filenames = set(sniffer.pcapwriter.filename
                                 for sniffer in self.sniffers.values())
            pcap_filenames.add(filename_pcap)
            log.msg(
                "pcap files %s can be messed up because several netTests are being executed in parallel."
                % ','.join(pcap_filenames))

        sniffer = ScapySniffer(filename_pcap)
        self.sniffers[test_details['test_name']] = sniffer
        config.scapyFactory.registerProtocol(sniffer)
        log.msg("Starting packet capture to: %s" % filename_pcap)
Example #3
0
    def startSniffing(self, testDetails):
        """ Start sniffing with Scapy. Exits if required privileges (root) are not
        available.
        """
        from ooni.utils.txscapy import ScapySniffer, ScapyFactory

        if config.scapyFactory is None:
            config.scapyFactory = ScapyFactory(config.advanced.interface)

        if not config.reports.pcap:
            prefix = 'report'
        else:
            prefix = config.reports.pcap
        filename = config.global_options['reportfile'] if 'reportfile' in config.global_options.keys() else None
        filename_pcap = generate_filename(testDetails, filename=filename, prefix=prefix, extension='pcap')
        if len(self.sniffers) > 0:
            pcap_filenames = set(sniffer.pcapwriter.filename for sniffer in self.sniffers.values())
            pcap_filenames.add(filename_pcap)
            log.msg("pcap files %s can be messed up because several netTests are being executed in parallel." %
                    ','.join(pcap_filenames))

        sniffer = ScapySniffer(filename_pcap)
        self.sniffers[testDetails['test_name']] = sniffer
        config.scapyFactory.registerProtocol(sniffer)
        log.msg("Starting packet capture to: %s" % filename_pcap)
Example #4
0
    def startSniffing(self, testDetails):
        """ Start sniffing with Scapy. Exits if required privileges (root) are not
        available.
        """
        from ooni.utils.txscapy import ScapySniffer, ScapyFactory

        if config.scapyFactory is None:
            config.scapyFactory = ScapyFactory(config.advanced.interface)

        if not config.reports.pcap:
            prefix = 'report'
        else:
            prefix = config.reports.pcap
        filename = config.global_options[
            'reportfile'] if 'reportfile' in config.global_options.keys(
            ) else None
        filename_pcap = generate_filename(testDetails,
                                          filename=filename,
                                          prefix=prefix,
                                          extension='pcap')
        if len(self.sniffers) > 0:
            pcap_filenames = set(sniffer.pcapwriter.filename
                                 for sniffer in self.sniffers.values())
            pcap_filenames.add(filename_pcap)
            log.msg(
                "pcap files %s can be messed up because several netTests are being executed in parallel."
                % ','.join(pcap_filenames))

        sniffer = ScapySniffer(filename_pcap)
        self.sniffers[testDetails['test_name']] = sniffer
        config.scapyFactory.registerProtocol(sniffer)
        log.msg("Starting packet capture to: %s" % filename_pcap)
Example #5
0
    def __init__(self, test_details, report_destination='.', report_filename=None):
        self.reportDestination = report_destination

        if not os.path.isdir(report_destination):
            raise errors.InvalidDestination

        report_filename = generate_filename(test_details, filename=report_filename, prefix='report', extension='yamloo')

        report_path = os.path.join(self.reportDestination, report_filename)

        if os.path.exists(report_path):
            log.msg("Report already exists with filename %s" % report_path)
            pushFilenameStack(report_path)

        self.report_path = os.path.abspath(report_path)
        OReporter.__init__(self, test_details)
Example #6
0
    def __init__(self, test_details, report_destination='.', report_filename=None):
        self.reportDestination = report_destination

        if not os.path.isdir(report_destination):
            raise errors.InvalidDestination

        report_filename = generate_filename(test_details, filename=report_filename, prefix='report', extension='yamloo')

        report_path = os.path.join(self.reportDestination, report_filename)

        if os.path.exists(report_path):
            log.msg("Report already exists with filename %s" % report_path)
            pushFilenameStack(report_path)

        self.report_path = os.path.abspath(report_path)
        OReporter.__init__(self, test_details)
Example #7
0
def random_measurement_name(start_date=None, end_date=None):
    # By default we use as start date something in the past 6 days and end
    # date today.
    if start_date is None:
        start_date = datetime.now() - timedelta(days=6)
    if end_date is None:
        end_date = datetime.now()

    test_details = dict(
        test_name=random.choice([
            'http_invalid_request_line', 'web_connectivity',
            'http_header_field_manipulation', 'vanilla_tor', 'new_test_name'
        ]),
        probe_cc=randomSTR(2, num=False),  # XXX this should be a valid CC
        probe_asn='AS' + str(random.randint(0, 2**16)),
        test_start_time=randomDate(start_date, end_date).strftime(LONG_DATE))
    return generate_filename(test_details)
def random_measurement_name(start_date=None, end_date=None):
    # By default we use as start date something in the past 6 days and end
    # date today.
    if start_date is None:
        start_date = datetime.now() - timedelta(days=6)
    if end_date is None:
        end_date = datetime.now()

    test_details = dict(
        test_name=random.choice(['http_invalid_request_line',
                                 'web_connectivity',
                                 'http_header_field_manipulation',
                                 'vanilla_tor',
                                 'new_test_name']),
        probe_cc=randomSTR(2, num=False), # XXX this should be a valid CC
        probe_asn='AS'+str(random.randint(0, 2**16)),
        test_start_time=randomDate(start_date, end_date).strftime(LONG_DATE)
    )
    return generate_filename(test_details)
Example #9
0
    def _run_ooni_task(self, task, director):
        net_test_loader = task.ooni["net_test_loader"]
        # XXX-REFACTOR we do this so late to avoid the collision between the
        #  same id and hence generating the same filename.
        test_details = net_test_loader.getTestDetails()
        task.id = generate_filename(test_details)

        measurement_id = None
        report_filename = task.output_path
        if not task.output_path:
            measurement_id = task.id

            measurement_dir = self._measurement_path.child(measurement_id)
            try:
                measurement_dir.createDirectory()
            except OSError as ose:
                if ose.errno == errno.EEXIST:
                    raise Exception("Directory already exists, there is a "
                                    "collision")

            report_filename = measurement_dir.child("measurements.njson.progress").path
            pid_file = measurement_dir.child("running.pid")

            with pid_file.open('w') as out_file:
                out_file.write("{0}".format(os.getpid()))

        d = director.start_net_test_loader(
            net_test_loader,
            report_filename,
            collector_client=net_test_loader.collector,
            test_details=test_details,
            measurement_id=measurement_id
        )
        d.addCallback(self._measurement_completed, task)
        d.addErrback(self._measurement_failed, task)
        return d
Example #10
0
 def test_generate_filename_with_filename(self):
     filename = generate_filename(self.test_details, filename=self.filename)
     self.assertEqual(filename, 'filename.txe')
Example #11
0
 def test_generate_filename_with_extension_and_prefix(self):
     filename = generate_filename(self.test_details,
                                  prefix=self.prefix,
                                  extension=self.extension)
     self.assertEqual(filename, 'prefix-foo-2016-01-01T012222Z.ext')
Example #12
0
 def test_generate_filename_with_prefix(self):
     filename = generate_filename(self.test_details, prefix=self.prefix)
     self.assertEqual(filename, 'prefix-foo-2016-01-01T012222Z')
Example #13
0
 def test_generate_filename_with_extension(self):
     filename = generate_filename(self.test_details,
                                  extension=self.extension)
     self.assertEqual(filename, 'foo-2016-01-01T012222Z.ext')
Example #14
0
 def test_generate_filename(self):
     filename = generate_filename(self.test_details)
     self.assertEqual(filename, 'foo-2016-01-01T012222Z')
Example #15
0
 def test_generate_filename_with_prefix(self):
     filename = generate_filename(self.test_details, prefix=self.prefix)
     self.assertEqual(filename, "prefix-20160101T012222Z-ZZ-AS0-foo")
Example #16
0
 def test_generate_filename_with_prefix(self):
     filename = generate_filename(self.test_details, prefix=self.prefix)
     self.assertEqual(filename, 'prefix-foo-2016-01-01T012222Z')
Example #17
0
 def test_generate_filename(self):
     filename = generate_filename(self.test_details)
     self.assertEqual(filename, 'foo-2016-01-01T012222Z')
Example #18
0
 def test_generate_filename(self):
     filename = generate_filename(self.test_details)
     self.assertEqual(filename, '20160101T012222Z-ZZ-AS0-foo')
Example #19
0
 def test_generate_filename(self):
     filename = generate_filename(self.test_details)
     self.assertEqual(filename, 'foo-1970-01-01T000001Z')
Example #20
0
 def test_generate_filename_with_extension(self):
     filename = generate_filename(self.test_details, extension=self.extension)
     self.assertEqual(filename, "20160101T012222Z-ZZ-AS0-foo.ext")
Example #21
0
 def test_generate_filename(self):
     filename = generate_filename(self.test_details)
     self.assertEqual(filename, 'foo-1984-01-01T000000Z')
Example #22
0
 def test_generate_filename_with_extension_and_basename(self):
     filename = generate_filename(self.test_details,
                                  extension=self.extension,
                                  filename=self.basename)
     self.assertEqual(filename, 'filename.ext')
Example #23
0
 def test_generate_filename(self):
     filename = generate_filename(self.test_details)
     self.assertEqual(filename, "20160101T012222Z-ZZ-AS0-foo")
Example #24
0
 def generateReportFilename(self):
     report_filename = generate_filename(self.test_details,
                                         prefix='report',
                                         extension='yamloo')
     report_path = os.path.join('.', report_filename)
     return os.path.abspath(report_path)
Example #25
0
 def test_generate_filename_with_extension(self):
     filename = generate_filename(self.test_details, extension=self.extension)
     self.assertEqual(filename, '20160101T012222Z-ZZ-AS0-foo.ext')
Example #26
0
 def test_generate_filename_with_extension_and_prefix(self):
     filename = generate_filename(self.test_details, prefix=self.prefix, extension=self.extension)
     self.assertEqual(filename, "prefix-20160101T012222Z-ZZ-AS0-foo.ext")
Example #27
0
 def test_generate_filename_with_extension(self):
     filename = generate_filename(self.test_details, extension=self.extension)
     self.assertEqual(filename, 'foo-2016-01-01T012222Z.ext')
Example #28
0
 def test_generate_filename_with_prefix(self):
     filename = generate_filename(self.test_details, prefix=self.prefix)
     self.assertEqual(filename, 'prefix-20160101T012222Z-ZZ-AS0-foo')
Example #29
0
 def test_generate_filename_with_extension_and_prefix(self):
     filename = generate_filename(self.test_details, prefix=self.prefix, extension=self.extension)
     self.assertEqual(filename, 'prefix-foo-2016-01-01T012222Z.ext')
Example #30
0
 def test_generate_filename_with_filename(self):
     filename = generate_filename(self.test_details, filename=self.filename)
     self.assertEqual(filename, 'filename.txe')
Example #31
0
 def generateReportFilename(self):
     report_filename = generate_filename(self.test_details,
                                         prefix='report',
                                         extension='njson')
     report_path = os.path.join('.', report_filename)
     return os.path.abspath(report_path)
Example #32
0
 def test_generate_filename_with_extension_and_basename(self):
     filename = generate_filename(self.test_details, extension=self.extension, filename=self.basename)
     self.assertEqual(filename, 'filename.ext')