feat: add heal, persist, unpersist commands with LaunchDaemon support
- New 'heal' command: checks MDM suppression state and re-applies if needed - New 'persist' command: installs LaunchDaemon for boot-time auto-heal - New 'unpersist' command: removes the persistence LaunchDaemon - Interactive menu updated for all new commands - Heal works from both Recovery and booted system (sudo) - Updated README with full documentation for heal/persist/unpersist - macOS Tahoe 26.x added to compatibility list
This commit is contained in:
@@ -96,6 +96,41 @@ Creates a temporary admin account and suppresses MDM enrollment.
|
||||
|
||||
> **Must run from Recovery mode.**
|
||||
|
||||
### `unleash heal` — Auto-Heal
|
||||
|
||||
Checks if MDM suppression is still active and re-applies it if any component has been reset (e.g., after a macOS update). Safe to run from a booted system:
|
||||
|
||||
```bash
|
||||
sudo ./unleash heal # from booted system
|
||||
./unleash heal # from Recovery mode
|
||||
```
|
||||
|
||||
**What it checks:**
|
||||
1. DEP marker files — are they still cleared?
|
||||
2. Hosts file — are MDM domains still blocked?
|
||||
3. Launchd disabled.plist — are enrollment daemons still disabled?
|
||||
4. If any check fails, re-runs `suppress_enrollment` to restore suppression
|
||||
|
||||
### `unleash persist` — Boot-Time Persistence
|
||||
|
||||
Installs a LaunchDaemon that runs `unleash heal` automatically on every boot and every 24 hours:
|
||||
|
||||
```bash
|
||||
sudo ./unleash persist # from booted system
|
||||
./unleash persist # from Recovery mode
|
||||
```
|
||||
|
||||
Creates `/Library/LaunchDaemons/com.unleash.heal.plist`. Logs are written to `/var/log/unleash-heal.log` and `/var/log/unleash-heal.err`.
|
||||
|
||||
### `unleash unpersist` — Remove Persistence
|
||||
|
||||
Removes the LaunchDaemon installed by `unleash persist`:
|
||||
|
||||
```bash
|
||||
sudo ./unleash unpersist # from booted system
|
||||
./unleash unpersist # from Recovery mode
|
||||
```
|
||||
|
||||
### `unleash suppress` — Suppress Only
|
||||
|
||||
Suppresses MDM enrollment without creating a user. Ideal after a clean bypass breaks (e.g., after macOS update).
|
||||
@@ -456,8 +491,8 @@ unleash/
|
||||
|
||||
## FAQ
|
||||
|
||||
**Q: Does this work on macOS Sequoia?**
|
||||
A: Yes. Tested up to macOS 15.x (Sequoia) on both Intel and Apple Silicon.
|
||||
**Q: What macOS versions are supported?**
|
||||
A: macOS 12.x (Monterey) through 15.x (Sequoia) and 26.x (Tahoe). Tested on Intel T2, M1, M2, M3, and M4 hardware.
|
||||
|
||||
**Q: Do I need to disable SIP?**
|
||||
A: No. All operations target the Data volume, which does not require SIP to be disabled.
|
||||
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
# unleash/lib/heal.sh — Self-healing and boot persistence
|
||||
|
||||
heal_suppress() {
|
||||
local data_mount="$1"
|
||||
[ -z "$data_mount" ] && data_mount=""
|
||||
|
||||
step "Checking current MDM suppression state..."
|
||||
local cfg="${data_mount}/private/var/db/ConfigurationProfiles/Settings"
|
||||
local hosts="${data_mount}/private/etc/hosts"
|
||||
local ldp="${data_mount}/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
||||
|
||||
local needs_heal=false
|
||||
|
||||
if [ -f "$cfg/.cloudConfigRecordFound" ]; then
|
||||
warn "DEP activation record present"
|
||||
needs_heal=true
|
||||
else
|
||||
info "DEP markers clean"
|
||||
fi
|
||||
|
||||
if [ -f "$hosts" ]; then
|
||||
if grep -q "iprofiles.apple.com" "$hosts" 2>/dev/null; then
|
||||
info "Domain block active"
|
||||
else
|
||||
warn "Domain block missing"
|
||||
needs_heal=true
|
||||
fi
|
||||
else
|
||||
warn "Hosts file missing"
|
||||
needs_heal=true
|
||||
fi
|
||||
|
||||
if [ -f "$ldp" ]; then
|
||||
local missing=0
|
||||
for label in com.apple.ManagedClient.enroll com.apple.mdmclient.daemon.runatboot; do
|
||||
$PB -c "Print :$label" "$ldp" 2>/dev/null | grep -q "true" || missing=$((missing + 1))
|
||||
done
|
||||
if [ "$missing" -gt 0 ]; then
|
||||
warn "$missing enrollment daemon(s) not disabled"
|
||||
needs_heal=true
|
||||
else
|
||||
info "Enrollment daemons disabled"
|
||||
fi
|
||||
else
|
||||
warn "Launchd override missing"
|
||||
needs_heal=true
|
||||
fi
|
||||
|
||||
if [ "$needs_heal" = false ]; then
|
||||
success "MDM suppression intact — no action needed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
step "Re-applying MDM suppression..."
|
||||
suppress_enrollment "$data_mount"
|
||||
success "MDM suppression restored"
|
||||
}
|
||||
|
||||
_persist_mount_root() {
|
||||
local dm="$1"
|
||||
if [ -z "$dm" ] || [ ! -d "$dm/Library" ]; then
|
||||
echo ""
|
||||
else
|
||||
echo "$dm"
|
||||
fi
|
||||
}
|
||||
|
||||
install_persist_launchdaemon() {
|
||||
local data_mount="$1"
|
||||
local root
|
||||
root="$(_persist_mount_root "$data_mount")"
|
||||
|
||||
local unleash_src
|
||||
if [ -n "$SCRIPT_DIR" ]; then
|
||||
unleash_src="$SCRIPT_DIR/unleash"
|
||||
else
|
||||
unleash_src="$(cd "$(dirname "$0")" && pwd)/unleash"
|
||||
fi
|
||||
|
||||
step "Installing LaunchDaemon for boot-time persistence..."
|
||||
|
||||
local plist_dir="${root}/Library/LaunchDaemons"
|
||||
local plist_path="${plist_dir}/com.unleash.heal.plist"
|
||||
|
||||
mkdir -p "$plist_dir"
|
||||
|
||||
cat > "$plist_path" <<- PLIST
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.unleash.heal</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/bin/bash</string>
|
||||
<string>-c</string>
|
||||
<string>${unleash_src} heal</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StartInterval</key>
|
||||
<integer>86400</integer>
|
||||
<key>Nice</key>
|
||||
<integer>1</integer>
|
||||
<key>KeepAlive</key>
|
||||
<false/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/var/log/unleash-heal.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/var/log/unleash-heal.err</string>
|
||||
</dict>
|
||||
</plist>
|
||||
PLIST
|
||||
|
||||
chmod 644 "$plist_path"
|
||||
success "LaunchDaemon written to $plist_path"
|
||||
|
||||
step "Loading LaunchDaemon..."
|
||||
if command -v launchctl &>/dev/null; then
|
||||
launchctl load "$plist_path" 2>/dev/null \
|
||||
&& success "LaunchDaemon loaded (will run on next boot)" \
|
||||
|| info "LaunchDaemon will load on next boot"
|
||||
else
|
||||
info "launchctl not available (expected in Recovery) — will load on next boot"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_persist_launchdaemon() {
|
||||
local data_mount="$1"
|
||||
local root
|
||||
root="$(_persist_mount_root "$data_mount")"
|
||||
local plist_path="${root}/Library/LaunchDaemons/com.unleash.heal.plist"
|
||||
|
||||
if [ -f "$plist_path" ]; then
|
||||
step "Removing Unleash LaunchDaemon..."
|
||||
if command -v launchctl &>/dev/null; then
|
||||
launchctl unload "$plist_path" 2>/dev/null || true
|
||||
fi
|
||||
rm -f "$plist_path"
|
||||
success "LaunchDaemon removed"
|
||||
else
|
||||
info "No Unleash LaunchDaemon installed"
|
||||
fi
|
||||
}
|
||||
@@ -8,6 +8,9 @@ set -euo pipefail
|
||||
# ./unleash Interactive menu (auto-detects Recovery/dualboot)
|
||||
# ./unleash bypass Full bypass (create admin + suppress)
|
||||
# ./unleash suppress Suppress-only (no user created)
|
||||
# ./unleash heal Check and re-apply suppression (auto-heal)
|
||||
# ./unleash persist Install LaunchDaemon for boot-time persistence
|
||||
# ./unleash unpersist Remove the persistence LaunchDaemon
|
||||
# ./unleash backup Backup current state
|
||||
# ./unleash restore Restore from backup
|
||||
# ./unleash dualboot Target a different volume (needs sudo)
|
||||
@@ -24,7 +27,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB_DIR="$SCRIPT_DIR/lib"
|
||||
|
||||
# Source library modules
|
||||
for _lib in colors detect validate dscl suppress backup status; do
|
||||
for _lib in colors detect validate dscl suppress backup status heal; do
|
||||
_lib_path="$LIB_DIR/$_lib.sh"
|
||||
if [ -f "$_lib_path" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
@@ -133,6 +136,45 @@ cmd_dualboot() {
|
||||
echo -e "${YEL} Pass: $passw${NC}"
|
||||
}
|
||||
|
||||
cmd_heal() {
|
||||
header "unleash — Auto-Heal"
|
||||
if is_recovery; then
|
||||
local data_mount
|
||||
data_mount=$(resolve_data_volume)
|
||||
heal_suppress "$data_mount"
|
||||
else
|
||||
if ! is_root; then
|
||||
error_exit "Heal from booted system requires sudo: sudo ./unleash heal"
|
||||
fi
|
||||
heal_suppress ""
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_persist() {
|
||||
header "unleash — Install Persistence"
|
||||
local data_mount
|
||||
if is_recovery; then
|
||||
data_mount=$(resolve_data_volume)
|
||||
else
|
||||
if ! is_root; then
|
||||
error_exit "Persistence requires sudo: sudo ./unleash persist"
|
||||
fi
|
||||
data_mount=""
|
||||
fi
|
||||
install_persist_launchdaemon "$data_mount"
|
||||
}
|
||||
|
||||
cmd_unpersist() {
|
||||
header "unleash — Remove Persistence"
|
||||
local data_mount
|
||||
if is_recovery; then
|
||||
data_mount=$(resolve_data_volume)
|
||||
else
|
||||
data_mount=""
|
||||
fi
|
||||
remove_persist_launchdaemon "$data_mount"
|
||||
}
|
||||
|
||||
cmd_status() {
|
||||
if is_recovery; then
|
||||
local data_mount
|
||||
@@ -154,6 +196,7 @@ cmd_interactive_recovery() {
|
||||
local options=(
|
||||
"Full bypass (create admin + suppress MDM)"
|
||||
"Suppress enrollment only (no user)"
|
||||
"Auto-heal (check and re-suppress)"
|
||||
"Backup current state"
|
||||
"Restore from backup"
|
||||
"Check MDM status"
|
||||
@@ -166,10 +209,13 @@ cmd_interactive_recovery() {
|
||||
full_bypass_mode "$data_mount"
|
||||
echo -e "${CYAN}Reboot to apply changes.${NC}"
|
||||
;;
|
||||
"Suppress enrollment only (no user)")
|
||||
suppress_only_mode "$data_mount"
|
||||
;;
|
||||
"Backup current state")
|
||||
"Suppress enrollment only (no user)")
|
||||
suppress_only_mode "$data_mount"
|
||||
;;
|
||||
"Auto-heal (check and re-suppress)")
|
||||
heal_suppress "$data_mount"
|
||||
;;
|
||||
"Backup current state")
|
||||
backup_state "$data_mount"
|
||||
;;
|
||||
"Restore from backup")
|
||||
@@ -200,18 +246,25 @@ cmd_interactive_normal() {
|
||||
PS3="Choose an option: "
|
||||
local options=(
|
||||
"Suppress enrollment only"
|
||||
"Auto-heal (check and re-suppress)"
|
||||
"Backup current state"
|
||||
"Restore from backup"
|
||||
"Exit"
|
||||
)
|
||||
select opt in "${options[@]}"; do
|
||||
case $opt in
|
||||
"Suppress enrollment only")
|
||||
local data_mount
|
||||
data_mount=$(resolve_data_volume)
|
||||
suppress_only_mode "$data_mount"
|
||||
;;
|
||||
"Backup current state")
|
||||
"Suppress enrollment only")
|
||||
local data_mount
|
||||
data_mount=$(resolve_data_volume)
|
||||
suppress_only_mode "$data_mount"
|
||||
;;
|
||||
"Auto-heal (check and re-suppress)")
|
||||
if ! is_root; then
|
||||
error_exit "Heal from booted system requires sudo. Run: sudo ./unleash"
|
||||
fi
|
||||
heal_suppress ""
|
||||
;;
|
||||
"Backup current state")
|
||||
local data_mount
|
||||
data_mount=$(resolve_data_volume)
|
||||
backup_state "$data_mount"
|
||||
@@ -236,13 +289,16 @@ main() {
|
||||
case "${1:-}" in
|
||||
bypass) cmd_bypass ;;
|
||||
suppress) cmd_suppress ;;
|
||||
heal) cmd_heal ;;
|
||||
persist) cmd_persist ;;
|
||||
unpersist) cmd_unpersist ;;
|
||||
backup) cmd_backup ;;
|
||||
restore) cmd_restore ;;
|
||||
dualboot) cmd_dualboot ;;
|
||||
status) cmd_status ;;
|
||||
version|-v|--version) cmd_version ;;
|
||||
help|-h|--help)
|
||||
head -30 "$0" | grep -E '^# |^# \$'
|
||||
head -40 "$0" | grep -E '^# |^# \$'
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
|
||||
Reference in New Issue
Block a user