示例#1
0
    def launchServer(self, name, bindaddr, managedInfo):
        """
        Launch a client of transport 'name' using the environment
        information in 'managedInfo'.

        Return a tuple (<ok>, (<addr>, <port>)), where <ok> is whether
        the function was successful, and (<addr>, <port> is a tuple
        representing where we managed to bind.
        """

        serverClass = transports.get_transport_class_from_name_and_mode(
            name, 'server')
        if not serverClass:
            log.error("Could not find transport class for '%s' (%s)." %
                      (name, 'server'))
            return False, None

        factory = network.StaticDestinationServerFactory(
            managedInfo['orport'], 'server', serverClass())

        try:
            addrport = reactor.listenTCP(int(bindaddr[1]), factory)
        except CannotListenError:
            log.error("Could not set up a listener for TCP port '%s'." %
                      bindaddr[1])
            return False, None

        return True, (addrport.getHost().host, addrport.getHost().port)
示例#2
0
def launch_transport_listener(transport,
                              bindaddr,
                              role,
                              remote_addrport,
                              pt_config,
                              ext_or_cookie_file=None):
    """
    Launch a listener for 'transport' in role 'role' (socks/client/server/ext_server).

    If 'bindaddr' is set, then listen on bindaddr. Otherwise, listen
    on an ephemeral port on localhost.
    'remote_addrport' is the TCP/IP address of the other end of the
    circuit. It's not used if we are in 'socks' role.

    'pt_config' contains configuration options (such as the state location)
    which are of interest to the pluggable transport.

    'ext_or_cookie_file' is the filesystem path where the Extended
    ORPort Authentication cookie is stored. It's only used in
    'ext_server' mode.

    Return a tuple (addr, port) representing where we managed to bind.

    Throws obfsproxy.transports.transports.TransportNotFound if the
    transport could not be found.

    Throws twisted.internet.error.CannotListenError if the listener
    could not be set up.
    """

    transport_class = transports.get_transport_class(transport, role)
    listen_host = bindaddr[0] if bindaddr else 'localhost'
    listen_port = int(bindaddr[1]) if bindaddr else 0

    if role == 'socks':
        factory = socks.OBFSSOCKSv5Factory(transport_class, pt_config)
    elif role == 'ext_server':
        assert (remote_addrport and ext_or_cookie_file)
        factory = extended_orport.ExtORPortServerFactory(
            remote_addrport, ext_or_cookie_file, transport, transport_class,
            pt_config)
    else:
        assert (remote_addrport)
        factory = network.StaticDestinationServerFactory(
            remote_addrport, role, transport_class, pt_config)

    addrport = reactor.listenTCP(listen_port, factory, interface=listen_host)

    return (addrport.getHost().host, addrport.getHost().port)
 def _build_protocol(self, mode):
     """Build client and server protocols for an end point."""
     addr_tuple = (HOST, str(PORT))
     address = IPv4Address('TCP', HOST, PORT)
     pt_config = self._build_transport_configuration(mode)
     transport_class = self._configure_transport_class(mode, pt_config)
     f_server = net.StaticDestinationServerFactory(addr_tuple, mode,
                                                   transport_class,
                                                   pt_config)
     protocol_server = self._set_protocol(f_server, address)
     f_client = net.StaticDestinationClientFactory(protocol_server.circuit,
                                                   const.CLIENT)
     protocol_client = self._set_protocol(f_client, address)
     if mode == const.CLIENT:
         return protocol_client
     elif mode == const.SERVER:
         return protocol_server
     else:
         raise ValueError("Transport mode '%s' not recognized." % mode)
示例#4
0
def do_external_mode(args):
    """This function starts obfsproxy's external-mode functionality."""

    assert(args)
    assert(args.name)
    assert(args.name in transports.transports)

    transportClass = transports.get_transport_class_from_name_and_mode(args.name, args.mode)
    if (transportClass is None):
        log.error("Transport class was not found for '%s' in mode '%s'" % (args.name, args.mode))
        sys.exit(1)

    # XXX functionify
    import obfsproxy.network.network as network
    import obfsproxy.network.socks as socks
    from twisted.internet import reactor, error, address, tcp

    if (args.mode == 'client') or (args.mode == 'server'):
        factory = network.StaticDestinationServerFactory(args.dest, args.mode, transportClass())
    elif args.mode == 'socks':
        factory = socks.SOCKSv4Factory(transportClass())

    reactor.listenTCP(int(args.listen_addr[1]), factory)
    reactor.run()
示例#5
0
def launch_transport_listener(transport,
                              bindaddr,
                              role,
                              remote_addrport,
                              pt_config,
                              ext_or_cookie_file=None):
    """
    Launch a listener for 'transport' in role 'role' (socks/client/server/ext_server).

    If 'bindaddr' is set, then listen on bindaddr. Otherwise, listen
    on an ephemeral port on localhost.
    'remote_addrport' is the TCP/IP address of the other end of the
    circuit. It's not used if we are in 'socks' role.

    'pt_config' contains configuration options (such as the state location)
    which are of interest to the pluggable transport.

    'ext_or_cookie_file' is the filesystem path where the Extended
    ORPort Authentication cookie is stored. It's only used in
    'ext_server' mode.

    Return a tuple (addr, port) representing where we managed to bind.

    Throws obfsproxy.transports.transports.TransportNotFound if the
    transport could not be found.

    Throws twisted.internet.error.CannotListenError if the listener
    could not be set up.
    """

    listen_host = bindaddr[0] if bindaddr else 'localhost'
    listen_port = int(bindaddr[1]) if bindaddr else 0

    if role == 'socks':
        transport_class = FTETransportClient
        if hasattr(socks, "OBFSSOCKSv5Factory"):
            # obfsproxy >= 0.2.7 provides SOCKS5.
            factory = socks.OBFSSOCKSv5Factory(transport_class, pt_config)
            pt_config.fte_client_socks_version = 5
        elif hasattr(socks, "SOCKSv4Factory"):
            # obfsproxy < 0.2.7 provides SOCKS4.
            factory = socks.SOCKSv4Factory(transport_class, pt_config)
            pt_config.fte_client_socks_version = 4
        else:
            # This will only happen if the obfsproxy people change the socks
            # code again.  This really is a dependency issue, so raise an
            # ImportError.
            raise ImportError(
                "Failed to setup an obfsproxy SOCKS server factory")
    elif role == 'ext_server':
        assert (remote_addrport and ext_or_cookie_file)
        transport_class = FTETransportServer
        factory = extended_orport.ExtORPortServerFactory(
            remote_addrport, ext_or_cookie_file, transport, transport_class,
            pt_config)
    elif role == 'client':
        assert (remote_addrport)
        transport_class = FTETransportClient
        factory = network.StaticDestinationServerFactory(
            remote_addrport, role, transport_class, pt_config)
    elif role == 'server':
        assert (remote_addrport)
        transport_class = FTETransportServer
        factory = network.StaticDestinationServerFactory(
            remote_addrport, role, transport_class, pt_config)
    else:
        raise InvalidRoleException()

    addrport = twisted.internet.reactor.listenTCP(listen_port,
                                                  factory,
                                                  interface=listen_host)

    return (addrport.getHost().host, addrport.getHost().port)