Beispiel #1
0
def find_vuln_poc(mod):
    '''给定加载的 module (load_poc_file_as_module 结果)

    返回其中的 ABVuln 和 ABPoc 实例

    :return: (vuln, poc)
    '''
    vuln = None
    poc = None
    for attr in dir(mod):
        try:
            val = getattr(mod, attr)()
            if isinstance(val, ABPoc):
                if val.poc_id is not None and val.poc_id.strip() != '':
                    poc = val
                else:
                    logger.warn('POC ID 为空: {} - {}'.format(val, mod))
            elif isinstance(val, ABVuln):
                if val.vuln_id is not None and val.vuln_id.strip() != '':
                    vuln = val
                else:
                    logger.warn('Vuln ID 为空: {} - {}'.format(val, mod))
        except:
            continue
    return (vuln, poc)
Beispiel #2
0
    def update_pocs(self, poc_id_set):
        if (len(poc_id_set) == 0):
            return
        logger.info('开始更新 POC [count={}]'.format(len(poc_id_set)))

        self.sync_vuln(
            set([self.poc_vuln_ind[poc_id] for poc_id in poc_id_set]))

        poc_update_sql = '''UPDATE poc
            SET poc_name=%s, author=%s, vuln_id=%s,
                updated_at=%s, args=%s, create_time=%s
            WHERE poc_id=%s'''

        logger.info('准备要更新的 POC 数据 [count={}]'.format(len(poc_id_set)))
        now = datetime.datetime.now()
        poc_infos = [
            x for x in [self.poc_ind[x] for x in poc_id_set] if x is not None
        ]
        count = 0
        cursor = self.cnx.cursor()

        for poc_info in poc_infos:
            progress(count, len(poc_infos), '更新 POC')
            count += 1
            vuln_id = self.poc_vuln_ind[poc_info['poc_id']]
            if vuln_id not in self.synced_vuln_ids_in_db:
                poc_info['vuln_id'] = None
            else:
                poc_info['vuln_id'] = vuln_id
            poc_info['updated_at'] = now
            poc_info['args'] = poc_info.get('option_schema', None)
            poc_info['create_date'] = poc_info.get('create_date', now)
            try:
                cursor.execute(poc_update_sql, [
                    poc_info.get(k) for k in [
                        'name', 'author', 'vuln_id', 'updated_at', 'args',
                        'poc_id', 'create_date'
                    ]
                ])
            except Exception as e:
                logger.warn('POC 更新失败: {}\n{}\n{}'.format(
                    poc_info, e, poc_update_sql))

        self.cnx.commit()
        logger.info('成功更新 POC [count={}]'.format(len(poc_id_set)))
Beispiel #3
0
    def insert_vuln(self, vuln_id_set):
        if (len(vuln_id_set) == 0):
            return
        logger.info('开始插入 Vuln [count={}]'.format(len(vuln_id_set)))

        vuln_insert_sql = '''INSERT INTO vuln
            (vuln_id, vuln_name, vuln_type, c_id, c_version, cve_id, disclosure_date,
             submit_time, level, source, detail, created_at, updated_at)
            VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'''

        logger.info('准备要插入的 Vuln 数据')
        vuln_infos = [
            info
            for info in [self.vuln_ind[vuln_id] for vuln_id in vuln_id_set]
            if info is not None
        ]
        now = datetime.datetime.now()
        cursor = self.cnx.cursor()
        count = 0

        for vuln_info in vuln_infos:
            progress(count, len(vuln_infos), '插入漏洞')
            count += 1
            c_id = self.get_component_id(vuln_info['product'])
            if c_id is None:
                continue
            vuln_info['c_id'] = c_id
            vuln_info['submit_time'] = now
            vuln_info['created_at'] = now
            vuln_info['updated_at'] = now
            try:
                cursor.execute(vuln_insert_sql, [
                    vuln_info.get(k) for k in [
                        'vuln_id', 'name', 'type', 'c_id', 'product_version',
                        'cve_id', 'disclosure_date', 'submit_time', 'level',
                        'ref', 'desc', 'created_at', 'updated_at'
                    ]
                ])
            except Exception as e:
                logger.warn('Vuln 插入失败: {}\n{}'.format(vuln_info, e))
        self.cnx.commit()
        logger.info('成功插入 Vuln [count={}]'.format(len(vuln_id_set)))
