前一千页CVE 对应影响产品信息 JSON文件格式转成HTML

第一部分代码:

下面代码不完整。完整代码:密码myname

import os
import json
import re
def show_files(path, all_files):
    global sum
    print("遍历:  "+path+"  文件夹ing ...")
    # 首先遍历当前目录所有文件及文件夹
    file_list = os.listdir(path)
    # 准备循环判断每个元素是否是文件夹还是文件,是文件的话,把名称传入list,是文件夹的话,递归
    for file in file_list:
        sum += 1
        # 利用os.path.join()方法取得路径全名,并存入cur_path变量,否则每次只能遍历一层目录
        cur_path = os.path.join(path, file)
        # 判断是否是文件夹
        if os.path.isdir(cur_path):
            show_files(cur_path, all_files)
        else:
            all_files.append(file)
    print("遍历结束: 共计:"+str(sum)+"个文件")
    return all_files
def json_to_html(i):
    print('正在处理:'+i)
    cve_inf_file = open('D:/0json/'+i+'_in_prod.json', "r")#2019-1010275_in_prod.json
    cve_inf_context = str(json.load(cve_inf_file))
    # print(cve_inf_context)
    cve_inf_context = cve_inf_context.replace('}, ', '}<br>').replace('[','').replace(']','')
    # print(cve_inf_context)
    head = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>漏洞对应影响产品信息</title></head>" \
           "<body bgcolor='#faebd7'><h1 style='padding-left: 320px'>Products Affected By This CVE</h1><div style='color: #3e2c42; text-align: -moz-left; line-height: 35px;font-size: 20px;'>"
    tail = "</div></body></html>"
    cve_inf_context = head + cve_inf_context + tail
    i = str(i)
    i = i.replace('-','')#去掉横杠
    with open('D:/0html/'+i+'.html', "w", encoding='utf-8') as json_file:
        json_file.write(cve_inf_context)
        json_file.close()
    print('D:/0html/'+i+'.html')
def rewrite():

if __name__ == '__main__':
    global contents,num,sum
    num = 0
    sum = 0
    contents = show_files("D:/0json", [])
    print("contents:"+str(contents))
    rewrite()
    # showresult()




第二部分代码:

# encoding=utf-8
'''
保存全部其他信息,起先可以设置为空!
'''
import json
if __name__ == '__main__':
    extend_dict = {}
    cve_num_file = open('D:/00000000/cve_num0.json', "r")
    cve_num_context = json.load(cve_num_file)
    cve_inf_file = open('D:/00000000/cve_addprod.json', "r")
    cve_inf_context = json.load(cve_inf_file)

    i = 0
    for suffix in cve_num_context:
        if str(type(suffix)) != "<class 'str'>":
            print("本次遍历已经结束!")
            break
        print('************本次:是位于列表第:'+str(i+1)+'位的CVE编号。爬取:'+str(suffix)+'所对应的信息!************')
        cve_inf_context[i]['exp_poc'] = ''
        cve_inf_context[i]['snort_rules'] = ''
        cve_inf_context[i]['test_traffic_pcap_packet'] = ''
        cve_inf_context[i]['vulnerability_triggering_environment'] = ''
        cve_inf_context[i]['download_blogs'] = ''
        i = i + 1
    with open('D:/00000000/cve_addprod_addexp_addothers.json', "w", encoding='utf-8') as json_file:
        json_str = json.dumps(cve_inf_context, indent=4, ensure_ascii=False)
        json_file.write(json_str)
        json_file.close()
        print('************成功存储:' + str(suffix) + '对应的exploit信息!************\n')
    print('\n\n************一共' + str(i) + '个数据,全部写入完成!************')

视频:https://www.bilibili.com/video/BV1gt4y1U7eY

发布了624 篇原创文章 · 获赞 1694 · 访问量 121万+

猜你喜欢

转载自blog.csdn.net/weixin_42859280/article/details/105488572