|
@@ -12,6 +12,7 @@ from .CVEParse import CVEParse
|
|
from ..VendorModel import VendorModel
|
|
from ..VendorModel import VendorModel
|
|
from .CSVReader import CSVReader
|
|
from .CSVReader import CSVReader
|
|
from .Tests import Tests
|
|
from .Tests import Tests
|
|
|
|
+from fixcwes import ret_roots
|
|
|
|
|
|
class DebianModel(VendorModel):
|
|
class DebianModel(VendorModel):
|
|
"""
|
|
"""
|
|
@@ -35,6 +36,9 @@ class DebianModel(VendorModel):
|
|
self.src2deps = dict()
|
|
self.src2deps = dict()
|
|
self.pkg_with_cvss = dict()
|
|
self.pkg_with_cvss = dict()
|
|
self.src2sum = dict()
|
|
self.src2sum = dict()
|
|
|
|
+ self.src2monthDLA = dict()
|
|
|
|
+ self.pkg_with_cvss_DLA = dict()
|
|
|
|
+ self.src2cwe = dict()
|
|
|
|
|
|
|
|
|
|
## config
|
|
## config
|
|
@@ -99,6 +103,9 @@ class DebianModel(VendorModel):
|
|
self.src2sloccount = self.load_single_db_from_cache('src2sloccount')
|
|
self.src2sloccount = self.load_single_db_from_cache('src2sloccount')
|
|
self.src2pop = self.load_single_db_from_cache('src2pop')
|
|
self.src2pop = self.load_single_db_from_cache('src2pop')
|
|
self.pkg_with_cvss = self.load_single_db_from_cache('pkg_with_cvss')
|
|
self.pkg_with_cvss = self.load_single_db_from_cache('pkg_with_cvss')
|
|
|
|
+ self.src2monthDLA = self.load_single_db_from_cache('src2monthDLA')
|
|
|
|
+ self.pkg_with_cvss_DLA = self.load_single_db_from_cache('plg_with_cvss_DLA')
|
|
|
|
+ self.src2cwe = self.load_single_db_from_cache('src2cwe')
|
|
|
|
|
|
def load_single_db_from_cache(self, file_name):
|
|
def load_single_db_from_cache(self, file_name):
|
|
cache_dir = os.path.join(self.module_path, self.config['DIR']['cache_dir'])
|
|
cache_dir = os.path.join(self.module_path, self.config['DIR']['cache_dir'])
|
|
@@ -118,8 +125,12 @@ class DebianModel(VendorModel):
|
|
self.store_db_single('src2sloccount', self.src2sloccount)
|
|
self.store_db_single('src2sloccount', self.src2sloccount)
|
|
self.store_db_single('src2pop', self.src2pop)
|
|
self.store_db_single('src2pop', self.src2pop)
|
|
self.store_db_single('pkg_with_cvss', self.pkg_with_cvss)
|
|
self.store_db_single('pkg_with_cvss', self.pkg_with_cvss)
|
|
|
|
+ self.store_db_single('src2monthDLA', self.src2monthDLA)
|
|
|
|
+ self.store_db_single('pkg_with_cvss_DLA', self.pkg_with_cvss_DLA)
|
|
|
|
+ self.store_db_single('src2cwe', self.src2cwe)
|
|
|
|
|
|
# src2month needs special handling
|
|
# src2month needs special handling
|
|
|
|
+ # Check later if the same is true for other dicts
|
|
cache_src2month = os.path.join(self.module_path, self.config['DIR']['cache_dir'], 'src2month')
|
|
cache_src2month = os.path.join(self.module_path, self.config['DIR']['cache_dir'], 'src2month')
|
|
int_list = dict()
|
|
int_list = dict()
|
|
|
|
|
|
@@ -235,11 +246,6 @@ class DebianModel(VendorModel):
|
|
return state, err
|
|
return state, err
|
|
|
|
|
|
def processCVEs(self, srcpkg, now):
|
|
def processCVEs(self, srcpkg, now):
|
|
- """
|
|
|
|
- compute and store MTBF, MTBR and Scores of each src pkg
|
|
|
|
- output: %src2mtbf
|
|
|
|
- (srcpkg=> ())
|
|
|
|
- """
|
|
|
|
|
|
|
|
stats = [now, 0, 0, 0, 0, 0, 0]
|
|
stats = [now, 0, 0, 0, 0, 0, 0]
|
|
cvestats = dict()
|
|
cvestats = dict()
|
|
@@ -248,6 +254,9 @@ class DebianModel(VendorModel):
|
|
## keep track of the number of low-medium-high severity vulnerabilities
|
|
## keep track of the number of low-medium-high severity vulnerabilities
|
|
## TODO see how cvss affects vulnerability prediction - if some packages show patterns
|
|
## TODO see how cvss affects vulnerability prediction - if some packages show patterns
|
|
with_cvss = dict()
|
|
with_cvss = dict()
|
|
|
|
+ ## Keep track of the vulnerability types
|
|
|
|
+ with_cwe = dict()
|
|
|
|
+ root_list = ['682', '118', '330', '435', '664', '691', '693', '697', '703', '707', '710' ]
|
|
|
|
|
|
## To eliminate duplicate cves
|
|
## To eliminate duplicate cves
|
|
haveseen = dict()
|
|
haveseen = dict()
|
|
@@ -266,9 +275,8 @@ class DebianModel(VendorModel):
|
|
cvestats[tt] = 1
|
|
cvestats[tt] = 1
|
|
stats[1] += 1
|
|
stats[1] += 1
|
|
|
|
|
|
- ## Date at the moment taken from CVE? - not sure.
|
|
|
|
-
|
|
|
|
haveseen = dict()
|
|
haveseen = dict()
|
|
|
|
+ haveseen2 = dict()
|
|
|
|
|
|
## with_cvss = (date: number low, number med, number high, number undefined)
|
|
## with_cvss = (date: number low, number med, number high, number undefined)
|
|
for dsa_id in self.src2dsa[srcpkg]:
|
|
for dsa_id in self.src2dsa[srcpkg]:
|
|
@@ -304,6 +312,41 @@ class DebianModel(VendorModel):
|
|
else:
|
|
else:
|
|
with_cvss[tt][2] += 1
|
|
with_cvss[tt][2] += 1
|
|
|
|
|
|
|
|
+ ## with_cwe = (date: 11*[root type])
|
|
|
|
+ for dsa_id in self.src2dsa[srcpkg]:
|
|
|
|
+ for cve_id in self.dsa2cve[str(dsa_id)]:
|
|
|
|
+ tt = self.cvetable[cve_id][0]
|
|
|
|
+ try:
|
|
|
|
+ temp_cwe = self.cvetable[cve_id][5]
|
|
|
|
+ except TypeError:
|
|
|
|
+ print(cve_id)
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ if cve_id in haveseen2:
|
|
|
|
+ continue
|
|
|
|
+ else:
|
|
|
|
+ haveseen2[cve_id] = 1
|
|
|
|
+ if tt in with_cwe:
|
|
|
|
+ for i in ret_roots(temp_cwe):
|
|
|
|
+ if i == 0:
|
|
|
|
+ with_cwe[tt][11] += 1
|
|
|
|
+ print('Problem with cve: ', cve_id)
|
|
|
|
+ for j in range(len(root_list)):
|
|
|
|
+ if i == root_list[j]:
|
|
|
|
+ with_cwe[tt][j] += 1
|
|
|
|
+ else:
|
|
|
|
+ with_cwe[tt] = [0]*12
|
|
|
|
+ for i in ret_roots(temp_cwe):
|
|
|
|
+ if i == 0:
|
|
|
|
+ with_cwe[tt][11] += 1
|
|
|
|
+ print('Problem with cve: ', cve_id)
|
|
|
|
+ for j in range(len(root_list)):
|
|
|
|
+ print('This is the with_cwe')
|
|
|
|
+ if i == root_list[j]:
|
|
|
|
+ with_cwe[tt][j] += 1
|
|
|
|
+ print('This is the with_cwe')
|
|
|
|
+ print(with_cwe)
|
|
|
|
+
|
|
# Ignore pkgs with less than one incident, should not happen..
|
|
# Ignore pkgs with less than one incident, should not happen..
|
|
if stats[1] < 1:
|
|
if stats[1] < 1:
|
|
return
|
|
return
|
|
@@ -321,6 +364,48 @@ class DebianModel(VendorModel):
|
|
|
|
|
|
self.format_data(srcpkg, cvestats, self.src2month, False)
|
|
self.format_data(srcpkg, cvestats, self.src2month, False)
|
|
|
|
|
|
|
|
+ self.format_cwes(srcpkg, with_cwe)
|
|
|
|
+
|
|
|
|
+#########################################################################
|
|
|
|
+ def format_cwes(self, srcpkg, with_cwe):
|
|
|
|
+ x = []
|
|
|
|
+ y = []
|
|
|
|
+ monthyear = []
|
|
|
|
+ year = []
|
|
|
|
+
|
|
|
|
+ temp_items = list(with_cwe.items())
|
|
|
|
+ items = []
|
|
|
|
+
|
|
|
|
+ for cwe_dict in temp_items:
|
|
|
|
+ if isinstance(cwe_dict[0], str):
|
|
|
|
+ tmpx = (parser.parse(cwe_dict[0]))
|
|
|
|
+ else:
|
|
|
|
+ tmpx = cwe_dict[0]
|
|
|
|
+ x.append(tmpx)
|
|
|
|
+
|
|
|
|
+ tmpy = cwe_dict[1]
|
|
|
|
+
|
|
|
|
+ y.append(tmpy)
|
|
|
|
+ items.append((tmpx, tmpy))
|
|
|
|
+
|
|
|
|
+ items.sort(key=lambda tup: tup[0])
|
|
|
|
+
|
|
|
|
+ for i in range(2000,2019):
|
|
|
|
+ temp = []
|
|
|
|
+ for j in range(12):
|
|
|
|
+ temp.append([0]*12)
|
|
|
|
+ monthyear.append(temp)
|
|
|
|
+
|
|
|
|
+ for i in range(len(x)):
|
|
|
|
+ for j in range(len(y[i])):
|
|
|
|
+ monthyear[x[i].year - 2000][x[i].month - 1][j] += y[i][j]
|
|
|
|
+
|
|
|
|
+ months_list = [item for sublist in monthyear for item in sublist]
|
|
|
|
+
|
|
|
|
+ self.src2cwe[srcpkg] = months_list
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
def format_data(self, pkg, cvestats, src2temp, cvss):
|
|
def format_data(self, pkg, cvestats, src2temp, cvss):
|
|
x = []
|
|
x = []
|
|
y = []
|
|
y = []
|
|
@@ -355,9 +440,6 @@ class DebianModel(VendorModel):
|
|
temp.append(0)
|
|
temp.append(0)
|
|
monthyear.append(temp)
|
|
monthyear.append(temp)
|
|
|
|
|
|
- if pkg=='linux':
|
|
|
|
- print(x)
|
|
|
|
-
|
|
|
|
for i in range(len(x)):
|
|
for i in range(len(x)):
|
|
if cvss:
|
|
if cvss:
|
|
tmp0 = y[i][0]
|
|
tmp0 = y[i][0]
|