forked from mlcsec/Graphpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintune_enum.py
More file actions
380 lines (321 loc) · 16 KB
/
Copy pathintune_enum.py
File metadata and controls
380 lines (321 loc) · 16 KB
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
import requests
import json
from Graphpython.utils.helpers import print_yellow, print_green, print_red, get_user_agent, get_access_token
from Graphpython.utils.helpers import graph_api_get
################################
# Post-Auth Intune Enumeration #
################################
# get-manageddevices
def get_manageddevices(args):
print_yellow("[*] Get-ManagedDevices")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-userdevices
def get_userdevices(args):
if not args.id:
print_red("[-] Error: --id argument is required for Get-UserDevices command")
return
print_yellow("[*] Get-UserDevices")
print("=" * 80)
api_url = f"https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$filter=userPrincipalName eq '{args.id}'"
if args.select:
api_url += "&$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-caps
def get_caps(args):
print_yellow("[*] Get-CAPs")
print("=" * 80)
api_url = "https://graph.microsoft.com//beta/identity/conditionalAccess/policies"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-devicecategories
def get_devicecategories(args):
print_yellow("[*] Get-DeviceCategories")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCategories"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-devicecompliancesummary
def get_devicecompliancesummary(args):
print_yellow("[*] Get-DeviceComplianceSummary")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicyDeviceStateSummary"
if args.select:
api_url += "?$select=" + args.select
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.get(api_url, headers=headers)
if response.ok:
response_body = response.json()
for key, value in response_body.items():
if not key.startswith("@odata.context"):
pretty_value = json.dumps(value, indent=4)
print(f"{key}: {pretty_value}")
else:
print_red(f"[-] Failed to retrieve settings: {response.status_code}")
print_red(response.text)
print("=" * 80)
# get-deviceconfigurations
def get_deviceconfigurations(args):
print_yellow("[*] Get-DeviceConfigurations")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/deviceConfigurations"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-deviceconfigurationpolicysettings
def get_deviceconfigurationpolicysettings(args):
if not args.id:
print_red("[-] Error: --id argument is required for Get-DeviceConfigurationPolicySettings command")
return
print_yellow("[*] Get-DeviceConfigurationPolicySettings")
print("=" * 80)
api_url = f"https://graph.microsoft.com/beta/deviceManagement/configurationPolicies('{args.id}')/settings?expand=settingDefinitions"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.get(api_url, headers=headers)
if response.ok:
response_body = response.json()
for key, value in response_body.items():
if not key.startswith("@odata.context"):
pretty_value = json.dumps(value, indent=4)
print(f"{key}: {pretty_value}") # redo this
else:
print_red(f"[-] Failed to retrieve settings: {response.status_code}")
print_red(response.text)
print("=" * 80)
# get-deviceenrollmentconfigurations
def get_deviceenrollmentconfigurations(args):
print_yellow("[*] Get-DeviceEnrollmentConfigurations")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/deviceEnrollmentConfigurations"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-devicegrouppolicyconfigurations
def get_devicegrouppolicyconfigurations(args):
print_yellow("[*] Get-DeviceGroupPolicyConfigurations")
print("=" * 80)
api_url = "https://graph.microsoft.com/beta/deviceManagement/groupPolicyConfigurations"
if args.select:
api_url += "?$select=" + args.select
user_agent = get_user_agent(args)
headers = {
'Authorization': 'Bearer ' + get_access_token(args.token),
'Accept': 'application/json',
'User-Agent': user_agent
}
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
group_policies = response.json()
else:
print_red(f"[-] Error: API request failed with status code {response.status_code}")
group_policies = None
if group_policies and 'value' in group_policies:
for policy in group_policies['value']:
for key, value in policy.items():
print(f"{key} : {value}")
policy_id = policy.get('id')
if policy_id:
assignments_api_url = f"https://graph.microsoft.com/beta/deviceManagement/groupPolicyConfigurations/{policy_id}/assignments"
assignments_response = requests.get(assignments_api_url, headers=headers)
if assignments_response.status_code == 200:
assignments = assignments_response.json()
if not assignments.get('value'):
print_red("assignmentTarget: No assignments")
else:
print_green("assignmentTargets:")
for assignment in assignments.get('value', []):
if 'target' in assignment:
target = assignment['target']
odata_type = target.get('@odata.type', '').split('.')[-1]
if odata_type == 'exclusionGroupAssignmentTarget':
group_id = target.get('groupId', 'N/A')
print(f"- Excluded Group ID: {group_id}")
elif odata_type == 'allLicensedUsersAssignmentTarget':
print("- Assigned to all users")
elif odata_type == 'allDevicesAssignmentTarget':
print("- Assigned to all devices")
elif odata_type == 'groupAssignmentTarget':
group_id = target.get('groupId', 'N/A')
print(f"- Assigned to Group ID: {group_id}")
else:
print(f" {odata_type}: {target}")
else:
print_red("assignmentTarget: No assignments")
else:
print_red(f"[-] Error: API request for assignments failed with status code {assignments_response.status_code}")
print("\n")
print("=" * 80)
# get-devicegrouppolicydefinition
# - remove
def get_devicegrouppolicydefinition(args):
if not args.id:
print_red("[-] Error: --id argument is required for Get-DeviceGroupPolicyDefinition command")
return
print_yellow("[*] Get-DeviceGroupPolicyDefinition")
print("=" * 80)
api_url = f"https://graph.microsoft.com//beta/deviceManagement/groupPolicyConfigurations('{args.id}')/definitionValues?$expand=definition($select=id,classType,displayName,policyType,hasRelatedDefinitions,version,minUserCspVersion,minDeviceCspVersion)"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-roledefinitions
def get_roledefinitions(args):
print_yellow("[*] Get-RoleDefinitions")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/roleDefinitions"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-roleassignments
def get_roleassignments(args):
print_yellow("[*] Get-RoleAssignments")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/roleAssignments"
if args.select:
api_url += "?$select=" + args.select
graph_api_get(get_access_token(args.token), api_url, args)
print("=" * 80)
# get-devicecompliancepolicies
def get_devicecompliancepolicies(args):
print_yellow("[*] Get-DeviceCompliancePolicies")
print("=" * 80)
api_url = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies?$expand=scheduledActionsForRule($expand=scheduledActionConfigurations)"
if args.select:
api_url += "&$select=" + args.select
try:
user_agent = get_user_agent(args)
headers = {
"Authorization": f"Bearer {get_access_token(args.token)}",
"Accept": "application/json",
"User-Agent": user_agent
}
response = requests.get(api_url, headers=headers)
response.raise_for_status()
policies = response.json()
if policies and 'value' in policies:
for policy in policies['value']:
for key, value in policy.items():
if key not in ['assignments', 'scheduledActionsForRule']:
print(f"{key} : {value}")
# Display assignments for each policy
policy_id = policy.get('id')
if policy_id:
assignments_api_url = f"https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies('{policy_id}')/assignments"
assignments_response = requests.get(assignments_api_url, headers=headers)
assignments_response.raise_for_status()
assignments = assignments_response.json()
if not assignments.get('value'):
print_red("assignments: None")
else:
print_green("assignments:")
for assignment in assignments.get('value', []):
if 'target' in assignment:
target = assignment['target']
odata_type = target.get('@odata.type', '').split('.')[-1]
if odata_type == 'exclusionGroupAssignmentTarget':
group_id = target.get('groupId', 'N/A')
print(f"- Excluded Group ID: {group_id}")
elif odata_type == 'allLicensedUsersAssignmentTarget':
print("- Assigned to all users")
elif odata_type == 'allDevicesAssignmentTarget':
print("- Assigned to all devices")
elif odata_type == 'groupAssignmentTarget':
group_id = target.get('groupId', 'N/A')
print(f"- Assigned to Group ID: {group_id}")
else:
print(f"- {odata_type}: {target}")
# Display scheduled actions for rule
scheduled_actions = policy.get('scheduledActionsForRule', [])
if not scheduled_actions:
print_red("scheduledActionsForRule: None")
else:
print_green("scheduledActionsForRule:")
for action in scheduled_actions:
#print(f"- Config ID: {action.get('id')}")
for config in action.get('scheduledActionConfigurations', []):
print(f" - Action Type: {config.get('actionType')}")
print(f" - Grace Period Hours: {config.get('gracePeriodHours')}")
print(f" - Notification Template Type: {config.get('notificationTemplateType')}")
print("\n")
else:
print_red("[-] No data found")
except requests.exceptions.RequestException as ex:
print_red(f"[-] HTTP Error: {ex}")
print("=" * 80)
# get-deviceconfigurationpolicies
def get_deviceconfigurationpolicies(args):
print_yellow("[*] Get-DeviceConfigurationPolicies")
print("=" * 80)
api_url = "https://graph.microsoft.com/beta/deviceManagement/configurationPolicies"
if args.select:
api_url += "?$select=" + args.select
user_agent = get_user_agent(args)
headers = {
'Authorization': 'Bearer ' + get_access_token(args.token),
'Accept': 'application/json',
'User-Agent': user_agent
}
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
policies = response.json()
else:
print_red(f"[-] Error: API request failed with status code {response.status_code}")
policies = None
print("=" * 80)
if policies and 'value' in policies:
for policy in policies['value']:
for key, value in policy.items():
print(f"{key} : {value}")
if 'templateReference' in policy and 'templateDisplayName' in policy['templateReference']:
print(f"template: {policy['templateReference']['templateDisplayName']}")
# display assignments for each policy
policy_id = policy.get('id')
if policy_id:
assignments_api_url = f"https://graph.microsoft.com/beta/deviceManagement/configurationPolicies('{policy_id}')/assignments"
assignments_response = requests.get(assignments_api_url, headers=headers)
if assignments_response.status_code == 200:
assignments = assignments_response.json()
if not assignments.get('value'):
print_red("assignments: None")
else:
print_green("assignments:")
for assignment in assignments.get('value', []):
if 'target' in assignment:
target = assignment['target']
odata_type = target.get('@odata.type', '').split('.')[-1]
if odata_type == 'exclusionGroupAssignmentTarget':
group_id = target.get('groupId', 'N/A')
print(f"- Excluded Group ID: {group_id}")
elif odata_type == 'allLicensedUsersAssignmentTarget':
print("- Assigned to all users")
elif odata_type == 'allDevicesAssignmentTarget':
print("- Assigned to all devices")
elif odata_type == 'groupAssignmentTarget':
group_id = target.get('groupId', 'N/A')
print(f"- Assigned to Group ID: {group_id}")
else:
print(f"- {odata_type}: {target}")
else:
print_red(f"[-] Error: API request for assignments failed with status code {assignments_response.status_code}")
print("\n")
print("=" * 80)