-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvulnerability_node.py
53 lines (46 loc) · 2.28 KB
/
vulnerability_node.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
from bs4 import BeautifulSoup
from pymongo import MongoClient
class VulnerabilityNode(object):
def __init__(self, CVEName, port, entry=False):
self.vulnerabilityName = CVEName
self.vulnerabilityPort = port
self.mapping1 = { 'High': 2, 'Low': 1, 'None': 0 }
self.mapping2 = { 'Admin': 2, 'User': 1, 'None': 0 }
self.type = 'vuln'
vulns = MongoClient('localhost', 27017).project.vulnerabilities
query = {}
query['cveName'] = CVEName
result = list(vulns.find(query))[0]
self.accessVector = result['access_vector']
self.accessLevel = result['gained_access']
self.requiredPrivilege = result['required_priv']
self.entry = entry
# def get_gained_access_and_access_vector(self):
# url = "https://www.cvedetails.com/cve/" + self.vulnerabilityName
# req = Request(url, headers={ 'User-Agent': 'Mozilla/5.0' })
# html_doc = urlopen(req).read()
# soup = BeautifulSoup(html_doc, 'lxml')
# table = soup.find("table", { 'id': 'cvssscorestable', 'class': 'details' })
# field_row = table.findAll("tr")[6]
# field_value = field_row.find("span").string
# return self.mapping2[field_value]
# def get_required_privilege(self):
# url = "https://nvd.nist.gov/vuln/detail/" + self.vulnerabilityName
# html_doc = urlopen(url)
# soup = BeautifulSoup(html_doc, 'lxml')
# tag = soup.find('span', { 'data-testid': 'vuln-cvssv3-pr' })
# if tag:
# field_value = tag.string.strip()
# else:
# field_value = "None" # By default, "None" privileges are required
# return self.mapping1[field_value]
def to_string(self):
return "({}, {}, {}, {}, {})".format(self.vulnerabilityName, self.vulnerabilityPort, self.requiredPrivilege, self.accessLevel, self.type)
def __eq__(self, other):
return self.vulnerabilityName == other.vulnerabilityName and self.vulnerabilityPort == other.vulnerabilityPort
def __hash__(self):
return hash(('name', self.vulnerabilityName, 'port', self.vulnerabilityPort))
# v = VulnerabilityNode('CVE-2012-3137', 53)
# print(v.accessLevel)
# print(v.accessVector)
# print(v.requiredPrivilege)