forked from infobyte/faraday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSeverityByCwe.py
123 lines (91 loc) · 3.43 KB
/
getSeverityByCwe.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
'''
Faraday Penetration Test IDE
Copyright (C) 2016 Infobyte LLC (http://www.infobytesec.com/)
See the file 'doc/LICENSE' for the license information
'''
import json
import requests
from persistence.server import models
__description__ = 'Get Vulns filtered by Severity and change Severity based in CWE'
__prettyname__ = 'Get Severity By CWE'
SEVERITY_OPTIONS = ('unclassified', 'info', 'low', 'med', 'high', 'critical', 'all')
def getCweData(couch_url):
# Get elements from cwe DB in couchdb
headers = {'Content-Type': 'application/json'}
payload = {
'map':
'function(doc) { if(doc.severity && doc.name){'
'emit(doc.name, doc.severity); }}'
}
r = requests.post(
couch_url + '/cwe/_temp_view',
headers=headers,
data=json.dumps(payload)
)
response_code = r.status_code
if response_code == 200:
data = r.json()['rows']
dict = {}
for item in data:
value = item['value']
if value == 'informational':
value = 'info'
dict.update({item['key']: value})
if dict == {}:
return None
else:
print 'Get CWE data: OK\n'
return dict
elif response_code == 401:
print 'Autorization required, make sure to add user:pwd to Couch URI'
else:
print 'Error couchDB: ' + str(response_code) + str(r.text)
def checkSeverity(vuln, cwe_dict, severity_choose, workspace, couch_url):
severity_dict = {
'unclassified': 0,
'info': 1,
'low': 2,
'med': 3,
'high': 4,
'critical': 5,
'all': 100
}
if vuln._name in cwe_dict and severity_dict[vuln.severity] <= severity_dict[severity_choose]:
print 'Change: ' + vuln._name + ' to ' + cwe_dict[vuln._name]
# Get object Vuln
response = requests.get(
models.server.SERVER_URL + '/' + workspace + '/' + str(vuln._id)
)
vulnWeb = response.json()
# Change severity
vulnWeb['severity'] = cwe_dict[vuln._name]
# Put changes...
headers = {'Content-Type': 'application/json'}
update = requests.put(
couch_url + '/' + workspace + '/' + vuln._id,
headers=headers,
data=json.dumps(vulnWeb)
)
if update.status_code == 200 or update.status_code == 201:
print 'Change OK\n'
else:
print 'Error in update Vulnerability, status code: ' + str(update.status_code)
print update.text
def main(workspace='', args=None, parser=None):
parser.add_argument('severity', nargs='?', help='Filter by Severity (<=)', default="info", choices=SEVERITY_OPTIONS)
parser.add_argument('--couchdb', nargs='?', help='CouchDB URL', default="http://faraday:faraday@localhost:5984")
parsed_args = parser.parse_args(args)
cwe = getCweData(parsed_args.couchdb)
if cwe is None:
print 'CWE DB not downloaded....EXIT'
return 2, None
for host in models.get_hosts(workspace):
for v in host.getVulns():
checkSeverity(v, cwe, parsed_args.severity, workspace, parsed_args.couchdb)
for i in host.getAllInterfaces():
for s in i.getAllServices():
for v in s.getVulns():
checkSeverity(v, cwe, parsed_args.severity, workspace, parsed_args.couchdb)
return 0, None