Exemplo n.º 1
0
def list_clients():
    results = ''
    for i, client in enumerate(kb.data.clients):
        try:
            client.conn.send(str.encode('uname\n'))
            time.sleep(0.01)
            ret = client.conn.recv(2048)
            if ret:
                ret = ret.decode('utf-8', errors="ignore")
                system = "unknown"
                if "darwin" in ret.lower():
                    system = "Darwin"
                elif "linux" in ret.lower():
                    system = "Linux"
                elif "uname" in ret.lower():
                    system = "Windows"

        except Exception as ex:  # If a connection fails, remove it
            logger.exception(ex)
            del kb.data.clients[i]
            continue
        results += (str(i) + "   " +
                    (desensitization(client.address[0])
                     if conf.ppt else str(client.address[0])) + "    " +
                    str(client.address[1]) + " ({0})".format(system) + '\n')
    data_to_stdout("----- Remote Clients -----" + "\n" + results)
Exemplo n.º 2
0
    def execute(self, target, headers=None, params=None, mode='verify', verbose=True):
        self.target = target
        self.url = parse_target_url(target) if self.current_protocol == POC_CATEGORY.PROTOCOL.HTTP else self.build_url()
        self.headers = headers
        self.params = str_to_dict(params) if params else {}
        self.mode = mode
        self.verbose = verbose
        self.expt = (0, 'None')
        # TODO
        output = None

        try:
            output = self._execute()

        except NotImplementedError as e:
            self.expt = (ERROR_TYPE_ID.NOTIMPLEMENTEDERROR, e)
            logger.log(CUSTOM_LOGGING.ERROR, 'POC: {0} not defined "{1}" mode'.format(self.name, self.mode))
            output = Output(self)

        except ConnectTimeout as e:
            self.expt = (ERROR_TYPE_ID.CONNECTTIMEOUT, e)
            while conf.retry > 0:
                logger.debug('POC: {0} timeout, start it over.'.format(self.name))
                try:
                    output = self._execute()
                    break
                except ConnectTimeout:
                    logger.debug('POC: {0} time-out retry failed!'.format(self.name))
                conf.retry -= 1
            else:
                msg = "connect target '{0}' failed!".format(target)
                logger.error(msg)
                output = Output(self)

        except HTTPError as e:
            self.expt = (ERROR_TYPE_ID.HTTPERROR, e)
            logger.warn('POC: {0} HTTPError occurs, start it over.'.format(self.name))
            output = Output(self)

        except ConnectionError as e:
            self.expt = (ERROR_TYPE_ID.CONNECTIONERROR, e)
            msg = "connect target '{0}' failed!".format(target)
            logger.error(msg)
            output = Output(self)

        except TooManyRedirects as e:
            self.expt = (ERROR_TYPE_ID.TOOMANYREDIRECTS, e)
            logger.debug(str(e))
            output = Output(self)


        except Exception as e:
            self.expt = (ERROR_TYPE_ID.OTHER, e)
            # logger.debug(str(e))
            logger.exception(e)
            output = Output(self)

        return output