-
Notifications
You must be signed in to change notification settings - Fork 1
/
Splunk_SOAR_Phantom_POC_AZ_Defender_IR_Status.py
230 lines (175 loc) · 8.17 KB
/
Splunk_SOAR_Phantom_POC_AZ_Defender_IR_Status.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
"""
"""
import phantom.rules as phantom
import json
from datetime import datetime, timedelta
@phantom.playbook_block()
def on_start(container):
phantom.debug('on_start() called')
# call 'debug_1' block
debug_1(container=container)
return
@phantom.playbook_block()
def debug_1(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None, custom_function=None, **kwargs):
phantom.debug("debug_1() called")
data_summary_requestid_value = container.get("data", {}).get("summary", {}).get("requestId", None)
data_summary_userid_value = container.get("data", {}).get("summary", {}).get("userId", None)
data_disposition_value = container.get("data", {}).get("disposition", None)
data_incidentId_value = container.get("data", {}).get("summary", {}).get("incidentId", None)
phantom.debug("data_incidentId_value: ")
phantom.debug( data_incidentId_value )
parameters = []
parameters.append({
"input_1": data_summary_requestid_value,
"input_2": data_summary_userid_value,
"input_3": data_incidentId_value,
"input_4": None,
"input_5": None,
"input_6": None,
"input_7": None,
"input_8": None,
"input_9": None,
"input_10": None,
})
################################################################################
## Custom Code Start
################################################################################
phantom.debug("DEBUG: Custom Code Start")
# replace:
# with: phantom.error
import json
import requests
import time
import array
import yaml
# for async
import asyncio
import logging
# for command line args
import sys
# get the byte size of a vars
from sys import getsizeof
# for file mamagment backup of JSON output etc..
import shutil
# for skipping cert errors in proxy
import ssl
# hiding warnings for ssl
import urllib3
# for setting OS env vars for proxy
import os
# for checking for files existing
import pathlib
# This is set to False when we enable proxy support later
VAR_SSL_FLAG = True
# regex
import re
# to check dates on last seen key
import datetime
# import dateutil.parser
#import pytz
#Sep 19, 12:22:26 : data_summary_userid_value: 36688b1d-1916-4b80-9627-218567ddec1b
#Sep 19, 12:22:26 : data_summary_requestid_value: b57f2a9e-a70e-4171-9be2-2b4f6c004300
#global data_summary_requestid_value
#global data_summary_userid_value
# WORKING !!!!
#data_summary_requestid_value="1747fb72-23f3-43ed-b763-798cd31fc100"
global headers
global access_token
#data_summary_requestid_value="c0234c93-80f3-42d2-9cf9-dbca84eaa000"
#data_summary_userid_value="36688b1d-1916-4b80-9627-218567ddec1b"
############################################ DANGER SECURTY ############
############################################ DANGER SECURTY ############
############################################ DANGER SECURTY ############
############################################ DANGER SECURTY ############
with open("config.yml", "w") as file:
lines = [
'{\r "app_id":"66f2dfec-e2a2-4e1a-ab21-432e30496f98",\r "app_id_secret":"gKK8Q~LxJbyYANK1wdAEz1Ou85nJG6oimyv8yc_a",\r "tenant_id":"666310ae-0b9d-4182-a5f8-8c8d8d802154"\r}']
file.writelines(lines)
file.close()
############################################ DANGER SECURTY ############
############################################ DANGER SECURTY ############
############################################ DANGER SECURTY ############
############################################ DANGER SECURTY ############
############################################################ FUNCTIONS
def LOADCONFIG():
phantom.debug("DEBUG: Running LOADCONFIG")
yaml.warnings({'YAMLLoadWarning': False})
Loader = yaml.FullLoader
with open("config.yml", 'r') as ymlfile:
cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)
global app_id
global app_id_secret
global tenant_id
app_id = (cfg['app_id'])
app_id_secret = (cfg['app_id_secret'])
tenant_id = (cfg['tenant_id'])
def PROXY():
phantom.error("DEBUG: Running PROXY")
os.environ["HTTP_PROXY"] = "http://127.0.0.1:8080"
os.environ["HTTPS_PROXY"] = "http://127.0.0.1:8080"
global VAR_SSL_FLAG
VAR_SSL_FLAG = False
# supress warnings for ssl
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
################################################################################ AUTH
def FUNC_AUTH():
print("DEBUG: Running FUNC_AUTH")
r = requests.post('https://login.windows.net/' + tenant_id + '/oauth2/token',
data={'resource': 'https://api.security.microsoft.com', 'client_id': app_id, 'client_secret': app_id_secret, 'grant_type': 'client_credentials'}, verify=VAR_SSL_FLAG)
if r.status_code in [200]:
# print("DEBUG: Status 200 OK!")
tok_dict = json.loads(r.text)
global access_token
access_token = tok_dict["access_token"]
# print("DEBUG: Access Token is: XXXXXXXXXXXXXXX ", access_token[-4:])
phantom.debug("200 STATUS CODE AUTH SUCCESS" )
phantom.debug(r.status_code)
phantom.debug(r.url)
phantom.debug(r.text)
phantom.debug(r.content)
phantom.debug("data_incidentId_value: ")
phantom.debug( data_incidentId_value )
else:
phantom.error(r.status_code)
phantom.error(r.url)
phantom.error(r.text)
phantom.error(r.content)
phantom.error("ERROR DID NOT GET 200 STATUS CODE AUTH FAILED")
global headers
headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"}
r = requests.patch('https://api.securitycenter.microsoft.com/api/incidents/' + data_incidentId_value , data=json.dumps(
{'status': 'resolved'}),
headers=headers, verify=VAR_SSL_FLAG)
if r.status_code in [200]:
phantom.debug("DEBUG: Status 200 OK incident updated ")
phantom.debug(r.status_code)
phantom.debug(r.url)
phantom.debug(r.text)
phantom.debug(r.content)
else:
phantom.error(r.status_code)
phantom.error(r.url)
phantom.error(r.text)
phantom.error(r.content)
phantom.error("ERROR DID NOT GET 200 STATUS CODE incident NOT updated ")
############################################################ MAIN
phantom.debug("DEBUG: MAIN")
LOADCONFIG()
FUNC_AUTH()
phantom.debug("DEBUG: Custom Code End")
################################################################################
## Custom Code End
################################################################################
#phantom.custom_function(custom_function="community/debug", parameters=parameters, name="debug_1")
return
@phantom.playbook_block()
def on_finish(container, summary):
phantom.debug("on_finish() called")
################################################################################
## Custom Code Start
################################################################################
# Write your custom code here...
################################################################################
## Custom Code End
################################################################################
return