Beispiel #4
0
    def insert_component(self, component_name_set):
        if (len(component_name_set) == 0):
            return
        logger.info('开始插入 Component [count={}]'.format(
            len(component_name_set)))
        component_insert_sql = '''INSERT INTO component
            (c_id, c_name, c_first, c_type, `desc`, producer,
             properties, created_at, updated_at)
            VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)'''

        logger.info('准备要插入的 Component 数据')
        now = datetime.datetime.now()
        name_infos = [
            name_info for name_info in [(n, get_product_info(n))
                                        for n in component_name_set]
            if name_info[1] is not None
        ]

        cursor = self.cnx.cursor()
        i = 0
        for (n, info) in name_infos:
            progress(i, len(name_infos), '插入组件')
            i += 1
            info['c_id'] = str(uuid.uuid4())
            info['c_name'] = n
            info['created_at'] = now
            info['updated_at'] = now
            try:
                cursor.execute(component_insert_sql, [
                    info.get(k) for k in [
                        'c_id', 'c_name', 'name_pinyin_first', 'type', 'desc',
                        'producer', 'properties', 'created_at', 'updated_at'
                    ]
                ])
            except Exception as e:
                logger.warn('组件插入失败: {} {}\n{}'.format(n, info, e))
        self.cnx.commit()
        logger.info('成功插入 Component [count={}]'.format(
            len(component_name_set)))
Beispiel #5
0
    def update_component(self, component_name_set):
        if (len(component_name_set) == 0):
            return
        logger.info('更新 Component [count={}]'.format(len(component_name_set)))

        component_update_sql = '''UPDATE component
            SET c_first=%s, c_type=%s, `desc`=%s, producer=%s, properties=%s, updated_at=%s
            WHERE c_name=%s'''

        logger.info('准备要更新的 Component 数据')
        now = datetime.datetime.now()
        name_infos = [
            name_info for name_info in [(n, get_product_info(n))
                                        for n in component_name_set]
            if name_info[1] is not None
        ]

        cursor = self.cnx.cursor()
        count = 0

        for (n, info) in name_infos:
            progress(count, len(name_infos), '更新组件')
            count += 1
            info['c_name'] = n
            info['updated_at'] = now

            try:
                cursor.execute(component_update_sql, [
                    info.get(k) for k in [
                        'name_pinyin_first', 'type', 'desc', 'producer',
                        'properties', 'updated_at', 'c_name'
                    ]
                ])
            except Exception as e:
                logger.warn('Component 更新失败: {} {}\n{}'.format(n, info, e))

        self.cnx.commit()
        logger.info('成功更新 Component [count={}]'.format(
            len(component_name_set)))
Beispiel #6
0
    def update_vuln(self, vuln_id_set):
        if (len(vuln_id_set) == 0):
            return
        logger.info('开始更新漏洞 [count={}]'.format(len(vuln_id_set)))
        vuln_update_sql = '''UPDATE vuln
            SET vuln_name=%s, vuln_type=%s, c_id=%s, c_version=%s, cve_id=%s, disclosure_date=%s, level=%s, source=%s, detail=%s, updated_at=%s
            WHERE vuln_id=%s'''

        logger.info('准备要更新的 Vuln 数据')
        vuln_infos = [
            info
            for info in [self.vuln_ind[vuln_id] for vuln_id in vuln_id_set]
            if info is not None
        ]
        now = datetime.datetime.now()
        count = 0
        cursor = self.cnx.cursor()

        for vuln_info in vuln_infos:
            progress(count, len(vuln_infos), '更新漏洞')
            count += 1
            c_id = self.get_component_id(vuln_info['product'])
            vuln_info['c_id'] = c_id
            vuln_info['updated_at'] = now
            try:
                cursor.execute(vuln_update_sql, [
                    vuln_info.get(k) for k in [
                        'name', 'type', 'c_id', 'product_version', 'cve_id',
                        'disclosure_date', 'level', 'ref', 'desc',
                        'updated_at', 'vuln_id'
                    ]
                ])
            except Exception as e:
                logger.warn('Vuln 更新失败: {}\n{}'.format(vuln_info, e))

        self.cnx.commit()
        logger.info('成功更新漏洞 [count={}]'.format(len(vuln_id_set)))