-
Notifications
You must be signed in to change notification settings - Fork 18
/
mdm.sh
309 lines (295 loc) · 10.8 KB
/
mdm.sh
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
#!/bin/bash
credit() {
for i in {1..97}
do
echo ""
done
echo "============================================="
echo " MDM Tools by Kaitiz "
echo "============================================="
}
show_menu() {
credit
echo ""
echo "1. First Setup (Recovery)"
echo "2. Disable MDM Notification"
echo "3. Check MDM Enrollment (Terminal)"
echo "4. Quit"
echo ""
}
show_first_setup_menu() {
for i in {1..97}
do
echo ""
done
echo "============================================="
echo " First Setup (Recovery) "
echo "============================================="
echo ""
echo "1. Set Root Password (Recovery)"
echo "2. Apple Setup Done (Recovery)"
echo "3. Disable Root User (Terminal)"
echo "4. Back to Main Menu"
echo ""
}
show_disable_notification_menu() {
for i in {1..97}
do
echo ""
done
echo "============================================="
echo " MDM Enrollment Notification "
echo "============================================="
echo ""
echo "1. Disable DEP (Recovery)"
echo "2. Disable DEP (Terminal - Requires SIP to be disabled)"
echo "3. Check /etc/hosts file"
echo "4. Back to Main Menu"
echo ""
}
handle_choice() {
case $1 in
1)
handle_first_setup
;;
2)
handle_disable_notification
;;
3)
for i in {1..97}
do
echo ""
done
echo "============================================="
echo " Check MDM Enrollment "
echo "============================================="
echo ""
sudo profiles status -type enrollment
echo ""
sudo profiles show -type enrollment
echo ""
echo "- Note: Error is success -"
echo ""
read -p "Please press Enter to continue..."
;;
4)
echo "Quit. Goodbye!"
exit 0
;;
*)
echo "Invalid choice. Please select again."
;;
esac
}
ask_block_hosts() {
for i in {1..97}
do
echo ""
done
read -p "Do you want to block hosts? (Y/N): " block_choice
case $block_choice in
[Yy]* )
echo ""
sudo sed -i '' '/# MDM Servers/d' /Volumes/Macintosh\ HD/etc/hosts
sudo sed -i '' '/# End/d' /Volumes/Macintosh\ HD/etc/hosts
sudo sed -i '' '/deviceenrollment.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sudo sed -i '' '/mdmenrollment.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sudo sed -i '' '/iprofiles.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sudo sed -i '' '/acmdm.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sudo sed -i '' '/axm-adm-mdm.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
echo "# MDM Servers" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 deviceenrollment.apple.com" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 mdmenrollment.apple.com" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 iprofiles.apple.com" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 acmdm.apple.com" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 axm-adm-mdm.apple.com" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo "# End" | sudo tee -a /Volumes/Macintosh\ HD/etc/hosts
echo ""
echo "Blocked all MDM servers!"
echo ""
;;
[Nn]* )
echo ""
echo "Skipping host blocking."
;;
* )
echo "Invalid choice. Please enter Y or N."
ask_block_hosts
;;
esac
}
ask_block_hosts_recovery() {
for i in {1..97}
do
echo ""
done
read -p "Do you want to block hosts? (Y/N): " block_recovery_choice
case $block_recovery_choice in
[Yy]* )
echo ""
sed -i '' '/# MDM Servers/d' /Volumes/Macintosh\ HD/etc/hosts
sed -i '' '/# End/d' /Volumes/Macintosh\ HD/etc/hosts
sed -i '' '/deviceenrollment.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sed -i '' '/mdmenrollment.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sed -i '' '/iprofiles.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sed -i '' '/acmdm.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
sed -i '' '/axm-adm-mdm.apple.com/d' /Volumes/Macintosh\ HD/etc/hosts
echo "# MDM Servers" >> /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 deviceenrollment.apple.com" >> /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 mdmenrollment.apple.com" >> /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 iprofiles.apple.com" >> /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 acmdm.apple.com" >> /Volumes/Macintosh\ HD/etc/hosts
echo "0.0.0.0 axm-adm-mdm.apple.com" >> /Volumes/Macintosh\ HD/etc/hosts
echo "# End" >> /Volumes/Macintosh\ HD/etc/hosts
echo ""
echo "Blocked all MDM servers!"
echo ""
;;
[Nn]* )
echo ""
echo "Skipping host blocking."
;;
* )
echo "Invalid choice. Please enter Y or N."
ask_block_hosts_recovery
;;
esac
}
handle_first_setup() {
while true; do
show_first_setup_menu
read -p "Please choose one option (1-4): " sub_choice
for i in {1..97}
do
echo ""
done
case $sub_choice in
1)
for i in {1..97}
do
echo ""
done
if [ -d "/Volumes/Macintosh HD - Data" ]; then
diskutil rename "Macintosh HD - Data" "Data"
fi
echo ""
dscl -f /Volumes/Data/private/var/db/dslocal/nodes/Default localhost -passwd /Local/Default/Users/root
echo ""
ask_block_hosts_recovery
echo ""
echo "1. Please restart your Mac and select a language..."
echo "2. Press 'Command + Option + Control + T' at the same time to open Terminal."
echo "3. In Terminal, go to 'System Settings -> Users & Groups'."
echo "4. Select 'Add User' and input the username as 'root' and the password as the password you set above."
echo "5. Create an admin user account, then reboot your Mac to recovery, run the script again, and select 'Apple Setup Done'."
echo ""
read -p "Do you want to reboot now? (Y/N): " reboot_choice
case $reboot_choice in
[Yy]* )
reboot
;;
*)
echo "Returning to main menu..."
;;
esac
;;
2)
for i in {1..97}
do
echo ""
done
if [ -d "/Volumes/Macintosh HD - Data" ]; then
diskutil rename "Macintosh HD - Data" "Data"
fi
touch /Volumes/Data/private/var/db/.AppleSetupDone
echo ""
rm -rf /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigHasActivationRecord
rm -rf /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordFound
touch /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigProfileInstalled
touch /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordNotFound
ask_block_hosts_recovery
echo ""
read -p "Do you want to reboot now? (Y/N): " reboot_choice
case $reboot_choice in
[Yy]* )
reboot
;;
*)
echo "Returning to main menu..."
;;
esac
;;
3)
for i in {1..97}
do
echo ""
done
dsenableroot -d
echo ""
read -p "Please press Enter to continue..."
;;
4)
echo "Returning to the main menu."
return
;;
*)
echo "Invalid choice. Please select again."
;;
esac
done
}
handle_disable_notification() {
while true; do
show_disable_notification_menu
read -p "Please choose one option (1-4): " noti_choice
for i in {1..97}
do
echo ""
done
case $noti_choice in
1)
for i in {1..97}
do
echo ""
done
rm -rf /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigHasActivationRecord
rm -rf /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordFound
touch /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigProfileInstalled
touch /Volumes/Macintosh\ HD/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordNotFound
ask_block_hosts_recovery
echo ""
read -p "Please press Enter to continue..."
;;
2)
for i in {1..97}
do
echo ""
done
sudo rm /var/db/ConfigurationProfiles/Settings/.cloudConfigHasActivationRecord
sudo rm /var/db/ConfigurationProfiles/Settings/.cloudConfigRecordFound
sudo touch /var/db/ConfigurationProfiles/Settings/.cloudConfigProfileInstalled
sudo touch /var/db/ConfigurationProfiles/Settings/.cloudConfigRecordNotFound
ask_block_hosts
echo ""
read -p "Please press Enter to continue..."
;;
3)
cat /Volumes/Macintosh\ HD/etc/hosts
echo ""
read -p "Please press Enter to continue..."
;;
4)
echo "Returning to the main menu."
return
;;
*)
echo "Invalid choice. Please select again."
;;
esac
done
}
while true; do
show_menu
read -p "Please choose one option (1-4): " choice
handle_choice $choice
done