-
Notifications
You must be signed in to change notification settings - Fork 4
/
corelight_investigate_ip.py
1169 lines (867 loc) · 49.3 KB
/
corelight_investigate_ip.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 collects a variety of Corelight-observed network indicators from a suspect IP address. By default, it provides details on all traffic for the past 7 days, with an optional whitelist of CIDR blocks (one per line) in a custom list named IPWhitelist. If called with an optional time stamp parameter, it also compares connections made for the 5 days prior to that time stamp to the connections made between the time stamp and now, highlighting connections to new systems and the layer 7 service present for those connections.
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
def on_start(container):
phantom.debug('on_start() called')
# call 'MultiArtifact_StartTime' block
MultiArtifact_StartTime(container=container)
# call 'CalcLookbackWindow' block
CalcLookbackWindow(container=container)
return
"""
Calculate start of lookback window based on an offset from the current time. Window can be changed with the amount_to_modify and modification_unit items.
"""
def CalcLookbackWindow(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('CalcLookbackWindow() called')
literal_values_0 = [
[
-50,
"days",
],
]
parameters = []
for item0 in literal_values_0:
parameters.append({
'input_datetime': None,
'amount_to_modify': item0[0],
'modification_unit': item0[1],
'input_format_string': None,
'output_format_string': None,
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
# call custom function "community/datetime_modify", returns the custom_function_run_id
phantom.custom_function(custom_function='community/datetime_modify', parameters=parameters, name='CalcLookbackWindow', callback=CalcLookbackWindow_callback)
return
def CalcLookbackWindow_callback(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None):
phantom.debug('CalcLookbackWindow_callback() called')
Format_External_IP_Query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function)
Format_Internal_IP_Query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function)
return
"""
Format a query for all external connections from the suspect host between now and the previously calculated lookback window.
"""
def Format_External_IP_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_External_IP_Query() called')
template = """index=corelight sourcetype=corelight_conn {0} local_resp=\"false\" earliest={1} latest=now() | eval resp_cc=if(isnull(resp_cc), \" \", resp_cc) | fields dest_ip id.resp_p resp_cc service | stats count by dest_ip, service, id.resp_p, resp_cc | sort dest_ip, service"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_External_IP_Query")
Execute_External_IP_Query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_External_IP_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_External_IP_Query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_External_IP_Query' call
formatted_data_1 = phantom.get_format_data(name='Format_External_IP_Query')
parameters = []
# build parameters list for 'Execute_External_IP_Query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], callback=Remove_Whitelisted_IPs, name="Execute_External_IP_Query")
return
"""
Format a query for all internal connections from the suspect host between now and the previously calculated lookback window.
"""
def Format_Internal_IP_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_Internal_IP_Query() called')
template = """index=corelight sourcetype=corelight_conn {0} local_resp=\"true\" earliest={1} latest=now() | eval resp_cc=if(isnull(resp_cc), \" \", resp_cc) | fields dest_ip id.resp_p resp_cc service | stats count by dest_ip, service, id.resp_p, resp_cc | sort dest_ip, service"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_Internal_IP_Query")
Execute_Internal_IP_Query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_Internal_IP_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_Internal_IP_Query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_Internal_IP_Query' call
formatted_data_1 = phantom.get_format_data(name='Format_Internal_IP_Query')
parameters = []
# build parameters list for 'Execute_Internal_IP_Query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], callback=Execute_Internal_IP_Query_callback, name="Execute_Internal_IP_Query")
return
def Execute_Internal_IP_Query_callback(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None):
phantom.debug('Execute_Internal_IP_Query_callback() called')
Internal_Service_Filter(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function)
Format_Software_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function)
return
"""
Switch to different queries/notes based on detected service type
"""
def Service_Branch(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Service_Branch() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["filtered-data:Remove_Whitelisted_IPs:condition_1:Execute_External_IP_Query:action_result.data.*.service", "==", "http"],
],
name="Service_Branch:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
Format_HTTP_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, 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=[
["filtered-data:Remove_Whitelisted_IPs:condition_1:Execute_External_IP_Query:action_result.data.*.service", "==", "ssl"],
],
name="Service_Branch:condition_2")
# call connected blocks if filtered artifacts or results
if matched_artifacts_2 or matched_results_2:
Format_SSL_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_2, filtered_results=matched_results_2)
# collect filtered artifact ids for 'if' condition 3
matched_artifacts_3, matched_results_3 = phantom.condition(
container=container,
action_results=results,
conditions=[
["filtered-data:Remove_Whitelisted_IPs:condition_1:Execute_External_IP_Query:action_result.data.*.service", "==", "dns"],
],
name="Service_Branch:condition_3")
# call connected blocks if filtered artifacts or results
if matched_artifacts_3 or matched_results_3:
Format_DNS_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_3, filtered_results=matched_results_3)
# collect filtered artifact ids for 'if' condition 4
matched_artifacts_4, matched_results_4 = phantom.condition(
container=container,
action_results=results,
conditions=[
["filtered-data:Remove_Whitelisted_IPs:condition_1:Execute_External_IP_Query:action_result.data.*.service", "not in", "http,ssl,dns"],
],
name="Service_Branch:condition_4")
# call connected blocks if filtered artifacts or results
if matched_artifacts_4 or matched_results_4:
Format_service_note(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_4, filtered_results=matched_results_4)
return
"""
Format a query to collect HTTP indicators
"""
def Format_HTTP_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_HTTP_query() called')
template = """index=corelight sourcetype=corelight_http id_orig_h={0} earliest={1} latest=now() | spath host | table uid method host uri status_code resp_mime_types user_agent"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_HTTP_query")
Execute_HTTP_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_HTTP_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_HTTP_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_HTTP_query' call
formatted_data_1 = phantom.get_format_data(name='Format_HTTP_query')
parameters = []
# build parameters list for 'Execute_HTTP_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_HTTP_query")
return
"""
Format a query to collect SSL indicators
"""
def Format_SSL_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_SSL_query() called')
template = """index=corelight sourcetype=corelight_ssl src_ip={0} earliest={1} latest=now()| table uid subject validation_status version ja3 ja3s"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_SSL_query")
Execute_SSL_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_SSL_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_SSL_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_SSL_query' call
formatted_data_1 = phantom.get_format_data(name='Format_SSL_query')
parameters = []
# build parameters list for 'Execute_SSL_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_SSL_query")
return
"""
Format a query to collect DNS indicators
"""
def Format_DNS_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_DNS_query() called')
template = """index=corelight sourcetype=corelight_dns id.orig_h={0} earliest={1} latest=now() | table uid query answers qtype_name rcode_name"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_DNS_query")
Execute_DNS_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_DNS_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_DNS_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_DNS_query' call
formatted_data_1 = phantom.get_format_data(name='Format_DNS_query')
parameters = []
# build parameters list for 'Execute_DNS_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_DNS_query")
return
"""
Switch to different queries/notes based on detected service type
"""
def Internal_Service_Filter(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Internal_Service_Filter() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["Execute_Internal_IP_Query:action_result.data.*.service", "==", "\"*smb*\""],
],
name="Internal_Service_Filter:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
Format_SMB_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, 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=[
["Execute_Internal_IP_Query:action_result.data.*.service", "==", "\"*dce_rpc*\""],
],
name="Internal_Service_Filter:condition_2")
# call connected blocks if filtered artifacts or results
if matched_artifacts_2 or matched_results_2:
Format_DCE_RPC_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_2, filtered_results=matched_results_2)
# collect filtered artifact ids for 'if' condition 3
matched_artifacts_3, matched_results_3 = phantom.condition(
container=container,
action_results=results,
conditions=[
["Execute_Internal_IP_Query:action_result.data.*.service", "==", "\"*ntlm*\""],
],
name="Internal_Service_Filter:condition_3")
# call connected blocks if filtered artifacts or results
if matched_artifacts_3 or matched_results_3:
Format_NTLM_query(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_3, filtered_results=matched_results_3)
# collect filtered artifact ids for 'if' condition 4
matched_artifacts_4, matched_results_4 = phantom.condition(
container=container,
action_results=results,
conditions=[
["Execute_Internal_IP_Query:action_result.data.*.service", "==", "dns"],
],
name="Internal_Service_Filter:condition_4")
# call connected blocks if filtered artifacts or results
if matched_artifacts_4 or matched_results_4:
Format_DNS_query_2(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_4, filtered_results=matched_results_4)
# collect filtered artifact ids for 'if' condition 5
matched_artifacts_5, matched_results_5 = phantom.condition(
container=container,
action_results=results,
conditions=[
["Execute_Internal_IP_Query:action_result.data.*.service", "not in", "\"*smb*\",\"*dce_rpc*\",\"*ntlm*\",dns"],
],
name="Internal_Service_Filter:condition_5")
# call connected blocks if filtered artifacts or results
if matched_artifacts_5 or matched_results_5:
Extra_service_branch(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_5, filtered_results=matched_results_5)
return
"""
Format a query to collect SMB indicators
"""
def Format_SMB_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_SMB_query() called')
template = """index=corelight path=corelight_smb_files src_ip={0} earliest={1} latest=now | table uid dest_ip action name fuid"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_SMB_query")
Execute_SMB_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_SMB_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_SMB_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_SMB_query' call
formatted_data_1 = phantom.get_format_data(name='Format_SMB_query')
parameters = []
# build parameters list for 'Execute_SMB_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], callback=Format_SMB_Mappings_query, name="Execute_SMB_query")
return
"""
Format a query for all software passively detected by Corelight in the previously calculated lookback window.
"""
def Format_Software_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_Software_query() called')
template = """index=corelight sourcetype=corelight_software | spath host | search host=\"{0}\" | table *"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_Software_query")
Execute_Software_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_Software_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_Software_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_Software_query' call
formatted_data_1 = phantom.get_format_data(name='Format_Software_query')
parameters = []
# build parameters list for 'Execute_Software_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], callback=Format_Suricata_query, name="Execute_Software_query")
return
"""
Format a query to collect details about SMB shares connected to
"""
def Format_SMB_Mappings_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_SMB_Mappings_query() called')
template = """index=corelight path=corelight_smb_mapping src_ip={0} earliest={1} latest=now() | table uid dest_ip path service share_type"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_SMB_Mappings_query")
Execute_SMB_Mappings_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_SMB_Mappings_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_SMB_Mappings_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_SMB_Mappings_query' call
formatted_data_1 = phantom.get_format_data(name='Format_SMB_Mappings_query')
parameters = []
# build parameters list for 'Execute_SMB_Mappings_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_SMB_Mappings_query")
return
"""
Format a query to collect NTLM indicators
"""
def Format_NTLM_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_NTLM_query() called')
template = """index=corelight sourcetype=corelight_ntlm src_ip={0} earliest={1} latest=now() | table uid dest_ip domainname server_dns_computername server_nb_computername success"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_NTLM_query")
Execute_NTLM_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_NTLM_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_NTLM_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_NTLM_query' call
formatted_data_1 = phantom.get_format_data(name='Format_NTLM_query')
parameters = []
# build parameters list for 'Execute_NTLM_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_NTLM_query")
return
"""
Format a query to collect DCE/RPC indicators
"""
def Format_DCE_RPC_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_DCE_RPC_query() called')
template = """index=corelight sourcetype=corelight_dce_rpc src_ip={0} earliest={1} latest=now() | table uid dest_ip endpoint operation named_pipe"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_DCE_RPC_query")
Execute_DCE_RPC_query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_DCE_RPC_query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_DCE_RPC_query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_DCE_RPC_query' call
formatted_data_1 = phantom.get_format_data(name='Format_DCE_RPC_query')
parameters = []
# build parameters list for 'Execute_DCE_RPC_query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_DCE_RPC_query")
return
"""
Format a query to collect DNS indicators
"""
def Format_DNS_query_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_DNS_query_2() called')
template = """index=corelight sourcetype=corelight_dns src_ip={0} earliest={1} latest=now() | table uid query answers qtype_name rcode_name"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"CalcLookbackWindow:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_DNS_query_2")
Execute_DNS_query_2(container=container)
return
"""
Execute previously formatted query
"""
def Execute_DNS_query_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_DNS_query_2() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_DNS_query_2' call
formatted_data_1 = phantom.get_format_data(name='Format_DNS_query_2')
parameters = []
# build parameters list for 'Execute_DNS_query_2' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], name="Execute_DNS_query_2")
return
"""
Format a note indicating the presence of services beyond DNS, HTTP, or SSL, and the IP address of the remote device communicating over that service.
"""
def Format_service_note(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_service_note() called')
template = """%%
Service detected: {0} on {1}
%%"""
# parameter list for template variable replacement
parameters = [
"filtered-data:Service_Branch:condition_4:Execute_External_IP_Query:action_result.data.*.service",
"filtered-data:Remove_Whitelisted_IPs:condition_1:Execute_External_IP_Query:action_result.data.*.dest_ip",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_service_note")
Add_service_note(container=container)
return
"""
Add previously configured note
"""
def Add_service_note(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Add_service_note() called')
formatted_data_1 = phantom.get_format_data(name='Format_service_note')
note_title = "External service detection"
note_content = formatted_data_1
note_format = "html"
phantom.add_note(container=container, note_type="general", title=note_title, content=note_content, note_format=note_format)
return
"""
Optional whitelist for external IP addresses. Reads from Phantom built-in Custom List named IPWhitelist (if present), which is composed of CIDR blocks or single IP addresses, one per line.
"""
def Remove_Whitelisted_IPs(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Remove_Whitelisted_IPs() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["Execute_External_IP_Query:action_result.data.*.dest_ip", "not in", "custom_list:IPWhitelist"],
],
name="Remove_Whitelisted_IPs:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
Service_Branch(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
"""
Format a note indicating the presence of services beyond DNS, NTLM, SMB, or DCE/RPC, and the IP address of the remote device communicating over that service.
"""
def Format_other_service_note(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_other_service_note() called')
template = """%%
Service detected: {0} on {1}
%%"""
# parameter list for template variable replacement
parameters = [
"filtered-data:Internal_Service_Filter:condition_5:Execute_Internal_IP_Query:action_result.data.*.service",
"filtered-data:Internal_Service_Filter:condition_5:Execute_Internal_IP_Query:action_result.data.*.dest_ip",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_other_service_note")
Add_other_service_note(container=container)
return
"""
Add previously configured note
"""
def Add_other_service_note(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Add_other_service_note() called')
formatted_data_1 = phantom.get_format_data(name='Format_other_service_note')
note_title = "Internal service detection"
note_content = formatted_data_1
note_format = "html"
phantom.add_note(container=container, note_type="general", title=note_title, content=note_content, note_format=note_format)
return
"""
Only run comparative queries if a time of suspected compromise is supplied
"""
def MultiArtifact_StartTime(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('MultiArtifact_StartTime() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
conditions=[
["artifact:*.cef.startTime", "!=", ""],
],
name="MultiArtifact_StartTime:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
CalcPreCompromiseTime(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
"""
Calculate start of lookback window based on an offset from suspected time of compromise. Window can be changed with the amount_to_modify and modification_unit items.
"""
def CalcPreCompromiseTime(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('CalcPreCompromiseTime() called')
filtered_artifacts_data_0 = phantom.collect2(container=container, datapath=['filtered-data:MultiArtifact_StartTime:condition_1:artifact:*.cef.startTime'])
literal_values_0 = [
[
-5,
"days",
],
]
parameters = []
for item0 in filtered_artifacts_data_0:
for item1 in literal_values_0:
parameters.append({
'input_datetime': item0[0],
'amount_to_modify': item1[0],
'modification_unit': item1[1],
'input_format_string': None,
'output_format_string': None,
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
# call custom function "community/datetime_modify", returns the custom_function_run_id
phantom.custom_function(custom_function='community/datetime_modify', parameters=parameters, name='CalcPreCompromiseTime', callback=ConvertCompromiseTimeFormat)
return
"""
Search for all connections made by suspect host in the configured time window prior to time of potential compromise. This example focuses on services, but see https://docs.zeek.org/en/current/scripts/base/protocols/conn/main.zeek.html#type-Conn::Info for details on fields available for this analysis.
"""
def Format_PreCompromise_Service_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_PreCompromise_Service_Query() called')
template = """index=corelight sourcetype=corelight_conn src_ip={2} earliest={0} latest={1} | table service dest_ip | stats count by service, dest_ip"""
# parameter list for template variable replacement
parameters = [
"CalcPreCompromiseTime:custom_function_result.data.epoch_time",
"ConvertCompromiseTimeFormat:custom_function_result.data.epoch_time",
"artifact:*.cef.sourceAddress",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_PreCompromise_Service_Query")
Execute_PreCompromise_Service_Query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_PreCompromise_Service_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_PreCompromise_Service_Query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_PreCompromise_Service_Query' call
formatted_data_1 = phantom.get_format_data(name='Format_PreCompromise_Service_Query')
parameters = []
# build parameters list for 'Execute_PreCompromise_Service_Query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], callback=Format_PostCompromise_Service_Query, name="Execute_PreCompromise_Service_Query")
return
"""
Use community built-in to convert to epoch timestamp
"""
def ConvertCompromiseTimeFormat(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('ConvertCompromiseTimeFormat() called')
filtered_artifacts_data_0 = phantom.collect2(container=container, datapath=['filtered-data:MultiArtifact_StartTime:condition_1:artifact:*.cef.startTime'])
parameters = []
for item0 in filtered_artifacts_data_0:
parameters.append({
'input_datetime': item0[0],
'amount_to_modify': None,
'modification_unit': None,
'input_format_string': None,
'output_format_string': None,
})
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
# call custom function "community/datetime_modify", returns the custom_function_run_id
phantom.custom_function(custom_function='community/datetime_modify', parameters=parameters, name='ConvertCompromiseTimeFormat', callback=Format_PreCompromise_Service_Query)
return
"""
Search for all connections made by suspect host between the time of potential compromise and the current time. This example focuses on services, but see https://docs.zeek.org/en/current/scripts/base/protocols/conn/main.zeek.html#type-Conn::Info for details on fields available for this analysis.
"""
def Format_PostCompromise_Service_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_PostCompromise_Service_Query() called')
template = """index=corelight sourcetype=corelight_conn src_ip={0} earliest={1} latest=now() | table service dest_ip | stats count by service, dest_ip"""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.sourceAddress",
"ConvertCompromiseTimeFormat:custom_function_result.data.epoch_time",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_PostCompromise_Service_Query")
Execute_PostCompromise_Service_Query(container=container)
return
"""
Execute previously formatted query
"""
def Execute_PostCompromise_Service_Query(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Execute_PostCompromise_Service_Query() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Execute_PostCompromise_Service_Query' call
formatted_data_1 = phantom.get_format_data(name='Format_PostCompromise_Service_Query')
parameters = []
# build parameters list for 'Execute_PostCompromise_Service_Query' call
parameters.append({
'query': formatted_data_1,
'command': "search",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk-demo'], callback=New_Connections, name="Execute_PostCompromise_Service_Query")
return
"""
Check to see if any systems connected to since the time of suspected compromise were not connected to in the configured lookback window prior to time of suspected compromise.
"""
def New_Connections(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('New_Connections() called')
# collect filtered artifact ids for 'if' condition 1
matched_artifacts_1, matched_results_1 = phantom.condition(
container=container,
action_results=results,
conditions=[
["Execute_PostCompromise_Service_Query:action_result.data.*.dest_ip", "not in", "Execute_PreCompromise_Service_Query:action_result.data.*.dest_ip"],
],
name="New_Connections:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
Format_New_Systems_Note(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
return
"""