|
| 1 | +import hashlib |
| 2 | + |
| 3 | +from dojo.models import Finding |
1 | 4 |
|
2 | 5 |
|
3 | 6 | class WazuhV4_8:
|
4 | 7 | def parse_findings(self, test, data):
|
5 |
| - # dupes = {} |
6 |
| - # vulnerabilities = data.get("data", {}).get("affected_items", []) |
7 |
| - # for item in vulnerabilities: |
8 |
| - # if ( |
9 |
| - # item["condition"] != "Package unfixed" |
10 |
| - # and item["severity"] != "Untriaged" |
11 |
| - # ): |
12 |
| - # cve = item.get("cve") |
13 |
| - # package_name = item.get("name") |
14 |
| - # package_version = item.get("version") |
15 |
| - # description = item.get("condition") |
16 |
| - # severity = item.get("severity").capitalize() |
17 |
| - # agent_ip = item.get("agent_ip") |
18 |
| - # links = item.get("external_references") |
19 |
| - # cvssv3_score = item.get("cvss3_score") |
20 |
| - # publish_date = item.get("published") |
21 |
| - # agent_name = item.get("agent_name") |
22 |
| - # agent_ip = item.get("agent_ip") |
23 |
| - # detection_time = item.get("detection_time").split("T")[0] |
24 |
| - |
25 |
| - # references = "\n".join(links) if links else None |
26 |
| - |
27 |
| - # title = ( |
28 |
| - # item.get("title") + " (version: " + package_version + ")" |
29 |
| - # ) |
30 |
| - |
31 |
| - # if agent_name: |
32 |
| - # dupe_key = title + cve + agent_name + package_name + package_version |
33 |
| - # else: |
34 |
| - # dupe_key = title + cve + package_name + package_version |
35 |
| - # dupe_key = hashlib.sha256(dupe_key.encode("utf-8")).hexdigest() |
36 |
| - |
37 |
| - # if dupe_key in dupes: |
38 |
| - # find = dupes[dupe_key] |
39 |
| - # else: |
40 |
| - # dupes[dupe_key] = True |
41 |
| - |
42 |
| - # find = Finding( |
43 |
| - # title=title, |
44 |
| - # test=test, |
45 |
| - # description=description, |
46 |
| - # severity=severity, |
47 |
| - # references=references, |
48 |
| - # static_finding=True, |
49 |
| - # component_name=package_name, |
50 |
| - # component_version=package_version, |
51 |
| - # cvssv3_score=cvssv3_score, |
52 |
| - # publish_date=publish_date, |
53 |
| - # unique_id_from_tool=dupe_key, |
54 |
| - # date=detection_time, |
55 |
| - # ) |
56 |
| - |
57 |
| - # # in some cases the agent_ip is not the perfect way on how to identify a host. Thus prefer the agent_name, if existant. |
58 |
| - # if agent_name: |
59 |
| - # find.unsaved_endpoints = [Endpoint(host=agent_name)] |
60 |
| - # elif agent_ip: |
61 |
| - # find.unsaved_endpoints = [Endpoint(host=agent_ip)] |
62 |
| - |
63 |
| - # if id: |
64 |
| - # find.unsaved_vulnerability_ids = cve |
65 |
| - |
66 |
| - # dupes[dupe_key] = find |
67 |
| - return [] |
| 8 | + dupes = {} |
| 9 | + vulnerabilities = data.get("hits", {}).get("hits", []) |
| 10 | + for item in vulnerabilities: |
| 11 | + vuln = item.get("vulnerability") |
| 12 | + cve = vuln.get("id") |
| 13 | + description = vuln.get("description") |
| 14 | + severity = vuln.get("severity") |
| 15 | + cvssv3_score = vuln.get("score").get("base") |
| 16 | + publish_date = vuln.get("published_at").split("T")[0] |
| 17 | + agent_name = item.get("agent").get("name") |
| 18 | + agent_id = item.get("agent").get("id") |
| 19 | + detection_time = vuln.get("detected_at").split("T")[0] |
| 20 | + |
| 21 | + references = vuln.get("reference") |
| 22 | + |
| 23 | + title = ( |
| 24 | + cve + " (agent_id: " + agent_id + ")" |
| 25 | + ) |
| 26 | + |
| 27 | + dupe_key = title + agent_name + description |
| 28 | + dupe_key = hashlib.sha256(dupe_key.encode("utf-8")).hexdigest() |
| 29 | + |
| 30 | + if dupe_key in dupes: |
| 31 | + find = dupes[dupe_key] |
| 32 | + else: |
| 33 | + dupes[dupe_key] = True |
| 34 | + |
| 35 | + find = Finding( |
| 36 | + title=title, |
| 37 | + test=test, |
| 38 | + description=description, |
| 39 | + severity=severity, |
| 40 | + references=references, |
| 41 | + static_finding=True, |
| 42 | + cvssv3_score=cvssv3_score, |
| 43 | + publish_date=publish_date, |
| 44 | + unique_id_from_tool=dupe_key, |
| 45 | + date=detection_time, |
| 46 | + ) |
| 47 | + dupes[dupe_key] = find |
| 48 | + return list(dupes.values()) |
0 commit comments