Ejemplo n.º 1
0
    def new_circuit(self, circ_event):
        """
        Invoke a new probing module when a new circuit becomes ready.
        """

        self.stats.update_circs(circ_event)
        self.check_finished()

        if circ_event.status not in [CircStatus.BUILT]:
            return

        last_hop = circ_event.path[-1]
        exit_fpr = last_hop[0]
        logger.debug("Circuit for exit relay \"%s\" is built.  "
                     "Now invoking probing module." % exit_fpr)

        # Prepare the execution environment.  In particular, a Command() object
        # to execute external tools and a decorator for the probing module we
        # are about to run.

        cmd = command.Command("doc/torsocks.conf", self.queue, circ_event.id,
                              self.origsock)
        func = decorator(self.queue, self.origsock, self.probing_module,
                         circ_event.id, exit_fpr, cmd)

        # Monkey-patch the socket API to redirect network traffic originating
        # from our Python process to Tor's SOCKS port.

        socket.socket = mysocks.socksocket
        mysocks.setqueue(self.queue, circ_event.id)

        proc = multiprocessing.Process(target=func)
        proc.daemon = True
        proc.start()
Ejemplo n.º 2
0
def probe( exitFpr, queue, circID ):

    logger.info("I'm the module which is probing exit relay \"%s\"." % exitFpr)

    mysocks.setdefaultproxy(mysocks.PROXY_TYPE_SOCKS5, "127.0.0.1", 10000)
    mysocks.setqueue(queue, circID)
    socket.socket = mysocks.socksocket

    data = None
    try:
        data = urllib2.urlopen("https://check.torproject.org",
                               timeout=10).read()
    except urllib2.URLError as err:
        logger.error("urllib2.urlopen says: %s" % err)

    if not data:
        return

    identifier = "Congratulations. This browser is configured to use Tor."
    if not (identifier in data):
        logger.error("Detected false negative for \"%s\".  " \
                     "Full dump below." % exitFpr)
        logger.error(data)
    else:
        logger.info("Exit relay \"%s\" passed the check test." % exitFpr)
Ejemplo n.º 3
0
    def new_circuit(self, circ_event):
        """
        Invoke a new probing module when a new circuit becomes ready.
        """

        self.stats.update_circs(circ_event)
        self.check_finished()

        if circ_event.status not in [CircStatus.BUILT]:
            return

        last_hop = circ_event.path[-1]
        exit_fpr = last_hop[0]
        logger.debug("Circuit for exit relay \"%s\" is built.  "
                     "Now invoking probing module." % exit_fpr)

        # Prepare the execution environment.  In particular, a Command() object
        # to execute external tools and a decorator for the probing module we
        # are about to run.

        cmd = command.Command(self.torsocks_conf, self.queue, circ_event.id,
                              self.origsock)
        func = decorator(self.queue, self.origsock, self.module.probe,
                         circ_event.id, exit_fpr, cmd)

        # Monkey-patch the socket API to redirect network traffic originating
        # from our Python process to Tor's SOCKS port.

        socket.socket = mysocks.socksocket
        mysocks.setqueue(self.queue, circ_event.id)

        proc = multiprocessing.Process(target=func)
        proc.daemon = True
        proc.start()
Ejemplo n.º 4
0
    def new_circuit(self, circ_event):
        """
        Invoke a new probing module when a new circuit becomes ready.
        """

        if circ_event.status not in self.our_circuit_events:
            return

        # Keep track of how many circuits are already finished.

        if circ_event.status in [CircStatus.FAILED, CircStatus.CLOSED]:
            logger.debug("Circuit closed because: %s" % str(circ_event.reason))
            self.stats.failed_circuits += 1
            return

        self.stats.successful_circuits += 1
        self.stats.print_progress()
        exit_fpr = circ_event.path[-1][0]
        logger.debug("Circuit for exit relay \"%s\" is built.  "
                     "Now invoking probing module." % exit_fpr)

        cmd = command.Command("/tmp/torsocks.conf", self.queue, circ_event.id,
                              self.origsock)
        socket.socket = mysocks.socksocket
        mysocks.setqueue(self.queue, circ_event.id)

        # Invoke the module in a dedicated process.
        proc = multiprocessing.Process(target=self.probing_module,
                                       args=(exit_fpr, cmd,))
        proc.start()