forked from phantomcyber/playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
otsec_action_check_audit_odd_process.py
204 lines (147 loc) · 8.3 KB
/
otsec_action_check_audit_odd_process.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
"""
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
def on_start(container):
phantom.debug('on_start() called')
# call 'Format_Asset_Lookup' block
Format_Asset_Lookup(container=container)
return
def Format_Audit_Endpoint_Process(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_Audit_Endpoint_Process() called')
template = """tag=application ComputerName=\"{1}\" sophos
| stats count by ComputerName, EngineVersion, PrimaryCIDLoc"""
# parameter list for template variable replacement
parameters = [
"Search_OT_Asset:action_result.data.*.ip",
"artifact:*.cef.dvc",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_Audit_Endpoint_Process")
Check_Audit_Endpoint_Process(container=container)
return
"""
Search for Access priv logins to the asset
"""
def Check_Audit_Endpoint_Process(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Check_Audit_Endpoint_Process() called')
#phantom.debug('Action: {0} {1}'.format(action['name'], ('SUCCEEDED' if success else 'FAILED')))
# collect data for 'Check_Audit_Endpoint_Process' call
formatted_data_1 = phantom.get_format_data(name='Format_Audit_Endpoint_Process')
parameters = []
# build parameters list for 'Check_Audit_Endpoint_Process' call
parameters.append({
'query': formatted_data_1,
'command': "",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk es - ot sec'], callback=filter_1, name="Check_Audit_Endpoint_Process")
return
def filter_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
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=[
["Check_Audit_Endpoint_Process:action_result.summary.total_events", ">", 0],
],
name="filter_1:condition_1")
# call connected blocks if filtered artifacts or results
if matched_artifacts_1 or matched_results_1:
Format_Pin_Audit_Endpoint_Process(action=action, success=success, container=container, results=results, handle=handle, custom_function=custom_function, filtered_artifacts=matched_artifacts_1, filtered_results=matched_results_1)
Add_Note_Format(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=[
["Check_Audit_Endpoint_Process:action_result.summary.total_events", "==", 0],
],
name="filter_1:condition_2")
# call connected blocks if filtered artifacts or results
if matched_artifacts_2 or matched_results_2:
pass
return
def Format_Pin_Audit_Endpoint_Process(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_Pin_Audit_Endpoint_Process() called')
template = """Total {0} Records Detected for Review"""
# parameter list for template variable replacement
parameters = [
"filtered-data:filter_1:condition_1:Check_Audit_Endpoint_Process:action_result.summary.total_events",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_Pin_Audit_Endpoint_Process")
Pin_Check_Audit_Endpoint_Process(container=container)
return
def Pin_Check_Audit_Endpoint_Process(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Pin_Check_Audit_Endpoint_Process() called')
formatted_data_1 = phantom.get_format_data(name='Format_Pin_Audit_Endpoint_Process')
phantom.pin(container=container, data=formatted_data_1, message="Check Audit Endpoint Process", name="Check Audit Endpoint Process")
return
def Add_Note_Format(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Add_Note_Format() called')
template = """|ComputerName|EngineVersion|PrimaryCIDLoc|count|
|--|--|--|--|
%%
|{0}|{1}|{2}|{3}|
%%"""
# parameter list for template variable replacement
parameters = [
"Check_Audit_Endpoint_Process:action_result.data.*.ComputerName",
"Check_Audit_Endpoint_Process:action_result.data.*.EngineVersion",
"Check_Audit_Endpoint_Process:action_result.data.*.PrimaryCIDLoc",
"Check_Audit_Endpoint_Process:action_result.data.*.count",
]
phantom.format(container=container, template=template, parameters=parameters, name="Add_Note_Format")
add_note_3(container=container)
return
def add_note_3(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('add_note_3() called')
formatted_data_1 = phantom.get_format_data(name='Add_Note_Format')
note_title = "Check Audit Endpoint Process"
note_content = formatted_data_1
note_format = "markdown"
phantom.add_note(container=container, note_type="general", title=note_title, content=note_content, note_format=note_format)
return
def Format_Asset_Lookup(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Format_Asset_Lookup() called')
template = """| `reverse_asset_lookup(\"{0}\")`
| strcat asset_vendor \" : \" asset_model asset_vendor_model
| rex field=zone \"level[_]*(?<zone_no>\\d+)\"
| mvexpand zone_no
| table asset asset_id asset_vendor_model asset_model asset_status asset_system asset_tag asset_type asset_vendor asset_version bunit category city classification country description dns exposure ip location mac nt_host owner pci_domain priority requires_av should_timesync should_update site_id vlan zone zone_no
| rex field=ip \"^(?P<net_local>\\d+\\.\\d+)\""""
# parameter list for template variable replacement
parameters = [
"artifact:*.cef.dvc",
]
phantom.format(container=container, template=template, parameters=parameters, name="Format_Asset_Lookup")
Search_OT_Asset(container=container)
return
def Search_OT_Asset(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug('Search_OT_Asset() called')
# collect data for 'Search_OT_Asset' call
formatted_data_1 = phantom.get_format_data(name='Format_Asset_Lookup')
parameters = []
# build parameters list for 'Search_OT_Asset' call
parameters.append({
'query': formatted_data_1,
'command': "",
'display': "",
'parse_only': "",
})
phantom.act(action="run query", parameters=parameters, assets=['splunk es - ot sec'], callback=Format_Audit_Endpoint_Process, name="Search_OT_Asset")
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 details of actions
# can be collected here.
# summary_json = phantom.get_summary()
# if 'result' in summary_json:
# for action_result in summary_json['result']:
# if 'action_run_id' in action_result:
# action_results = phantom.get_action_results(action_run_id=action_result['action_run_id'], result_data=False, flatten=False)
# phantom.debug(action_results)
return