Exemplo n.º 1
0
    def startSniffing(self):
        """ Start sniffing with Scapy. Exits if required privileges (root) are not
        available.
        """
        from ooni.utils.txscapy import ScapyFactory, ScapySniffer
        try:
            checkForRoot()
        except errors.InsufficientPrivileges:
            print "[!] Includepcap options requires root priviledges to run"
            print "    you should run ooniprobe as root or disable the options in ooniprobe.conf"
            reactor.stop()
            sys.exit(1)

        print "Starting sniffer"
        config.scapyFactory = ScapyFactory(config.advanced.interface)

        if os.path.exists(config.reports.pcap):
            print "Report PCAP already exists with filename %s" % config.reports.pcap
            print "Renaming files with such name..."
            pushFilenameStack(config.reports.pcap)

        if self.sniffer:
            config.scapyFactory.unRegisterProtocol(self.sniffer)
        self.sniffer = ScapySniffer(config.reports.pcap)
        config.scapyFactory.registerProtocol(self.sniffer)
Exemplo n.º 2
0
    def test_pushFilenameStack(self):
        f = open("dummyfile", "w+")
        f.write("0\n")
        f.close()
        for i in xrange(1, 5):
            f = open("dummyfile.%s" % i, "w+")
            f.write("%s\n" % i)
            f.close()

        pushFilenameStack("dummyfile")
        for i in xrange(1, 5):
            f = open("dummyfile.%s" % i)
            c = f.readlines()[0].strip()
            self.assertEqual(str(i-1), str(c))
            f.close()
Exemplo n.º 3
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)
Exemplo n.º 4
0
    def test_pushFilenameStack(self):
        basefilename = os.path.join(os.getcwd(), 'dummyfile')
        f = open(basefilename, "w+")
        f.write("0\n")
        f.close()
        for i in xrange(1, 20):
            f = open(basefilename+".%s" % i, "w+")
            f.write("%s\n" % i)
            f.close()

        pushFilenameStack(basefilename)
        for i in xrange(1, 20):
            f = open(basefilename+".%s" % i)
            c = f.readlines()[0].strip()
            self.assertEqual(str(i-1), str(c))
            f.close()
Exemplo n.º 5
0
    def startSniffing(self):
        """ Start sniffing with Scapy. Exits if required privileges (root) are not
        available.
        """
        from ooni.utils.txscapy import ScapyFactory, ScapySniffer
        config.scapyFactory = ScapyFactory(config.advanced.interface)

        if os.path.exists(config.reports.pcap):
            log.msg("Report PCAP already exists with filename %s" % config.reports.pcap)
            log.msg("Renaming files with such name...")
            pushFilenameStack(config.reports.pcap)

        if self.sniffer:
            config.scapyFactory.unRegisterProtocol(self.sniffer)
        self.sniffer = ScapySniffer(config.reports.pcap)
        config.scapyFactory.registerProtocol(self.sniffer)
        log.msg("Starting packet capture to: %s" % config.reports.pcap)
Exemplo n.º 6
0
    def __init__(self, test_details, report_destination='.'):
        self.reportDestination = report_destination

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

        report_filename = "report-" + \
                test_details['test_name'] + "-" + \
                otime.timestamp() + ".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 = report_path
        OReporter.__init__(self, test_details)
Exemplo n.º 7
0
    def __init__(self, cmd_line_options):
        if cmd_line_options['reportfile'] is None:
            try:
                test_filename = os.path.basename(cmd_line_options['test'])
            except IndexError:
                raise TestFilenameNotSet

            test_name = '.'.join(test_filename.split(".")[:-1])
            frm_str = "report_%s_"+otime.timestamp()+".%s"
            reportfile = frm_str % (test_name, "yamloo")
        else:
            reportfile = cmd_line_options['reportfile']

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

        log.debug("Creating %s" % reportfile)
        self._stream = open(reportfile, 'w+')
        OReporter.__init__(self, cmd_line_options)