-
Notifications
You must be signed in to change notification settings - Fork 7
/
products_update.py
72 lines (63 loc) · 2.35 KB
/
products_update.py
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
62
63
64
65
66
67
68
69
70
71
72
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
import normalized
def increase_product():
cursor = normalized.db.cursor()
vuldb_sql = "select vul_chname, vdb_id, cve_id, vul_des, affect_vendor, affect_product from vuldb"
products_sql = "select vdb_id from vuldb"
try:
cursor.execute(vuldb_sql)
vuldb_result = cursor.fetchall()
cursor.execute(products_sql)
products_vdb_ids = cursor.fetchall()
except Exception as e:
print e
for item in vuldb_result:
if not (item[2],) not in products_vdb_ids:
# update productsdb
tmp = {}
tmp["vul_chname"] = item[0].encode('utf-8')
tmp["vdb_id"] = item[1].encode('utf-8')
tmp["cve_id"] = item[2].encode('utf-8')
tmp["vul_des"] = item[3].encode('utf-8')
tmp["affect_vendor"] = item[4].encode('utf-8')
tmp["affect_product"] = item[5].encode('utf-8')
yield tmp
def recrawl_missed_url():
missed_cve_id = []
with open('missed_url', 'r') as f:
for line in f:
m = line.split(r'/')[-1]
missed_cve_id.append(m)
products_sql = "select vdb_id from vuldb"
try:
cursor.execute(products_sql)
products_vdb_ids = cursor.fetchall()
except Exception as e:
print e
normalized.db.rollback()
for cve_id in missed_cve_id:
if (cve_id,) not in products_vdb_ids:
# update productsdb
sql = "select vul_chname, vdb_id, cve_id, vul_des, affect_vendor, affect_product from vuldb where cve_id=%s"
cursor = db.cursor()
try:
cursor.execute(sql, [cve_id])
item = cursor.fetchall()
except Exception as e:
print e
normalized.db.rollback()
tmp = {}
tmp["vul_chname"] = item[0].encode('utf-8')
tmp["vdb_id"] = item[1].encode('utf-8')
tmp["cve_id"] = item[2].encode('utf-8')
tmp["vul_des"] = item[3].encode('utf-8')
tmp["affect_vendor"] = item[4].encode('utf-8')
tmp["affect_product"] = item[5].encode('utf-8')
yield tmp
def main():
normalized.fetch_product_detail(increase_product)
normalized.fetch_product_detail(recrawl_missed_url)
if __name__ == '__main__':
main()