Beispiel #1
0
    def buildProtocol(self, addr):
        log.info("%s: New connection." % self.name)

        circuit = network.Circuit(self.transport)
        self.circuits.append(circuit)

        return SOCKSv4Protocol(circuit)
Beispiel #2
0
    def __init__(self):
        try:
            managedInfo = init(transports.transports.keys())
        except EnvException:
            log.warn("Server managed-proxy protocol failed.")
            return

        log.debug("pyptlib gave us the following data:\n'%s'",
                  pprint.pformat(managedInfo))

        for transport, transport_bindaddr in managedInfo['transports'].items():
            ok, addrport = self.launchServer(transport, transport_bindaddr,
                                             managedInfo)
            if ok:
                log.debug("Successfully launched '%s' at '%s'" %
                          (transport, str(addrport)))
                reportSuccess(transport, addrport, None)
            else:
                log.info("Failed to launch '%s' at '%s'" %
                         (transport, str(addrport)))
                reportFailure(transport, 'Failed to launch')

        reportEnd()

        log.info("Starting up the event loop.")
        reactor.run()
Beispiel #3
0
    def __init__(self):
        try:
            managedInfo = init(transports.transports.keys())
        except EnvException:
            log.warn("Client managed-proxy protocol failed.")
            return

        log.debug("pyptlib gave us the following data:\n'%s'",
                  pprint.pformat(managedInfo))

        for transport in managedInfo['transports']:
            ok, addrport = self.launchClient(
                transport, managedInfo)  # XXX start using exceptions
            if ok:
                log.debug("Successfully launched '%s' at '%s'" %
                          (transport, str(addrport)))
                reportSuccess(transport, 4, addrport, None,
                              None)  # XXX SOCKS v4 hardcoded
            else:
                log.info("Failed to launch '%s'" % transport)
                reportFailure(transport, 'Failed to launch')

        reportEnd()

        log.info("Starting up the event loop.")
        reactor.run()
Beispiel #4
0
    def buildProtocol(self, addr):
        log.info("%s: New connection." % self.name)

        circuit = Circuit(self.transport)

        # XXX instantiates a new factory for each client
        clientFactory = StaticDestinationClientFactory(circuit, self.mode)
        reactor.connectTCP(self.remote_host, self.remote_port, clientFactory)

        return StaticDestinationProtocol(circuit, self.mode)
Beispiel #5
0
    def buildProtocol(self, addr):
        log.info("%s: New connection." % self.name)

        circuit = Circuit(self.transport)

        # XXX instantiates a new factory for each client
        clientFactory = StaticDestinationClientFactory(circuit, self.mode)
        reactor.connectTCP(self.remote_host, self.remote_port, clientFactory)

        return StaticDestinationProtocol(circuit, self.mode)
Beispiel #6
0
    def close(self):
        """
        Tear down the circuit.
        """
        if self.closed: return # NOP if already closed

        log.info("%s: Tearing down circuit." % self.name)

        if self.downstream: self.downstream.close()
        if self.upstream: self.upstream.close()
        self.closed = True

        self.transport.circuitDestroyed(self)
Beispiel #7
0
    def close(self):
        """
        Tear down the circuit.
        """
        if self.closed: return  # NOP if already closed

        log.info("%s: Tearing down circuit." % self.name)

        if self.downstream: self.downstream.close()
        if self.upstream: self.upstream.close()
        self.closed = True

        self.transport.circuitDestroyed(self)
Beispiel #8
0
    def __init__(self):
        try:
            managedInfo = init(transports.transports.keys())
        except EnvException:
            log.warn("Server managed-proxy protocol failed.")
            return

        log.debug("pyptlib gave us the following data:\n'%s'", pprint.pformat(managedInfo))

        for transport, transport_bindaddr in managedInfo['transports'].items():
            ok, addrport = self.launchServer(transport, transport_bindaddr, managedInfo)
            if ok:
                log.debug("Successfully launched '%s' at '%s'" % (transport, str(addrport)))
                reportSuccess(transport, addrport, None)
            else:
                log.info("Failed to launch '%s' at '%s'" % (transport, str(addrport)))
                reportFailure(transport, 'Failed to launch')

        reportEnd()

        log.info("Starting up the event loop.")
        reactor.run()
Beispiel #9
0
    def __init__(self):
        try:
            managedInfo = init(transports.transports.keys())
        except EnvException:
            log.warn("Client managed-proxy protocol failed.")
            return

        log.debug("pyptlib gave us the following data:\n'%s'", pprint.pformat(managedInfo))

        for transport in managedInfo['transports']:
            ok, addrport = self.launchClient(transport, managedInfo) # XXX start using exceptions
            if ok:
                log.debug("Successfully launched '%s' at '%s'" % (transport, str(addrport)))
                reportSuccess(transport, 4, addrport, None, None) # XXX SOCKS v4 hardcoded
            else:
                log.info("Failed to launch '%s'" % transport)
                reportFailure(transport, 'Failed to launch')

        reportEnd()

        log.info("Starting up the event loop.")
        reactor.run()
