afl_types.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from pymongo import MongoClient
  2. from vendors.debian.CVEParse import CVEParse as cparse
  3. import json
  4. from fixcwes import ret_roots
  5. import matplotlib.pyplot as plt
  6. import seaborn as sns
  7. import paper_plots as carlosplt
  8. cves = []
  9. client = MongoClient()
  10. with open('afl_data.txt', 'r') as f:
  11. for line in f:
  12. cves.append(line[:-1])
  13. cwes = []
  14. for cve_id in cves:
  15. cve = cparse.fetchCVE(cve_id, client)
  16. cvestats = cparse.parseCVE(cve_id, cve)
  17. cwes.append(cvestats[4])
  18. cwes_counter = dict()
  19. for cwe in cwes:
  20. if cwe in cwes_counter:
  21. cwes_counter[cwe] += 1
  22. else:
  23. cwes_counter[cwe] = 1
  24. with open("cwe_afl.json","w") as fp:
  25. json.dump(cwes_counter,fp)
  26. print(cwes_counter)
  27. path = './vendors/debian/cache/cvetable'
  28. cvetable = dict()
  29. with open(path) as f:
  30. cvetable = json.load(f)
  31. ii = 0
  32. for cve_id in cves:
  33. if cve_id in cvetable:
  34. ii += 1
  35. cwes_deb = []
  36. for cve_id in cves:
  37. if cve_id in cvetable:
  38. cve = cparse.fetchCVE(cve_id, client)
  39. cvestats = cparse.parseCVE(cve_id, cve)
  40. cwes_deb.append(cvestats[4])
  41. cwes_counter_deb = dict()
  42. for cwe in cwes_deb:
  43. if cwe in cwes_counter_deb:
  44. cwes_counter_deb[cwe] += 1
  45. else:
  46. cwes_counter_deb[cwe] = 1
  47. with open("cwe_afl_deb.json","w") as fp:
  48. json.dump(cwes_counter_deb,fp)
  49. print(ii)
  50. root_list = ['CWE-682', 'CWE-118', 'CWE-664', 'CWE-693', 'CWE-710', 'rest' ]
  51. data = [29, 158, 23, 27, 39, 62]
  52. carlosplt.pre_paper_plot()
  53. fig1, ax1 = plt.subplots()
  54. ax1.pie(data, labels=root_list, autopct='%1.1f%%', startangle=90)
  55. #draw circle
  56. centre_circle = plt.Circle((0,0),0.70,fc='white')
  57. fig = plt.gcf()
  58. fig.gca().add_artist(centre_circle)
  59. # Equal aspect ratio ensures that pie is drawn as a circle
  60. ax1.axis('equal')
  61. plt.tight_layout()
  62. carlosplt.post_paper_plot(True,True,True)
  63. plt.show()