-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcleanup.py
More file actions
182 lines (156 loc) · 5.57 KB
/
Copy pathcleanup.py
File metadata and controls
182 lines (156 loc) · 5.57 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
import requests
from Graphpython.utils.helpers import print_yellow, print_green, print_red, get_user_agent, get_access_token
###########
# Cleanup #
###########
# delete-user
def delete_user(args):
if not args.id:
print_red("[-] Error: --id argument is required for Delete-User command")
return
print_yellow("[*] Delete-User")
print("=" * 80)
api_url = f"https://graph.microsoft.com/v1.0/users/{args.id}"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.delete(api_url, headers=headers)
if response.ok:
print_green(f"[+] User deleted")
else:
print_red(f"[-] Failed to delete user: {response.status_code}")
print_red(response.text)
print("=" * 80)
# delete-group
def delete_group(args):
if not args.id:
print_red("[-] Error: --id argument is required for Delete-Group command")
return
print_yellow("[*] Delete-Group")
print("=" * 80)
api_url = f"https://graph.microsoft.com/v1.0/groups/{args.id}"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.delete(api_url, headers=headers)
if response.ok:
print_green(f"[+] Group deleted")
else:
print_red(f"[-] Failed to delete group: {response.status_code}")
print_red(response.text)
print("=" * 80)
# remove-groupmember
def remove_groupmember(args):
if not args.id:
print_red("[-] Error: --id groupid,objectid required for Remove-GroupMember command")
return
ids = args.id.split(',')
if len(ids) != 2:
print_red("[-] Please provide two IDs separated by a comma (group ID, object ID).")
return
group_id, member_id = ids[0].strip(), ids[1].strip()
print_yellow("[*] Remove-GroupMember")
print("=" * 80)
api_url = f"https://graph.microsoft.com/v1.0/groups/{group_id}/members/{member_id}/$ref"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.delete(api_url, headers=headers)
if response.ok:
print_green(f"[+] Group member removed")
else:
print_red(f"[-] Failed to remove group member: {response.status_code}")
print_red(response.text)
print("=" * 80)
# delete-application
def delete_application(args):
if not args.id:
print_red("[-] Error: --id argument is required for Delete-Application command")
return
print_yellow("[*] Delete-Application")
print("=" * 80)
api_url = f"https://graph.microsoft.com/v1.0/applications/{args.id}"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.delete(api_url, headers=headers)
if response.ok:
print_green(f"[+] Application deleted")
else:
print_red(f"[-] Failed to delete application: {response.status_code}")
print_red(response.text)
print("=" * 80)
# delete-device
def delete_device(args):
if not args.id:
print_red("[-] Error: --id argument is required for Delete-Device command")
return
print_yellow("[*] Delete-Device")
print("=" * 80)
api_url = f"https://graph.microsoft.com/v1.0/devices/{args.id}"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.delete(api_url, headers=headers)
if response.ok:
print_green(f"[+] Device deleted")
else:
print_red(f"[-] Failed to delete device: {response.status_code}")
print_red(response.text)
print("=" * 80)
# wipe-device
def wipe_device(args):
if not args.id:
print_red("[-] Error: --id argument is required for Wipe-Device command")
return
print_yellow("[*] Wipe-Device")
print("=" * 80)
api_url = f"https://graph.microsoft.com/beta/deviceManagement/managedDevices/{args.id}/wipe"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'Content-Type': 'application/json',
'User-Agent': user_agent
}
body = {
"keepEnrollmentData": True,
"keepUserData": True,
"useProtectedWipe": False
}
response = requests.post(api_url, headers=headers, json=body)
if response.ok:
print_green(f"[+] Device wipe initiated successfully")
else:
print_red(f"[-] Failed to initiate device wipe: {response.status_code}")
print_red(response.text)
print("=" * 80)
# retire-device
def retire_device(args):
if not args.id:
print_red("[-] Error: --id argument is required for Retire-Device command")
return
print_yellow("[*] Retire-Device")
print("=" * 80)
api_url = f"https://graph.microsoft.com/beta/deviceManagement/managedDevices/{args.id}/retire"
user_agent = get_user_agent(args)
headers = {
'Authorization': f'Bearer {get_access_token(args.token)}',
'User-Agent': user_agent
}
response = requests.post(api_url, headers=headers)
if response.ok:
print_green(f"[+] Device retire initiated successfully")
else:
print_red(f"[-] Failed to initiate device retire: {response.status_code}")
print_red(response.text)
print("=" * 80)