-
Notifications
You must be signed in to change notification settings - Fork 1
/
CBC Assets.py
658 lines (473 loc) · 24 KB
/
CBC Assets.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
"""
initial
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
@phantom.playbook_block()
def on_start(container):
phantom.debug('on_start() called')
# call 'get_asset_info_1' block
get_asset_info_1(container=container)
return
@phantom.playbook_block()
def get_asset_info_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("get_asset_info_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.deviceExternalId","artifact:*.id"])
parameters = []
# build parameters list for 'get_asset_info_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"device_id": container_artifact_item[0],
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("get asset info", parameters=parameters, name="get_asset_info_1", assets=["dev01"], callback=prompt_action)
return
@phantom.playbook_block()
def prompt_action(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("prompt_action() called")
# set user and message variables for phantom.prompt call
user = "admin"
message = """Choose an action to run"""
# parameter list for template variable replacement
parameters = []
# responses
response_types = [
{
"prompt": "Choose Action",
"options": {
"type": "list",
"choices": [
"Pivot to a LiveResponse session",
"Kill a process on the endpoint",
"Quarantine/Unquarantine",
"Ban/Unban process hash",
"Dismiss alert"
],
},
}
]
phantom.prompt2(container=container, user=user, message=message, respond_in_mins=30, name="prompt_action", parameters=parameters, response_types=response_types, callback=decision_1)
return
@phantom.playbook_block()
def decision_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("decision_1() called")
# check for 'elif' condition 1
found_match_1 = phantom.decision(
container=container,
conditions=[
["prompt_action:action_result.summary.responses.0", "==", "Kill a process on the endpoint"]
])
# call connected blocks if condition 1 matched
if found_match_1:
kill_process_1(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 2
found_match_2 = phantom.decision(
container=container,
conditions=[
["prompt_action:action_result.summary.responses.0", "==", "Pivot to a LiveResponse session"]
])
# call connected blocks if condition 2 matched
if found_match_2:
get_live_query_url_2(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 3
found_match_3 = phantom.decision(
container=container,
conditions=[
["prompt_action:action_result.summary.responses.0", "==", "Ban/Unban process hash"]
])
# call connected blocks if condition 3 matched
if found_match_3:
prompt_ban(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 4
found_match_4 = phantom.decision(
container=container,
conditions=[
["prompt_action:action_result.summary.responses.0", "==", "Quarantine/Unquarantine"]
])
# call connected blocks if condition 4 matched
if found_match_4:
prompt_quarantine(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 5
found_match_5 = phantom.decision(
container=container,
conditions=[
["prompt_action:action_result.summary.responses.0", "==", "Dismiss alert"]
])
# call connected blocks if condition 5 matched
if found_match_5:
prompt_dismiss(action=action, success=success, container=container, results=results, handle=handle)
return
return
@phantom.playbook_block()
def prompt_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("prompt_2() called")
# set user and message variables for phantom.prompt call
user = "admin"
message = """Please click [Here]({0}) for Process Analysis. Add a comment below."""
# parameter list for template variable replacement
parameters = [
"get_live_query_url_2:custom_function_result.data.console_url"
]
# responses
response_types = [
{
"prompt": "Enter comment",
"options": {
"type": "message",
},
}
]
phantom.prompt2(container=container, user=user, message=message, respond_in_mins=30, name="prompt_2", parameters=parameters, response_types=response_types)
return
@phantom.playbook_block()
def kill_process_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("kill_process_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.deviceExternalId","artifact:*.cef.process_guid","artifact:*.cef.destinationProcessName","artifact:*.id"])
parameters = []
# build parameters list for 'kill_process_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"device_id": container_artifact_item[0],
"process_guid": container_artifact_item[1],
"process_name": container_artifact_item[2],
"context": {'artifact_id': container_artifact_item[3]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("kill process", parameters=parameters, name="kill_process_1", assets=["dev01"])
return
@phantom.playbook_block()
def prompt_ban(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("prompt_ban() called")
# set user and message variables for phantom.prompt call
user = "admin"
message = """Ban or unban process hash"""
# parameter list for template variable replacement
parameters = []
# responses
response_types = [
{
"prompt": "Choose action",
"options": {
"type": "list",
"choices": [
"Ban process hash",
"Unban process hash"
],
},
}
]
phantom.prompt2(container=container, user=user, message=message, respond_in_mins=30, name="prompt_ban", parameters=parameters, response_types=response_types, callback=decision_2)
return
@phantom.playbook_block()
def decision_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("decision_2() called")
# check for 'if' condition 1
found_match_1 = phantom.decision(
container=container,
conditions=[
["prompt_ban:action_result.summary.responses.0", "==", "Ban process hash"]
])
# call connected blocks if condition 1 matched
if found_match_1:
ban_hash_1(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 2
found_match_2 = phantom.decision(
container=container,
conditions=[
["prompt_ban:action_result.summary.responses.0", "==", "Unban process hash"]
])
# call connected blocks if condition 2 matched
if found_match_2:
unban_hash_1(action=action, success=success, container=container, results=results, handle=handle)
return
return
@phantom.playbook_block()
def ban_hash_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("ban_hash_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.threat_cause_actor_sha256","artifact:*.id"])
parameters = []
# build parameters list for 'ban_hash_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"process_hash": container_artifact_item[0],
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("ban hash", parameters=parameters, name="ban_hash_1", assets=["dev01"])
return
@phantom.playbook_block()
def unban_hash_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("unban_hash_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.threat_cause_actor_sha256","artifact:*.id"])
parameters = []
# build parameters list for 'unban_hash_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"process_hash": container_artifact_item[0],
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("unban hash", parameters=parameters, name="unban_hash_1", assets=["dev01"])
return
@phantom.playbook_block()
def prompt_quarantine(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("prompt_quarantine() called")
# set user and message variables for phantom.prompt call
user = "admin"
message = """Quarantine or unquarantine device"""
# parameter list for template variable replacement
parameters = []
# responses
response_types = [
{
"prompt": "Choose action",
"options": {
"type": "list",
"choices": [
"Quarantine",
"Unquarantine"
],
},
}
]
phantom.prompt2(container=container, user=user, message=message, respond_in_mins=30, name="prompt_quarantine", parameters=parameters, response_types=response_types, callback=decision_4)
return
@phantom.playbook_block()
def decision_4(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("decision_4() called")
# check for 'if' condition 1
found_match_1 = phantom.decision(
container=container,
conditions=[
["prompt_quarantine:action_result.summary.responses.0", "==", "Quarantine"]
])
# call connected blocks if condition 1 matched
if found_match_1:
quarantine_device_1(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 2
found_match_2 = phantom.decision(
container=container,
conditions=[
["prompt_quarantine:action_result.summary.responses.0", "==", "Unquarantine"]
])
# call connected blocks if condition 2 matched
if found_match_2:
unquarantine_device_1(action=action, success=success, container=container, results=results, handle=handle)
return
return
@phantom.playbook_block()
def quarantine_device_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("quarantine_device_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.deviceExternalId","artifact:*.id"])
parameters = []
# build parameters list for 'quarantine_device_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"device_id": container_artifact_item[0],
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("quarantine device", parameters=parameters, name="quarantine_device_1", assets=["dev01"])
return
@phantom.playbook_block()
def unquarantine_device_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("unquarantine_device_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.deviceExternalId","artifact:*.id"])
parameters = []
# build parameters list for 'unquarantine_device_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"device_id": container_artifact_item[0],
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("unquarantine device", parameters=parameters, name="unquarantine_device_1", assets=["dev01"])
return
@phantom.playbook_block()
def prompt_dismiss(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("prompt_dismiss() called")
# set user and message variables for phantom.prompt call
user = "admin"
message = """Dismiss this alert only or dismiss all future alerts with that threat_id?"""
# parameter list for template variable replacement
parameters = []
# responses
response_types = [
{
"prompt": "Choose Action",
"options": {
"type": "list",
"choices": [
"Dismiss alert",
"Dismiss all future alerts"
],
},
}
]
phantom.prompt2(container=container, user=user, message=message, respond_in_mins=30, name="prompt_dismiss", parameters=parameters, response_types=response_types, callback=decision_5)
return
@phantom.playbook_block()
def decision_5(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("decision_5() called")
# check for 'if' condition 1
found_match_1 = phantom.decision(
container=container,
conditions=[
["prompt_dismiss:action_result.summary.responses.0", "==", "Dismiss alert"]
])
# call connected blocks if condition 1 matched
if found_match_1:
dismiss_alert_1(action=action, success=success, container=container, results=results, handle=handle)
return
# check for 'elif' condition 2
found_match_2 = phantom.decision(
container=container,
conditions=[
["prompt_dismiss:action_result.summary.responses.0", "==", "Dismiss all future alerts"]
])
# call connected blocks if condition 2 matched
if found_match_2:
dismiss_future_alerts_1(action=action, success=success, container=container, results=results, handle=handle)
return
return
@phantom.playbook_block()
def dismiss_alert_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("dismiss_alert_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.id","artifact:*.id"])
parameters = []
# build parameters list for 'dismiss_alert_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"alert_id": container_artifact_item[0],
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("dismiss alert", parameters=parameters, name="dismiss_alert_1", assets=["dev01"])
return
@phantom.playbook_block()
def get_live_query_url_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("get_live_query_url_2() called")
asset_name_value = container.get("asset_name", None)
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.deviceExternalId","artifact:*.id"])
container_artifact_cef_item_0 = [item[0] for item in container_artifact_data]
parameters = []
parameters.append({
"asset": asset_name_value,
"device_id": container_artifact_cef_item_0,
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.custom_function(custom_function="cbc-playbooks/get_live_query_url", parameters=parameters, name="get_live_query_url_2", callback=prompt_2)
return
@phantom.playbook_block()
def dismiss_future_alerts_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("dismiss_future_alerts_1() called")
# phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
container_artifact_data = phantom.collect2(container=container, datapath=["artifact:*.cef.id","artifact:*.id"])
parameters = []
# build parameters list for 'dismiss_future_alerts_1' call
for container_artifact_item in container_artifact_data:
if container_artifact_item[0] is not None:
parameters.append({
"comment": "\"Dismissed by Splunk SOAR CBC App\"",
"alert_id": container_artifact_item[0],
"remediation_status": "\"fixed\"",
"context": {'artifact_id': container_artifact_item[1]},
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
phantom.act("dismiss future alerts", parameters=parameters, name="dismiss_future_alerts_1", assets=["dev01"])
return
@phantom.playbook_block()
def on_finish(container, summary):
phantom.debug("on_finish() called")
################################################################################
## Custom Code Start
################################################################################
# This function is called after all actions are completed.
# summary of all the action and/or all details of actions
# can be collected here.
# summary_json = phantom.get_summary()
# if 'result' in summary_json:
# for action_result in summary_json['result']:
# if 'action_run_id' in action_result:
# action_results = phantom.get_action_results(action_run_id=action_result['action_run_id'], result_data=False, flatten=False)
# phantom.debug(action_results)
################################################################################
## Custom Code End
################################################################################
return