-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathparse_cs_incidents.py
136 lines (111 loc) · 4.58 KB
/
parse_cs_incidents.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
124
125
126
127
128
129
130
131
132
133
134
135
136
# File: parse_cs_incidents.py
#
# Copyright (c) 2019-2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.
import sys
from bs4 import UnicodeDammit
_container_common = {
"description": "Container added by Phantom",
"run_automation": False, # Don't run any playbooks when this container is added
}
_artifact_common = {
"label": "incident",
"type": "network",
"description": "Artifact added by Phantom",
"run_automation": False, # Don't run any playbooks when this artifact is added
}
_host_artifact_common = {
"label": "host",
"type": "host",
"description": "Artifact added by Phantom",
"run_automation": False, # Don't run any playbooks when this artifact is added
}
def _get_incident_severity(fine_score):
if fine_score >= 80:
return "high"
elif fine_score >= 60:
return "medium"
else:
return "low"
def _create_incident_artifact(incident):
artifact = dict(_artifact_common)
artifact["name"] = "Incident Details"
artifact["source_data_identifier"] = incident.get("incident_id")
artifact["severity"] = _get_incident_severity(incident.get("fine_score", 0))
# Key CEF mapping
artifact["cef"] = {
"status": incident.get("status"),
"name": incident.get("name"),
"description": incident.get("description"),
"severity": incident.get("fine_score"),
"state": incident.get("state"),
"tags": incident.get("tags", []),
"created_time": incident.get("created"),
"modified_time": incident.get("modified_timestamp"),
"incident_id": incident.get("incident_id"),
"tactics": incident.get("tactics", []),
"techniques": incident.get("techniques", []),
"objectives": incident.get("objectives", []),
}
return artifact
def _create_host_artifact(host, incident):
artifact = dict(_host_artifact_common)
artifact["name"] = "Affected Host"
artifact["source_data_identifier"] = f"{incident.get('incident_id')}_{host.get('device_id')}"
artifact["severity"] = _get_incident_severity(incident.get("fine_score", 0))
# Key CEF mapping
artifact["cef"] = {
"hostname": host.get("hostname"),
"host_id": host.get("device_id"),
"local_ip": host.get("local_ip"),
"external_ip": host.get("external_ip"),
"platform": host.get("platform_name"),
"os_version": host.get("os_version"),
"mac_address": host.get("mac_address"),
"system_manufacturer": host.get("system_manufacturer"),
"last_seen": host.get("last_seen"),
"status": host.get("status"),
}
return artifact
def process_incidents(incidents):
results = []
for incident in incidents:
ingest_event = dict()
results.append(ingest_event)
# Incident
artifacts = [_create_incident_artifact(incident)]
# Host
for host in incident.get("hosts", []):
artifacts.append(_create_host_artifact(host, incident))
# Container
container = dict()
ingest_event["container"] = container
container.update(_container_common)
if sys.version_info[0] == 2:
container["name"] = "{0} on {1} at {2}".format(
UnicodeDammit(incident.get("name", "Unnamed Incident")).unicode_markup.encode("utf-8"),
UnicodeDammit(incident.get("hosts", [{}])[0].get("hostname", "Unknown Host")).unicode_markup.encode("utf-8"),
incident.get("start", "Unknown Time"),
)
else:
container["name"] = "{0} on {1} at {2}".format(
incident.get("name", "Unnamed Incident"),
incident.get("hosts", [{}])[0].get("hostname", "Unknown Host"),
incident.get("start", "Unknown Time"),
)
# Container properties
container["description"] = incident.get("description", "No description available")
container["source_data_identifier"] = incident.get("incident_id")
container["severity"] = _get_incident_severity(incident.get("fine_score", 0))
ingest_event["artifacts"] = artifacts
return results