1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
import argparse import requests import redis import json import sys import re import os
try: UserInfo = json.load(open('userinfo.json')) except: print('[-]Load Json File Error!') exit()
r = redis.Redis(host=UserInfo['Host'],port=UserInfo['Port'],password=UserInfo['Pwd']) try: acount = r.scard('CNVD') print('[+]目前漏洞数为:',acount) except Exception as e: print('[-]Redis',e) exit()
def scanCNVD(): res = requests.post(UserInfo['Url'],data=UserInfo['Data'],headers=UserInfo['Headers']) text = bytes.decode(res.content) infos = re.findall('</img> <a\s.+href="/flaw/show/(.*?)"?\s+title="(.*?)">',text) for i in infos: info = i[0]+','+i[1] if r.sadd('CNVD',info): print('[*]New Info:',info) print('[*]Scan Finish.') r.save()
def writeFile(): cont = [bytes.decode(i) for i in r.smembers('CNVD')] if os.path.isfile('CNVD.csv'): with open('CNVD.csv','a') as af: af.write('\n'.join(cont)) else: with open('CNVD.csv','w') as wf: wf.write('编号,内容\n'+'\n'.join(cont)) print('[+]Save In CNVD.csv.')
if __name__ == '__main__': parse = argparse.ArgumentParser(description="CNVD INFO.") parse.add_argument('--update','-u',action='store_true',help='Update CNVD INFO') parse.add_argument('--file','-f',action='store_true',help='Save CNVD INFO') args = parse.parse_args() try: sys.argv[1] except: parse.print_help() exit() if args.file: writeFile() if args.update: scanCNVD()
|