forked from phantomcyber/playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain_investigate.py
327 lines (213 loc) · 13.2 KB
/
domain_investigate.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
"""
Investigate a domain name (typically a top-level domain plus one). This playbook uses three different apps to run "domain reputation" and then aggregates the results and returns a note and a verdict.
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
def on_start(container):
phantom.debug('on_start() called')
# call 'google_safe_browsing_reputation' block
google_safe_browsing_reputation(container=container)
# call 'cisco_umbrella_reputation' block
cisco_umbrella_reputation(container=container)
# call 'virustotal_reputation' block
virustotal_reputation(container=container)
return
def google_safe_browsing_reputation(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("google_safe_browsing_reputation() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
playbook_input_domain = phantom.collect2(container=container, datapath=["playbook_input:domain"])
parameters = []
# build parameters list for 'google_safe_browsing_reputation' call
for playbook_input_domain_item in playbook_input_domain:
if playbook_input_domain_item[0] is not None:
parameters.append({
"domain": playbook_input_domain_item[0],
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("domain reputation", parameters=parameters, name="google_safe_browsing_reputation", assets=["safe browsing"], callback=join_filter_matching_domains)
return
def format_note(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("format_note() called")
template = """| Domain | VirusTotal | Cisco Umbrella Investigate |\n|---|---|---|\n%%\n| {0} | {1} | {2} | \n%%\n"""
# parameter list for template variable replacement
parameters = [
"filtered-data:filter_matching_domains:condition_1:virustotal_reputation:action_result.parameter.domain",
"filtered-data:filter_matching_domains:condition_1:virustotal_reputation:action_result.message",
"filtered-data:filter_matching_domains:condition_1:cisco_umbrella_reputation:action_result.message"
]
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.format(container=container, template=template, parameters=parameters, name="format_note")
add_note_3(container=container)
return
def add_note_3(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("add_note_3() called")
format_note = phantom.get_format_data(name="format_note")
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.add_note(container=container, content=format_note, note_format="markdown", note_type="general", title="Domain Investigate Results")
verdict_decision(container=container)
return
def cisco_umbrella_reputation(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("cisco_umbrella_reputation() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
playbook_input_domain = phantom.collect2(container=container, datapath=["playbook_input:domain"])
parameters = []
# build parameters list for 'cisco_umbrella_reputation' call
for playbook_input_domain_item in playbook_input_domain:
if playbook_input_domain_item[0] is not None:
parameters.append({
"domain": playbook_input_domain_item[0],
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("domain reputation", parameters=parameters, name="cisco_umbrella_reputation", assets=["ciscoumbrellainvestigate"], callback=join_filter_matching_domains)
return
def verdict_decision(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("verdict_decision() called")
# check for 'if' condition 1
found_match_1 = phantom.decision(
container=container,
logical_operator="or",
conditions=[
["filtered-data:filter_matching_domains:condition_1:cisco_umbrella_reputation:action_result.data.*.risk_score", ">", 25],
["filtered-data:filter_matching_domains:condition_1:virustotal_reputation:action_result.summary.malicious", ">=", 3]
])
# call connected blocks if condition 1 matched
if found_match_1:
high_risk_verdict(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'else' condition 2
low_risk_verdict(action=action, success=success, container=container, results=results, handle=handle)
return
def high_risk_verdict(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("high_risk_verdict() called")
template = """high_risk"""
# parameter list for template variable replacement
parameters = []
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.format(container=container, template=template, parameters=parameters, name="high_risk_verdict")
join_verdict_merge(container=container)
return
def low_risk_verdict(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("low_risk_verdict() called")
template = """low_risk"""
# parameter list for template variable replacement
parameters = []
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.format(container=container, template=template, parameters=parameters, name="low_risk_verdict")
join_verdict_merge(container=container)
return
def join_verdict_merge(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("join_verdict_merge() called")
if phantom.completed(action_names=["google_safe_browsing_reputation", "cisco_umbrella_reputation", "virustotal_reputation"]):
# call connected block "verdict_merge"
verdict_merge(container=container, handle=handle)
return
def verdict_merge(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("verdict_merge() called")
template = """{0}{1}"""
# parameter list for template variable replacement
parameters = [
"high_risk_verdict:formatted_data",
"low_risk_verdict:formatted_data"
]
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.format(container=container, template=template, parameters=parameters, name="verdict_merge", drop_none=True)
return
def virustotal_reputation(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("virustotal_reputation() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
playbook_input_domain = phantom.collect2(container=container, datapath=["playbook_input:domain"])
parameters = []
# build parameters list for 'virustotal_reputation' call
for playbook_input_domain_item in playbook_input_domain:
if playbook_input_domain_item[0] is not None:
parameters.append({
"domain": playbook_input_domain_item[0],
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("domain reputation", parameters=parameters, name="virustotal_reputation", assets=["virustotalv3"], callback=join_filter_matching_domains)
return
def join_filter_matching_domains(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("join_filter_matching_domains() called")
if phantom.completed(action_names=["google_safe_browsing_reputation", "cisco_umbrella_reputation", "virustotal_reputation"]):
# call connected block "filter_matching_domains"
filter_matching_domains(container=container, handle=handle)
return
def filter_matching_domains(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("filter_matching_domains() called")
################################################################################
# Match together action results
################################################################################
# collect filtered artifact ids and results for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
conditions=[
["virustotal_reputation:action_result.parameter.domain", "==", "cisco_umbrella_reputation:action_result.parameter.domain"]
],
name="filter_matching_domains:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
format_note(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def on_finish(container, summary):
phantom.debug("on_finish() called")
verdict_merge = phantom.get_format_data(name="verdict_merge")
output = {
"verdict": verdict_merge,
}
################################################################################
## Custom Code Start
################################################################################
################################################################################
## Custom Code End
################################################################################
phantom.save_playbook_output_data(output=output)
return