Exemple #1
0
    def find_server(default_tunnel=None):
        LOG.debug("Trying to wake up with Monkey Island servers list: %r" %
                  WormConfiguration.command_servers)
        if default_tunnel:
            LOG.debug("default_tunnel: %s" % (default_tunnel, ))

        current_server = ""

        for server in WormConfiguration.command_servers:
            try:
                current_server = server

                debug_message = "Trying to connect to server: %s" % server
                if ControlClient.proxies:
                    debug_message += " through proxies: %s" % ControlClient.proxies
                LOG.debug(debug_message)
                requests.get(
                    "https://%s/api?action=is-up" % (server, ),  # noqa: DUO123
                    verify=False,
                    proxies=ControlClient.proxies,
                    timeout=TIMEOUT_IN_SECONDS)
                WormConfiguration.current_server = current_server
                break

            except ConnectionError as exc:
                current_server = ""
                LOG.warning("Error connecting to control server %s: %s",
                            server, exc)

        if current_server:
            return True
        else:
            if ControlClient.proxies:
                return False
            else:
                LOG.info("Starting tunnel lookup...")
                proxy_find = tunnel.find_tunnel(default=default_tunnel)
                if proxy_find:
                    proxy_address, proxy_port = proxy_find
                    LOG.info("Found tunnel at %s:%s" %
                             (proxy_address, proxy_port))
                    ControlClient.proxies['https'] = 'https://%s:%s' % (
                        proxy_address, proxy_port)
                    return ControlClient.find_server()
                else:
                    LOG.info("No tunnel found")
                    return False
Exemple #2
0
    def find_server(default_tunnel=None):
        logger.debug("Trying to wake up with Monkey Island servers list: %r" %
                     WormConfiguration.command_servers)
        if default_tunnel:
            logger.debug("default_tunnel: %s" % (default_tunnel, ))

        current_server = ""

        for server in WormConfiguration.command_servers:
            try:
                current_server = server

                debug_message = "Trying to connect to server: %s" % server
                if ControlClient.proxies:
                    debug_message += " through proxies: %s" % ControlClient.proxies
                logger.debug(debug_message)
                requests.get(  # noqa: DUO123
                    f"https://{server}/api?action=is-up",
                    verify=False,
                    proxies=ControlClient.proxies,
                    timeout=TIMEOUT_IN_SECONDS,
                )
                WormConfiguration.current_server = current_server
                break

            except ConnectionError as exc:
                current_server = ""
                logger.warning("Error connecting to control server %s: %s",
                               server, exc)

        if current_server:
            return True
        else:
            if ControlClient.proxies:
                return False
            else:
                logger.info("Starting tunnel lookup...")
                proxy_find = tunnel.find_tunnel(default=default_tunnel)
                if proxy_find:
                    ControlClient.set_proxies(proxy_find)
                    return ControlClient.find_server()
                else:
                    logger.info("No tunnel found")
                    return False