forked from muratozfidan/playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphishing_investigate_and_respond.py
761 lines (568 loc) · 32.9 KB
/
phishing_investigate_and_respond.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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
"""
This playbook investigates and remediates phishing emails with Admin approval.
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
##############################
# Start - Global Code Block
"""
This playbook is deigned to perform the investigative steps necessary to investigate a potential Phishing attempt. It will process File attachments, IPs, domains, and URLs. If there is a positive, the Admin user group on Phantom will have 6 hours to respond to the prompt in order to have the email deleted from the exchange server.
"""
def test_params(container, datapath, key_name):
params = []
items = set(phantom.collect(container, datapath, scope='all'))
for item in items:
params.append({key_name:item})
return params
# End - Global Code block
##############################
def on_start(container):
urls = test_params(container, 'artifact:*.cef.requestURL', 'url')
domains = test_params(container,'artifact:*.cef.destinationDnsDomain', 'domain')
ips = test_params(container, 'artifact:*.cef.destinationAddress', 'ip')
file_hashs = test_params(container, 'artifact:*.cef.cs6', 'hash')
#if no file hashes this way, lets see if there is a vault item that has been added manually)
if not file_hashs:
vault_items = phantom.Vault.get_file_info(container_id=container['id'])
hashes = []
for vault_item in vault_items:
hashes.append({'hash': vault_item['metadata']['sha256']})
if file_hashs:
# call 'file_reputation_1' block
file_reputation_1(container=container)
if urls:
# call 'url_reputation_1' block
url_reputation_1(container=container)
if domains:
# call 'domain_reputation_1' block
domain_reputation_1(container=container)
if ips:
# call 'ip_reputation_1' block
ip_reputation_1(container=container)
if domains:
# call 'whois_infoDomain' block
whois_domain(container=container)
if ips:
# call 'whois_infoIP' block
whois_ip(container=container)
if ips:
# call 'geolocate_ip_1' block
geolocate_ip_1(container=container)
return
def decision_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('decision_1() called')
# check for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["prompt_1:action_result.summary.response", "==", "YES"],
])
# call connected blocks if condition 1 matched
if matched_artifacts_1 or matched_results_1:
delete_email_2(action=action, success=success, container=container, results=results, handle=handle)
return
return
def filter_3(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_3() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["detonate_file_1:action_result.summary.malware", "==", "yes"],
],
name="filter_3:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
join_hunt_file_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def file_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('file_reputation_1() called')
# collect data for 'file_reputation_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.cs6', 'artifact:*.id'])
parameters = []
# build parameters list for 'file_reputation_1' call
for container_item in container_data:
parameters.append({
'hash': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("file reputation", parameters=parameters, assets=['virustotal'], callback=filter_1, name="file_reputation_1")
return
def whois_ip(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('whois_ip() called')
# collect data for 'whois_ip' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.sourceAddress', 'artifact:*.id'])
parameters = []
# build parameters list for 'whois_ip' call
for container_item in container_data:
if container_item[0]:
parameters.append({
'ip': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("whois ip", parameters=parameters, assets=['domaintools'], name="whois_ip")
return
def whois_domain(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('whois_domain() called')
# collect data for 'whois_domain' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.destinationDnsDomain', 'artifact:*.id'])
parameters = []
# build parameters list for 'whois_domain' call
for container_item in container_data:
if container_item[0]:
parameters.append({
'domain': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("whois domain", parameters=parameters, assets=['whois'], name="whois_domain")
return
def geolocate_ip_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('geolocate_ip_1() called')
# collect data for 'geolocate_ip_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.destinationAddress', 'artifact:*.id'])
parameters = []
# build parameters list for 'geolocate_ip_1' call
for container_item in container_data:
if container_item[0]:
parameters.append({
'ip': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("geolocate ip", parameters=parameters, assets=['maxmind'], callback=filter_10, name="geolocate_ip_1")
return
def ip_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('ip_reputation_1() called')
# collect data for 'ip_reputation_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.destinationAddress', 'artifact:*.id'])
parameters = []
# build parameters list for 'ip_reputation_1' call
for container_item in container_data:
parameters.append({
'ip': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("ip reputation", parameters=parameters, assets=['virustotal'], callback=filter_8, name="ip_reputation_1")
return
def domain_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('domain_reputation_1() called')
# collect data for 'domain_reputation_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.destinationDnsDomain', 'artifact:*.id'])
parameters = []
# build parameters list for 'domain_reputation_1' call
for container_item in container_data:
if container_item[0]:
parameters.append({
'domain': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("domain reputation", parameters=parameters, assets=['opendns_investigate'], callback=filter_5, name="domain_reputation_1")
return
def filter_10(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_10() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["geolocate_ip_1:action_result.data.*.country_name", "in", "Burma,China,Eretrea,Iran,North Korea,Saudi Arabia,Sudan,Turkmenistan,Uzbekistan"],
],
name="filter_10:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
filter_14(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def filter_8(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_8() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["ip_reputation_1:action_result.summary.detected_urls", ">=", "1"],
],
name="filter_8:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
filter_13(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def filter_5(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_5() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["domain_reputation_1:action_result.status", "==", "MALICIOUS"],
],
name="filter_5:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
filter_15(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def filter_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_1() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["file_reputation_1:action_result.data.*.positives", "<=", "3"],
],
name="filter_1:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
detonate_file_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
# collect filtered artifact ids for 'if' condition 2
matched_artifacts_2, matched_results_2 = phantom.condition(
container=container,
action_results=results,
conditions=[
["file_reputation_1:action_result.data.*.positives", ">", "3"],
],
name="filter_1:condition_2")
# call connected blocks if filtered artifacts or results
if matched_artifacts_2 or matched_results_2:
join_hunt_file_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_2, filtered_results=matched_results_2)
return
def filter_6(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_6() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["detonate_url_1:action_result.data.*.threat.max-confidence", ">", 50],
],
name="filter_6:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
attribution(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def filter_4(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_4() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["url_reputation_1:action_result.data.*.positives", ">=", "1"],
],
name="filter_4:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
join_get_screenshot_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
# collect filtered artifact ids for 'if' condition 2
matched_artifacts_2, matched_results_2 = phantom.condition(
container=container,
action_results=results,
conditions=[
["url_reputation_1:action_result.data.*.positives", "<", "1"],
],
name="filter_4:condition_2")
# call connected blocks if filtered artifacts or results
if matched_artifacts_2 or matched_results_2:
detonate_url_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_2, filtered_results=matched_results_2)
return
def filter_13(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_13() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["ip_reputation_1:action_result.parameter.ip", "==", "artifact:*.cef.destinationAddress"],
],
name="filter_13:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
lookup_ip_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def hunt_file_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('hunt_file_1() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'hunt_file_1' call
passed_filtered_results_data_1 = phantom.collect2(container=container, datapath=["file_reputation_1:filtered-action_result.data.*.sha256", "file_reputation_1:filtered-action_result.parameter.context.artifact_id"], action_results=filtered_results)
parameters = []
# build parameters list for 'hunt_file_1' call
for passed_filtered_results_item_1 in passed_filtered_results_data_1:
parameters.append({
'hash': passed_filtered_results_item_1[0],
'range': "",
'type': "",
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': passed_filtered_results_item_1[1]},
})
phantom.act("hunt file", parameters=parameters, assets=['cbprotect','carbonblack','cylance_1'], callback=filter_2, name="hunt_file_1")
return
def join_hunt_file_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('join_hunt_file_1() called')
# if the joined function has already been called, do nothing
if phantom.get_run_data(key='join_hunt_file_1_called'):
return
# no callbacks to check, call connected block "hunt_file_1"
phantom.save_run_data(key='join_hunt_file_1_called', value='hunt_file_1', auto=True)
hunt_file_1(container=container, handle=handle)
return
def detonate_file_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'detonate_file_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.deviceCustomString6', 'artifact:*.id'])
vault_items = phantom.Vault.get_file_info(container_id=container['id'])
parameters = []
# build parameters list for 'detonate_file_1' call
for vault_item in vault_items:
if vault_item['vault_id']:
parameters.append({
'file_name': "",
'vault_id': vault_item['vault_id'],
})
if parameters:
phantom.act("detonate file", parameters=parameters, assets=['wildfire'], callback=filter_3, name="detonate_file_1")
else:
phantom.error("'detonate_file_1' will not be executed due to lack of parameters")
return
def get_sysinfo(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('get_sysinfo() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'get_sysinfo' call
results_data_1 = phantom.collect2(container=container, datapath=['hunt_file_1:action_result.data.*.process.results.*.hostname', 'hunt_file_1:action_result.parameter.context.artifact_id'], action_results=results)
parameters = []
# build parameters list for 'get_sysinfo' call
for results_item_1 in results_data_1:
if results_item_1[0]:
parameters.append({
'fields': "",
'hostname': results_item_1[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': results_item_1[1]},
})
phantom.act("get system attributes", parameters=parameters, assets=['domainctrl1'], callback=join_prompt_1, name="get_sysinfo")
return
def filter_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_2() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["hunt_file_1:action_result.data.*.computerId", "!=", "\"NULL\""],
],
name="filter_2:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
get_sysinfo(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def attribution(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('attribution() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'attribution' call
filtered_results_data_1 = phantom.collect2(container=container, datapath=["filtered-data:filter_6:condition_1:detonate_url_1:action_result.parameter.url", "filtered-data:filter_6:condition_1:detonate_url_1:action_result.parameter.context.artifact_id"])
parameters = []
# build parameters list for 'attribution' call
for filtered_results_item_1 in filtered_results_data_1:
if filtered_results_item_1[0]:
parameters.append({
'url': filtered_results_item_1[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': filtered_results_item_1[1]},
})
phantom.act("hunt url", parameters=parameters, assets=['isightpartners'], callback=join_get_screenshot_1, name="attribution")
return
def url_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('url_reputation_1() called')
# collect data for 'url_reputation_1' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.requestURL', 'artifact:*.id'])
parameters = []
# build parameters list for 'url_reputation_1' call
for container_item in container_data:
parameters.append({
'url': container_item[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("url reputation", parameters=parameters, assets=['virustotal'], callback=filter_4, name="url_reputation_1")
return
def delete_email_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('delete_email_2() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
name_value = container.get('name', None)
# collect data for 'delete_email_2' call
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.sourceUserName', 'artifact:*.id'])
parameters = []
# build parameters list for 'delete_email_2' call
for container_item in container_data:
if container_item[0]:
parameters.append({
'from': container_item[0],
'user': "",
'ip_hostname': "exchange_server",
'subject': name_value,
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': container_item[1]},
})
phantom.act("delete email", parameters=parameters, assets=['domainctrl1'], name="delete_email_2")
return
def filter_11(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_11() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["domain_reputation_2:action_result.summary.domain_status", "==", "MALICIOUS"],
],
name="filter_11:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
join_prompt_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def prompt_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('prompt_1() called')
# set user and message variables for phantom.prompt call
user = "Administrator"
message = """An email is being marked as a Phish attempt. Please inspect and approve so that Phantom can delete all instances of the phish from your mail server. If you do not respond within 6 hours (360 Minutes) the email will _NOT_ be deleted. If you respond \"Yes\" Phantom will start the removal of the phish from all mailboxes on your mail server. All enrichment data is in MIssion Control for your review."""
# response options
options = {
"type": "list",
"choices": [
"Yes",
"No",
]
}
phantom.prompt(container=container, user=user, message=message, respond_in_mins=360, name="prompt_1", options=options, callback=decision_1)
return
def join_prompt_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('join_prompt_1() called')
# if the joined function has already been called, do nothing
if phantom.get_run_data(key='join_prompt_1_called'):
return
# check if all connected incoming actions are done i.e. have succeeded or failed
if phantom.actions_done([ 'domain_reputation_2', 'domain_reputation_1' ]):
# save the state that the joined function has now been called
phantom.save_run_data(key='join_prompt_1_called', value='prompt_1')
# call connected block "prompt_1"
prompt_1(container=container, handle=handle)
return
def filter_14(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_14() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["geolocate_ip_1:artifact:*.cef.destinationAddress", "==", "artifact:*.cef.destinationAddress"],
],
name="filter_14:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
join_prompt_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def get_screenshot_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('get_screenshot_1() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'get_screenshot_1' call
filtered_results_data_1 = phantom.collect2(container=container, datapath=["filtered-data:filter_4:condition_1:url_reputation_1:action_result.parameter.url", "filtered-data:filter_4:condition_1:url_reputation_1:action_result.parameter.context.artifact_id"])
parameters = []
# build parameters list for 'get_screenshot_1' call
for filtered_results_item_1 in filtered_results_data_1:
if filtered_results_item_1[0]:
parameters.append({
'url': filtered_results_item_1[0],
'size': "",
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': filtered_results_item_1[1]},
})
phantom.act("get screenshot", parameters=parameters, assets=['screenshot machine'], callback=join_prompt_1, name="get_screenshot_1")
return
def join_get_screenshot_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('join_get_screenshot_1() called')
# if the joined function has already been called, do nothing
if phantom.get_run_data(key='join_get_screenshot_1_called'):
return
# no callbacks to check, call connected block "get_screenshot_1"
phantom.save_run_data(key='join_get_screenshot_1_called', value='get_screenshot_1', auto=True)
get_screenshot_1(container=container, handle=handle)
return
def domain_reputation_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('domain_reputation_2() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'domain_reputation_2' call
results_data_1 = phantom.collect2(container=container, datapath=['lookup_ip_1:action_result.summary.hostname', 'lookup_ip_1:action_result.parameter.context.artifact_id'], action_results=results)
parameters = []
# build parameters list for 'domain_reputation_2' call
for results_item_1 in results_data_1:
if results_item_1[0]:
parameters.append({
'domain': results_item_1[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': results_item_1[1]},
})
phantom.act("domain reputation", parameters=parameters, assets=['opendns_investigate'], callback=filter_11, name="domain_reputation_2", parent_action=action)
return
def detonate_url_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('detonate_url_1() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'detonate_url_1' call
results_data_1 = phantom.collect2(container=container, datapath=['url_reputation_1:action_result.data.*.resource', 'url_reputation_1:action_result.parameter.context.artifact_id'], action_results=results)
parameters = []
# build parameters list for 'detonate_url_1' call
for results_item_1 in results_data_1:
if results_item_1[0]:
parameters.append({
'url': results_item_1[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': results_item_1[1]},
})
phantom.act("detonate url", parameters=parameters, assets=['threatgrid'], callback=filter_6, name="detonate_url_1")
return
def filter_15(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('filter_15() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["domain_reputation_1:action_result.parameter.domain", "==", "artifact:*.cef.destinationDnsDomain"],
],
name="filter_15:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
join_prompt_1(action=action, success=success, container=container, results=results, handle=handle, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
def lookup_ip_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('lookup_ip_1() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'lookup_ip_1' call
passed_filtered_results_data_1 = phantom.collect2(container=container, datapath=["ip_reputation_1:filtered-action_result.parameter.ip", "ip_reputation_1:filtered-action_result.parameter.context.artifact_id"], action_results=filtered_results)
parameters = []
# build parameters list for 'lookup_ip_1' call
for passed_filtered_results_item_1 in passed_filtered_results_data_1:
if passed_filtered_results_item_1[0]:
parameters.append({
'ip': passed_filtered_results_item_1[0],
# context (artifact id) is added to associate results with the artifact
'context': {'artifact_id': passed_filtered_results_item_1[1]},
})
phantom.act("lookup ip", parameters=parameters, assets=['dns'], callback=domain_reputation_2, name="lookup_ip_1")
return
def on_finish(container, summary):
phantom.debug('on_finish() called')
# This function is called after all actions are completed.
# summary of all the action and/or all detals 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)
return