예제 #1
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()
예제 #2
0
    def dataReceived(self, data):
        log.debug("%s: Received %d bytes:\n%s" \
                  % (self.name, len(data), str(data)))

        assert(self.circuit.circuitIsReady()) # XXX Is this always true?

        self.buffer = self.circuit.dataReceived(self.buffer + data, self)
예제 #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()
예제 #4
0
    def write(self, buf):
        """
        Write 'buf' to the underlying transport.
        """
        log.debug("%s: Writing %d bytes." % (self.name, len(buf)))

        self.transport.write(buf)
예제 #5
0
    def write(self, buf):
        """
        Write 'buf' to the underlying transport.
        """
        log.debug("%s: Writing %d bytes." % (self.name, len(buf)))

        self.transport.write(buf)
예제 #6
0
def do_managed_mode(): # XXX bad code
    """This function starts obfsproxy's managed-mode functionality."""

    # XXX original code caught exceptions here!!!
    if checkClientMode():
        log.debug('Entering client managed-mode.')
        ManagedClient()
    else:
        log.error('Entering server managed-mode.')
        ManagedServer()
예제 #7
0
    def close(self):
        """
        Close the connection.
        """
        if self.closed: return # NOP if already closed

        log.debug("%s: Closing connection." % self.name)

        self.transport.loseConnection()
        self.closed = True
예제 #8
0
    def close(self):
        """
        Close the connection.
        """
        if self.closed: return  # NOP if already closed

        log.debug("%s: Closing connection." % self.name)

        self.transport.loseConnection()
        self.closed = True
예제 #9
0
    def dataReceived(self, data, conn):
        """
        We received 'data' on 'conn'. Pass the data to our transport,
        and then proxy it to the other side.

        Requires both downstream and upstream connections to be set.

        Returns the bytes that were not used by the transport.
        """
        log.debug("%s: Received %d bytes." % (self.name, len(data)))

        assert (self.downstream and self.upstream)
        assert ((conn is self.downstream) or (conn is self.upstream))

        if conn is self.downstream:
            leftovers = self.transport.receivedDownstream(data, self)
        else:
            leftovers = self.transport.receivedUpstream(data, self)

        return leftovers
예제 #10
0
    def setUpstreamConnection(self, conn):
        """
        Set the upstream connection of a circuit.
        """

        log.debug("%s: Setting upstream connection (%s)." %
                  (self.name, conn.name))
        assert (not self.upstream)
        self.upstream = conn
        """We just completed the circuit.

        Do a dummy dataReceived on the initiating connection in case
        it has any buffered data that must be flushed to the network.

        Also, call the transport-specific handshake method since this
        is a good time to perform a handshake.
        """
        if self.circuitIsReady():
            self.downstream.dataReceived('')
            self.transport.handshake(self)
예제 #11
0
    def setDownstreamConnection(self, conn): # XXX merge set{Downstream,Upstream}Connection.
        """
        Set the downstream connection of a circuit.
        """

        log.debug("%s: Setting downstream connection (%s)." % (self.name, conn.name))
        assert(not self.downstream)
        self.downstream = conn

        """We just completed the circuit.

        Do a dummy dataReceived on the initiating connection in case
        it has any buffered data that must be flushed to the network.

        Also, call the transport-specific handshake method since this
        is a good time to perform a handshake.
        """
        if self.circuitIsReady():
            self.upstream.dataReceived('') # XXX kind of a hack.
            self.transport.handshake(self)
예제 #12
0
    def dataReceived(self, data, conn):
        """
        We received 'data' on 'conn'. Pass the data to our transport,
        and then proxy it to the other side.

        Requires both downstream and upstream connections to be set.

        Returns the bytes that were not used by the transport.
        """
        log.debug("%s: Received %d bytes." % (self.name, len(data)))

        assert(self.downstream and self.upstream)
        assert((conn is self.downstream) or (conn is self.upstream))

        if conn is self.downstream:
            leftovers = self.transport.receivedDownstream(data, self)
        else:
            leftovers = self.transport.receivedUpstream(data, self)

        return leftovers
예제 #13
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()
예제 #14
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()
예제 #15
0
    def dataReceived(self, data):
        """
        Received some 'data'. They might be SOCKS handshake data, or
        actual upstream traffic. Figure out what it is and either
        complete the SOCKS handshake or proxy the traffic.
        """

        # SOCKS handshake not completed yet: let the overriden socks
        # module complete the handshake.
        if not self.otherConn:
            log.debug("%s: Received SOCKS handshake data." % self.name)
            return socks.SOCKSv4.dataReceived(self, data)

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

        assert(self.otherConn)

        if not self.circuit.circuitIsReady():
            self.circuit.setDownstreamConnection(self.otherConn)
            self.circuit.setUpstreamConnection(self)

        self.buffer = self.circuit.dataReceived(self.buffer + data, self)
예제 #16
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)
예제 #17
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)
예제 #18
0
def main(argv):
    parser = set_up_cli_parsing()

    args = parser.parse_args()

    consider_cli_args(args)

    log.debug('obfsproxy starting up!')
    log.debug('argv: ' + str(sys.argv))
    log.debug('args: ' + str(args))

    if (args.name == 'managed'):
        do_managed_mode()
    else:
        # Pass parsed arguments to the appropriate transports so that
        # they can initialize and setup themselves. Exit if the
        # provided arguments were corrupted.
        if (args.validation_function(args) == False):
            sys.exit(1)

        do_external_mode(args)
예제 #19
0
 def startedConnecting(self, connector):
     log.debug("%s: Client factory started connecting." % self.name)
예제 #20
0
 def startedConnecting(self, connector):
     log.debug("%s: Client factory started connecting." % self.name)