forked from phantomcyber/playbooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvestigate.py
1147 lines (860 loc) · 49.5 KB
/
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
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This Playbook uses custom code to execute a wide range of investigative queries across all available assets.
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
##############################
# Start - Global Code Block
import traceback
def asset_configured(action):
assets = phantom.get_assets(action=action)
if assets:
return True
return False
def get_filtered_assets(action=None, exclude_products=None, products=None):
supported_assets = phantom.get_assets(action=action)
if not supported_assets:
return []
#phantom.debug(supported_assets)
ret_assets=[]
if exclude_products:
raise ValueError("Error in get_filtered_assets(): excluded_products is no longer supported")
if products:
products = [x.lower() for x in products]
for asset in supported_assets:
if products:
if asset['product_name'].lower() in products:
ret_assets.append(asset['name'])
else:
if exclude_products:
if asset['product_name'].lower() not in exclude_products:
ret_assets.append(asset['name'])
else:
ret_assets.append(asset['name'])
ret_assets = list(set(ret_assets))
if not ret_assets:
ret_assets = None
return ret_assets
def escalate(container):
phantom.set_severity(container, "high")
def deescalate(container):
phantom.set_severity(container, "low")
phantom.close(container)
# checks across all hash info providers if the hash is bad or not
def is_file_bad(results):
if not results:
return []
any_success = False
for result in results:
if result['status'] == 'success':
any_success = True
if not any_success:
return []
# users can override what they think is tha appropriate thershold
VT_BAD_THRESHOLD = 5
RL_BAD_THRESHOLD = 6
AUTOFOCUS_TAGS_THRESHOLD = 1
THREATSCAPE_REPORTS_THRESHOLD = 1
ret_data=[]
try:
ACTION_INDEX=0
APP_INDEX=1
STATUS_INDEX=2
HASH_INDEX=3
ARTIFACT_ID_INDEX=4
collected = phantom.collect2(action_results=results,
datapath=["action", #0
"app", #1
"status", #2
"action_result.parameter.hash", #3
"action_result.parameter.context.artifact_id", #4
# Action specific datapaths
#5 'file reputation' of Reversing Labs and VirusTotal
"action_result.summary.positives", #5
#6 'file reputation' of ThreatGrid
"action_result.threatgrid.score", #6
#7 'hunt file' of AutoFocus
"action_result.summary.total_tags_matched", #7
#8 'hunt file' of ThreatScape
"action_result.summary.reports_matched" #8
])
#phantom.debug(collected)
for item in collected:
ret_item = {}
ret_item['hash'] = item[HASH_INDEX]
ret_item['artifact_id'] = item[ARTIFACT_ID_INDEX]
if item[ACTION_INDEX] == "file reputation" and item[APP_INDEX] == "ReversingLabs" and item[STATUS_INDEX] == "success":
if item[HASH_INDEX] and item[ARTIFACT_ID_INDEX] and item[5]:
ret_item['bad']= item[5] > RL_BAD_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "file reputation" and item[APP_INDEX] == "VirusTotal" and item[STATUS_INDEX] == "success":
if item[HASH_INDEX] and item[ARTIFACT_ID_INDEX] and item[5]:
ret_item['bad']= item[5] > RL_BAD_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt file" and item[APP_INDEX] == "AutoFocus" and item[STATUS_INDEX] == "success":
if item[HASH_INDEX] and item[ARTIFACT_ID_INDEX] and item[7]:
ret_item['bad']= item[7] > AUTOFOCUS_TAGS_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt file" and item[APP_INDEX] == "ThreatScape" and item[STATUS_INDEX] == "success":
if item[HASH_INDEX] and item[ARTIFACT_ID_INDEX] and item[8]:
ret_item['bad']= item[8] > THREATSCAPE_REPORTS_THRESHOLD
ret_data.append(ret_item)
continue
except:
phantom.error("Exception ocurred in parsing results: {}".format(traceback.format_exc()))
return ret_data
# checks across all domain info providers if the domain is bad or not
def is_domain_bad(results):
if not results:
return []
any_success = False
for result in results:
if result['status'] == 'success':
any_success = True
if not any_success:
return []
ODNS_MALICIOUS = 'MALICIOUS'
ATS_THREATSCORE = 70
POSITIVES_THRESHOLD = 5
ODNS_KP = 'NORTH KOREA'
DT_KP = 'kp'
ATS_KP = 'North Korea'
WHOIS_KP = 'KP'
ret_data=[]
try:
#phantom.debug("domain investigation results: {}".format(results))
ACTION_INDEX=0
APP_INDEX=1
STATUS_INDEX=2
DOMAIN_INDEX=3
ARTIFACT_ID_INDEX=4
collected = phantom.collect2(action_results=results,
datapath=["action", #0
"app", #1
"status", #2
"action_result.parameter.domain", #3
"action_result.parameter.context.artifact_id", #4
# Action specific data paths
#5: 'domain reputation' from OpenDNS Investigate
"action_result.summary.domain_status", #5
#6: 'domain reputation' from Passive Total
"action_result.summary.being_watched", #6
#7: 'domain reputation' from ThreatStream
"action_result.data.*.threatscore", #7
#8: 'domain reputation' from URLVoid
"action_result.summary.positives", #8
#9: 'domain reputation' from VirusTotal
"action_result.summary.detected_urls", #9
#10: 'hunt domain' from AutoFocus
"action_result.summary.total_tags_matched", #10
#11: 'hunt domain' from ThreatScape
"action_result.summary.reports_matched", #11
#12: 'reverse domain' from DomainTools
"action_result.summary.total_ips", #12
#13: 'whois domain' from DomainTools
"action_result.summary.country", #13
#14: 'whois domain' from OpenDNSInvestigate
"action_result.data.*.registrantCountry", #14
#15: 'whois domain' from ThreatStream
"action_result.data.*.contacts.registrant.country", #15
#16: 'whois domain' from Whois
"action_result.summary.country_code"]) #16
#phantom.debug(collected)
for item in collected:
ret_item = {}
ret_item['domain'] = item[DOMAIN_INDEX]
ret_item['artifact_id'] = item[ARTIFACT_ID_INDEX]
if item[ACTION_INDEX] == "domain reputation" and item[APP_INDEX] == "OpenDNS Investigate" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[5]:
ret_item['bad']= item[5] == ODNS_MALICIOUS
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "domain reputation" and item[APP_INDEX] == "PassiveTotal" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[6]:
ret_item['bad'] = item[6]
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "domain reputation" and item[APP_INDEX] == "ThreatStream" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[7]:
for threatscore in item[7]:
if ret_item['bad']: # checking if the value has been set yet
if ret_item['bad'] == False: # Checking if the threatscore threshold has been already met.
ret_item['bad']= threatscore > ATS_THREATSCORE
ret_data.append(ret_item)
continue
else:
ret_item['bad']= threatscore > ATS_THREATSCORE
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "domain reputation" and item[APP_INDEX] == "URLVoid" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[8]:
ret_item['bad']= item[8] > POSITIVES_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "domain reputation" and item[APP_INDEX] == "VirusTotal" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[9]:
ret_item['bad']= item[9] > POSITIVES_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt domain" and item[APP_INDEX] == "AutoFocus" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[10]:
ret_item['bad']= item[10] > POSITIVES_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt domain" and item[APP_INDEX] == "ThreatScape" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[11]:
ret_item['bad']= item[11] > POSITIVES_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "reverse domain" and item[APP_INDEX] == "DomainTools" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[12]:
ret_item['bad']= item[12] > POSITIVES_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "whois domain" and item[APP_INDEX] == "DomainTools" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[13]:
ret_item['bad']= item[13] == DT_KP
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "whois domain" and item[APP_INDEX] == "OpenDNS Investigate" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[14]:
for country in item[14]:
if ret_item['bad']: # checking if the value has been set yet
if ret_item['bad'] == False: # Checking if the 'bad' bit has been already met.
ret_item['bad']= item[14] == ODNS_KP
ret_data.append(ret_item)
continue
else:
ret_item['bad']= item[14] == ODNS_KP
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "whois domain" and item[APP_INDEX] == "ThreatStream" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[15]:
for country in item[15]:
if ret_item['bad']: # checking if the value has been set yet
if ret_item['bad'] == False: # Checking if the 'bad' bit has been already met.
ret_item['bad']= item[15] == ATS_KP
ret_data.append(ret_item)
continue
else:
ret_item['bad']= item[15] == ATS_KP
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "whois domain" and item[APP_INDEX] == "Whois" and item[STATUS_INDEX] == "success":
if item[DOMAIN_INDEX] and item[ARTIFACT_ID_INDEX] and item[16]:
ret_item['bad']= item[16] == WHOIS_KP
ret_data.append(ret_item)
continue
except:
phantom.error("Exception ocurred in parsing results: {}".format(traceback.format_exc()))
return ret_data
# checks across all url info providers if the hash is bad or not
def is_url_bad(results):
if not results:
return []
any_success = False
for result in results:
if result['status'] == 'success':
any_success = True
if not any_success:
return []
GENERAL_THRESHOLD = 5
ret_data=[]
try:
ACTION_INDEX=0
APP_INDEX=1
STATUS_INDEX=2
URL_INDEX=3
ARTIFACT_ID_INDEX=4
collected = phantom.collect2(action_results=results,
datapath=["action", #0
"app", #1
"status", #2
"action_result.parameter.url", #3
"action_result.parameter.context.artifact_id", #4
# Action specific datapaths
#5: 'hunt url' of AutoFocus
"action_result.summary.total_tags_matched", #5
#6: 'hunt url' of ThreatScape
"action_result.summary.reports_matched", #6
#7: 'url reputation' of VirusTotal
"action_result.summary.positives"]) #7
#phantom.debug(collected)
for item in collected:
ret_item = {}
ret_item['url'] = item[URL_INDEX]
ret_item['artifact_id'] = item[ARTIFACT_ID_INDEX]
if item[ACTION_INDEX] == "hunt url" and item[APP_INDEX] == "AutoFocus" and item[STATUS_INDEX] == "success":
if item[URL_INDEX] and item[ARTIFACT_ID_INDEX] and item[5]:
ret_item['bad']= item[5] > GENERAL_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt url" and item[APP_INDEX] == "ThreatScape" and item[STATUS_INDEX] == "success":
if item[URL_INDEX] and item[ARTIFACT_ID_INDEX] and item[6]:
ret_item['bad']= item[6] > GENERAL_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "url reputation" and item[APP_INDEX] == "VirusTotal" and item[STATUS_INDEX] == "success":
if item[URL_INDEX] and item[ARTIFACT_ID_INDEX] and item[7]:
ret_item['bad']= item[7] > GENERAL_THRESHOLD
ret_data.append(ret_item)
continue
except:
phantom.error("Exception ocurred in parsing results: {}".format(traceback.format_exc()))
return ret_data
# checks across all ip info providers if the hash is bad or not
def is_ip_bad(results):
if not results:
return []
any_success = False
for result in results:
if result['status'] == 'success':
any_success = True
if not any_success:
return []
ODNS_MALICIOUS = 'MALICIOUS'
THREATSCORE_THRESHOLD = 70
GENERAL_THRESHOLD = 5
DOMAIN_THRESHOLD = 100
LOW_KP = 'kp'
CAP_KP = 'KP'
ret_data=[]
try:
#phantom.debug("ip investigation results: {}".format(results))
ACTION_INDEX=0
APP_INDEX=1
STATUS_INDEX=2
IP_INDEX=3
ARTIFACT_ID_INDEX=4
collected = phantom.collect2(action_results=results,
datapath=["action", #0
"app", #1
"status", #2
"action_result.parameter.ip", #3
"action_result.parameter.context.artifact_id", #4
# Action specific datapaths
"action_result.data.*.country_iso_code", #5
"action_result.summary.total_tags_matched", #6
"action_result.summary.reports_matched", #7
"action_result.summary.ip_status", #8
"action_result.summary.being_watched", #9
"action_result.data.*.threatscore", #10
"action_result.summary.detected_urls", #11
"action_result.data.*.ip_addresses.domain_count", #12
"action_result.data.*.parsed_whois.networks.*.country", #13
"action_result.summary.country_code", #14
])
#phantom.debug(collected)
for item in collected:
ret_item = {}
ret_item['ip'] = item[IP_INDEX]
ret_item['artifact_id'] = item[ARTIFACT_ID_INDEX]
if item[ACTION_INDEX] == "geolocate ip" and item[APP_INDEX] == "GeoIP2" and item[STATUS_INDEX] == "success":
if item[5]:
ret_item['bad']= CAP_KP in item[5]
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt ip" and item[APP_INDEX] == "AutoFocus" and item[STATUS_INDEX] == "success":
if item[6]:
ret_item['bad']= item[6] > GENERAL_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "hunt ip" and item[APP_INDEX] == "ThreatScape" and item[STATUS_INDEX] == "success":
if item[7]:
ret_item['bad']= item[7] > GENERAL_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "ip reputation" and item[APP_INDEX] == "OpenDNS Investigate" and item[STATUS_INDEX] == "success":
if item[8]:
ret_item['bad']= item[8] == ODNS_MALICIOUS
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "ip reputation" and item[APP_INDEX] == "PassiveTotal" and item[STATUS_INDEX] == "success":
if item[9]:
ret_item['bad'] = item[9]
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "ip reputation" and item[APP_INDEX] == "ThreatStream" and item[STATUS_INDEX] == "success":
if item[10]:
for threatscore in item[10]:
if ret_item['bad']: # checking if the value has been set yet
if ret_item['bad'] == False: # Checking if the threatscore threshold has been already met.
ret_item['bad']= threatscore > THREATSCORE_THRESHOLD
ret_data.append(ret_item)
continue
else:
ret_item['bad']= threatscore > THREATSCORE_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "ip reputation" and item[APP_INDEX] == "VirusTotal" and item[STATUS_INDEX] == "success":
if item[11]:
ret_item['bad']= item[11] > GENERAL_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "reverse ip" and item[APP_INDEX] == "DomainTools" and item[STATUS_INDEX] == "success":
if item[12]:
for domain_count in item[12]:
if ret_item['bad']: # checking if the value has been set yet
if ret_item['bad'] == False: # Checking if the threatscore threshold has been already met.
ret_item['bad']= domain_count > DOMAIN_THRESHOLD
ret_data.append(ret_item)
continue
else:
ret_item['bad']= domain_count > DOMAIN_THRESHOLD
ret_data.append(ret_item)
continue
if item[ACTION_INDEX] == "whois ip" and item[APP_INDEX] == "Whois" and item[STATUS_INDEX] == "success":
if item[14]:
ret_item['bad']= item[14] == CAP_KP
ret_data.append(ret_item)
continue
except:
phantom.error("Exception ocurred in parsing results: {}".format(traceback.format_exc()))
return ret_data
# checks across user information to determine is user is bad
def is_user_bad(results):
return []
# End - Global Code block
##############################
def on_start(container):
set_status_open(container=container)
container_data = phantom.collect2(container=container, datapath=['artifact:*.cef.sourceAddress', #0
'artifact:*.cef.destinationAddress', #1
'artifact:*.cef.requestURL', #2
'artifact:*.cef.sourceDnsDomain', #3
'artifact:*.cef.destinationDnsDomain', #4
'artifact:*.cef.destinationUserName', #5
'artifact:*.cef.fileHash', #6
'artifact:*.id']) #7
# call 'geolocate_ip_1' block
geolocate_ip_1(container=container, handle=container_data)
# call 'hunt_ip_1' block
hunt_ip_1(container=container, handle=container_data)
# call 'lookup_ip_1' block
#lookup_ip_1(container=container, handle=container_data)
# call 'ip_reputation_1' block
ip_reputation_1(container=container, handle=container_data)
# call 'whois_ip_1' block
whois_ip_1(container=container, handle=container_data)
# call 'reverse_ip_1' block
reverse_ip_1(container=container, handle=container_data)
# call 'domain_reputation' block
domain_reputation(container=container, handle=container_data)
# call 'hunt_url_1' block
hunt_url_1(container=container, handle=container_data)
# call 'url_reputation_1' block
url_reputation_1(container=container, handle=container_data)
# call 'file_reputation_1' block
file_reputation_1(container=container, handle=container_data)
# call 'lookup_domain_1' block
lookup_domain_1(container=container, handle=container_data)
# call 'hunt_domain_1' block
hunt_domain_1(container=container, handle=container_data)
# call 'reverse_domain_1' block
reverse_domain_1(container=container, handle=container_data)
# call 'whois_domain_1' block
whois_domain_1(container=container, handle=container_data)
# call 'hunt_file_1' block
#hunt_file_1(container=container, handle=container_data)
return
def filter_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
if not success or not results:
return
data = is_url_bad(results)
for item in data:
if item['bad'] == True:
escalate(container)
return # if anyone reporting this as bad, no need to detonate
detonate_url_1(action=action, success=success, container=container, results=results, handle=data)
return
def filter_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
if not success or not results:
return
data = is_file_bad(results)
#phantom.debug("In decision_1.. data: {}".format(data))
for item in data:
if item['bad'] == True:
escalate(container)#phantom.set_severity(container, "high")
return # if anyone reporting this as bad, no need to detonate
get_file_1(action=action, success=success, container=container, results=results, handle=data)
return
def get_file_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
unique_file_hashes=[]
parameters = []
if handle:
for data in handle:
if data['bad'] == False:
if data['hash'] not in unique_file_hashes:
unique_file_hashes.append(data['hash'])
parameters.append({'hash': data['hash'],'context': {'artifact_id': data['artifact_id']}})
if parameters:
phantom.debug("get file with parameters: {}".format(parameters))
return
phantom.act("get file", parameters=parameters, assets=['carbonblack'], callback=detonate_file_1, name="get_file_1")
return
def detonate_file_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
phantom.debug('detonate_file_1() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'detonate_file_1' call
results_data_1 = phantom.collect2(container=container, datapath=['get_file_1:action_result.data.*.vault_id', 'get_file_1:action_result.parameter.context.artifact_id'], action_results=results)
parameters = []
# build parameters list for 'detonate_file_1' call
for results_item_1 in results_data_1:
if results_item_1[0]:
parameters.append({
'file_name': "",
'vault_id': 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 file", parameters=parameters, assets=['cuckoo'], name="detonate_file_1", parent_action=action)
return
def detonate_url_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
unique_urls=[]
parameters = []
if handle:
for data in handle:
if data['bad'] == False:
if data['url'] not in unique_urls:
unique_urls.append(data['url'])
parameters.append({'url': data['url'],'context': {'artifact_id': data['artifact_id']}})
if parameters:
phantom.debug("parameters for detonate file: {}".format(parameters))
return
phantom.act("detonate url", parameters=parameters, assets=['cuckoo'], name="detonate_url_1")
return
def geolocate_ip_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="geolocate ip", products=["GeoIP2"])
if not assets:
return
container_data = handle # in collected data, 0th item is source address and 1st item is destination address
parameters = []
# build parameters list for 'geolocate_ip_1' call
param_values=[]
for container_item in container_data:
if container_item[0]:
if container_item[0] not in param_values:
param_values.append(container_item[0])
parameters.append({'ip': container_item[0],'context': {'artifact_id': container_item[7]}})
if container_item[1]:
if container_item[1] not in param_values:
param_values.append(container_item[1])
parameters.append({'ip': container_item[1],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("geolocate ip", parameters=parameters, name="geolocate_ip_1", assets=assets)
return
def ip_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="ip reputation", products=["VirusTotal"])
if not assets:
return
container_data = handle # in collected data, 0th item is source address and 1st item is destination address
parameters = []
# build parameters list for 'ip_reputation_1' call
param_values=[]
for container_item in container_data:
if container_item[0]:
if container_item[0] not in param_values:
param_values.append(container_item[0])
parameters.append({'ip': container_item[0],'context': {'artifact_id': container_item[7]}})
if container_item[1]:
if container_item[1] not in param_values:
param_values.append(container_item[1])
parameters.append({'ip': container_item[1],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("ip reputation", parameters=parameters, name="ip_reputation_1", assets=assets)
return
def lookup_domain_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="lookup domain", products=["Passive DNS"])
if not assets:
return
container_data = handle # 3rd item is source domain and 4th item is destination domain
parameters = []
# build parameters list for 'lookup_domain_1' call
param_values=[]
for container_item in container_data:
if container_item[3]:
if container_item[3] not in param_values:
param_values.append(container_item[3])
parameters.append({'domain': container_item[3],'context': {'artifact_id': container_item[7]}})
if container_item[4]:
if container_item[4] not in param_values:
param_values.append(container_item[4])
parameters.append({'domain': container_item[4],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("lookup domain", parameters=parameters, name="lookup_domain_1", assets=assets)
return
def domain_reputation(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="domain reputation", products=["URLVoid"])
if not assets:
return
container_data = handle # 3rd item is source domain and 4th item is destination domain
parameters = []
# build parameters list for 'domain_reputation' call
param_values=[]
for container_item in container_data:
if container_item[3]:
if container_item[3] not in param_values:
param_values.append(container_item[3])
parameters.append({'domain': container_item[3],'context': {'artifact_id': container_item[7]}})
if container_item[4]:
if container_item[4] not in param_values:
param_values.append(container_item[4])
parameters.append({'domain': container_item[4],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("domain reputation", parameters=parameters, name="domain_reputation", assets=assets)
return
def whois_domain_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="whois domain", products=["DomainTools"])
if not assets:
return
container_data = handle # in collected data, 3rd item is source domain and 4th item is destination domain
parameters = []
# build parameters list for 'whois_domain_1' call
param_values=[]
for container_item in container_data:
if container_item[3]:
if container_item[3] not in param_values:
param_values.append(container_item[3])
parameters.append({'domain': container_item[3],'context': {'artifact_id': container_item[7]}})
if container_item[4]:
if container_item[4] not in param_values:
param_values.append(container_item[4])
parameters.append({'domain': container_item[4],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("whois domain", parameters=parameters, name="whois_domain_1", assets=assets)
return
def hunt_domain_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="hunt domain", products=["ThreatScape", "Falcon Host API"])
if not assets:
return
container_data = handle # 3rd item is source domain and 4th item is destination domain
parameters = []
# build parameters list for 'hunt_domain_1' call
param_values=[]
for container_item in container_data:
if container_item[3]:
if container_item[3] not in param_values:
param_values.append(container_item[3])
parameters.append({'domain': container_item[3],'context': {'artifact_id': container_item[7]}})
if container_item[4]:
if container_item[4] not in param_values:
param_values.append(container_item[4])
parameters.append({'domain': container_item[4],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("hunt domain", parameters=parameters, name="hunt_domain_1", assets=assets)
return
def reverse_domain_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets=get_filtered_assets(action="reverse domain", products=["DomainTools"])
if not assets:
return
container_data = handle # in collected data, 3rd item is source domain and 4th item is destination domain
parameters = []
# build parameters list for 'reverse_domain_1' call
param_values=[]
for container_item in container_data:
if container_item[3]:
if container_item[3] not in param_values:
param_values.append(container_item[3])
parameters.append({'domain': container_item[3],'context': {'artifact_id': container_item[7]}})
if container_item[4]:
if container_item[4] not in param_values:
param_values.append(container_item[4])
parameters.append({'domain': container_item[4],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("reverse domain", parameters=parameters, name="reverse_domain_1", assets=assets)
return
def reverse_ip_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="reverse ip", products=["HackerTarget"])
if not assets:
return
container_data = handle # in collected data, 0th item is source address and 1st item is destination address
parameters = []
# build parameters list for 'reverse_ip_1' call
param_values=[]
for container_item in container_data:
if container_item[0]:
if container_item[0] not in param_values:
param_values.append(container_item[0])
parameters.append({'ip': container_item[0],'context': {'artifact_id': container_item[7]}})
if container_item[1]:
if container_item[1] not in param_values:
param_values.append(container_item[1])
parameters.append({'ip': container_item[1],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("reverse ip", parameters=parameters, name="reverse_ip_1", assets=assets)
return
def hunt_url_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="hunt url", products=["FireAMP"])
if not assets:
return
container_data = handle # in collected data, 2nd item is request URL
parameters = []
# build parameters list for 'geolocate_ip_1' call
param_values=[]
for container_item in container_data:
if container_item[2]: # request URL
if container_item[2] not in param_values:
param_values.append(container_item[2])
parameters.append({'url': container_item[2],'scope': "",'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("hunt url", parameters=parameters, name="hunt_url_1", assets=assets)
return
def url_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="url reputation", products=["Safe Browsing", "VirusTotal"])
if not assets:
return
container_data = handle # in collected data, 2nd item is request URL
parameters = []
# build parameters list for 'url_reputation_1' call
param_values=[]
for container_item in container_data:
if container_item[2]:
url=''
if container_item[2].startswith("http"):
url=container_item[2]
else:
url = "http://"+container_item[2]
if url not in param_values:
param_values.append(url)
parameters.append({'url': url,'scope': "",'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("url reputation", parameters=parameters, name="url_reputation_1", assets=assets)
return
def file_reputation_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="file reputation", products=["TitaniumCloud", "ThreatStream"])
if not assets:
return
container_data = handle # 6th item is file hash
parameters = []
# build parameters list for 'geolocate_ip_1' call
param_values=[]
for container_item in container_data:
if container_item[6]:
if container_item[6] not in param_values:
param_values.append(container_item[6])
parameters.append({'hash': container_item[6],'context': {'artifact_id': container_item[7]}})
if parameters:
phantom.act("file reputation", parameters=parameters, name="file_reputation_1", callback=filter_1, assets=assets)
return
def whois_ip_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
assets = get_filtered_assets(action="whois ip", products=["Whois RDAP"])
if not asset_configured("whois ip"):
return
container_data = handle # in collected data, 0th item is source address and 1st item is destination address
parameters = []
# build parameters list for 'whois_ip_1' call