Beispiel #10
0
    def dataReceived(self, data):
        """
        We received some data from the network. See if we have a
        complete circuit, and pass the data to it they get proxied.

        XXX: Can also be called with empty 'data' because of
        Circuit.setDownstreamConnection(). Document or split function.
        """
        if (not self.buffer) and (not data):
            log.info("%s: dataReceived called without a reason.", self.name)
            return

        log.debug("%s: Received %d bytes (and %d cached):\n%s" \
                  % (self.name, len(data), len(self.buffer), str(data)))

        # Circuit is not fully connected yet, cache what we got.
        if not self.circuit.circuitIsReady():
            log.debug("%s: Caching them %d bytes." % (self.name, len(data)))
            self.buffer += data
            return

        # Send received and buffered data to the circuit. Buffer the
        # data that the transport could not use.
        self.buffer = self.circuit.dataReceived(self.buffer + data, self)
Beispiel #11
0
    def dataReceived(self, data):
        """
        We received some data from the network. See if we have a
        complete circuit, and pass the data to it they get proxied.

        XXX: Can also be called with empty 'data' because of
        Circuit.setDownstreamConnection(). Document or split function.
        """
        if (not self.buffer) and (not data):
            log.info("%s: dataReceived called without a reason.", self.name)
            return

        log.debug("%s: Received %d bytes (and %d cached):\n%s" \
                  % (self.name, len(data), len(self.buffer), str(data)))

        # Circuit is not fully connected yet, cache what we got.
        if not self.circuit.circuitIsReady():
            log.debug("%s: Caching them %d bytes." % (self.name, len(data)))
            self.buffer += data
            return

        # Send received and buffered data to the circuit. Buffer the
        # data that the transport could not use.
        self.buffer = self.circuit.dataReceived(self.buffer + data, self)
Beispiel #12
0
    def connectionMade(self):
        """
        Callback for when a connection is successfully established.

        Find the connection's direction in the circuit, and register
        it in our circuit.
        """

        # Initialize the buffer for this connection:
        self.buffer = ''

        # Find the connection's direction and register it in the circuit.
        if self.mode == 'client' and not self.circuit.upstream:
            log.info("%s: connectionMade (client): " \
                     "Setting it as upstream on our circuit." % self.name)

            self.circuit.setUpstreamConnection(self)
            self.direction = 'upstream'
        elif self.mode == 'client':
            log.info("%s: connectionMade (client): " \
                     "Setting it as downstream on our circuit." % self.name)

            self.circuit.setDownstreamConnection(self)
            self.direction = 'downstream'
        elif self.mode == 'server' and not self.circuit.downstream:
            log.info("%s: connectionMade (server): " \
                     "Setting it as downstream on our circuit." % self.name)

            self.circuit.setDownstreamConnection(self)
            self.direction = 'downstream'
        elif self.mode == 'server':
            log.info("%s: connectionMade (server): " \
                     "Setting it as upstream on our circuit." % self.name)

            self.circuit.setUpstreamConnection(self)
            self.direction = 'upstream'
Beispiel #13
0
    def connectionMade(self):
        """
        Callback for when a connection is successfully established.

        Find the connection's direction in the circuit, and register
        it in our circuit.
        """

        # Initialize the buffer for this connection:
        self.buffer = ''

        # Find the connection's direction and register it in the circuit.
        if self.mode == 'client' and not self.circuit.upstream:
            log.info("%s: connectionMade (client): " \
                     "Setting it as upstream on our circuit." % self.name)

            self.circuit.setUpstreamConnection(self)
            self.direction = 'upstream'
        elif self.mode == 'client':
            log.info("%s: connectionMade (client): " \
                     "Setting it as downstream on our circuit." % self.name)

            self.circuit.setDownstreamConnection(self)
            self.direction = 'downstream'
        elif self.mode == 'server' and not self.circuit.downstream:
            log.info("%s: connectionMade (server): " \
                     "Setting it as downstream on our circuit." % self.name)

            self.circuit.setDownstreamConnection(self)
            self.direction = 'downstream'
        elif self.mode == 'server':
            log.info("%s: connectionMade (server): " \
                     "Setting it as upstream on our circuit." % self.name)

            self.circuit.setUpstreamConnection(self)
            self.direction = 'upstream'
Beispiel #14
0
 def startFactory(self):
     log.info("%s: Starting up static destination server factory." %
              self.name)
Beispiel #15
0
 def connectionFailed(self, reason):
     log.info("%s: Connection failed to connect (%s)." %
              (self.name, reason.getErrorMessage()))
     self.circuit.close()
Beispiel #16
0
 def connectionLost(self, reason):
     log.info("%s: Connection was lost (%s)." %
              (self.name, reason.getErrorMessage()))
     self.circuit.close()
Beispiel #17
0
 def startFactory(self):
     log.info("%s: Starting up SOCKS server factory." % self.name)
Beispiel #18
0
 def startFactory(self):
     log.info("%s: Starting up static destination server factory." % self.name)
Beispiel #19
0
 def connectionFailed(self, reason):
     log.info("%s: Connection failed to connect (%s)." % (self.name, reason.getErrorMessage()))
     self.circuit.close()
Beispiel #20
0
 def connectionLost(self, reason):
     log.info("%s: Connection was lost (%s)." % (self.name, reason.getErrorMessage()))
     self.circuit.close()