Initial commit: unleash v1.0.0

Unified MDM bypass tool for macOS.

- CLI with 7 subcommands (bypass/suppress/backup/restore/dualboot/status/version)
- Modular (lib/*.sh) + standalone (single-file) formats
- Auto-detect Recovery mode, APFS volume, FileVault
- SSV-safe: all writes target Data volume
- Backup/restore original state
- MIT License
This commit is contained in:
2026-06-12 13:40:58 -03:00
commit cdce779763
13 changed files with 1024 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
# unleash/lib/backup.sh — Backup and restore engine
BACKUP_DIR="$(dirname "$(dirname "$0")")/.unleash-backup"
backup_state() {
local data_mount="$1"
mkdir -p "$BACKUP_DIR"
step "Saving backup to $BACKUP_DIR"
if [ -f "$data_mount/private/etc/hosts" ]; then
cp "$data_mount/private/etc/hosts" "$BACKUP_DIR/hosts.backup"
success "hosts saved"
fi
local cfg_src="$data_mount/private/var/db/ConfigurationProfiles/Settings"
if [ -d "$cfg_src" ]; then
mkdir -p "$BACKUP_DIR/ConfigurationProfiles"
cp -r "$cfg_src/"* "$BACKUP_DIR/ConfigurationProfiles/" 2>/dev/null || true
success "config profiles saved"
fi
local ldp_src="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
if [ -f "$ldp_src" ]; then
mkdir -p "$BACKUP_DIR/launchd"
cp "$ldp_src" "$BACKUP_DIR/launchd/disabled.plist.backup" 2>/dev/null || true
success "launchd override saved"
fi
date +%Y-%m-%d_%H-%M-%S >"$BACKUP_DIR/timestamp"
echo "$data_mount" >"$BACKUP_DIR/data_volume_path"
success "Backup complete: $(cat "$BACKUP_DIR/timestamp")"
}
restore_state() {
[ -f "$BACKUP_DIR/timestamp" ] || error_exit "No backup found at $BACKUP_DIR"
local data_mount
if [ -f "$BACKUP_DIR/data_volume_path" ]; then
data_mount=$(cat "$BACKUP_DIR/data_volume_path")
if [ ! -d "$data_mount/private/var" ]; then
warn "Saved path unavailable — re-detecting..."
data_mount=$(resolve_data_volume)
fi
else
data_mount=$(resolve_data_volume)
fi
step "Restoring from backup ($(cat "$BACKUP_DIR/timestamp"))"
echo -e "${YEL}Target: $data_mount${NC}"
if [ -f "$BACKUP_DIR/hosts.backup" ]; then
cp "$BACKUP_DIR/hosts.backup" "$data_mount/private/etc/hosts"
success "hosts restored"
fi
if [ -d "$BACKUP_DIR/ConfigurationProfiles" ]; then
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
mkdir -p "$cfg"
cp -r "$BACKUP_DIR/ConfigurationProfiles/"* "$cfg/" 2>/dev/null || true
success "config profiles restored"
fi
if [ -f "$BACKUP_DIR/launchd/disabled.plist.backup" ]; then
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
mkdir -p "$(dirname "$ldp")"
cp "$BACKUP_DIR/launchd/disabled.plist.backup" "$ldp"
success "launchd override restored"
fi
sed -i '' '/# Added by unleash/d' "$data_mount/private/etc/hosts" 2>/dev/null || true
rm -f "$BACKUP_DIR/data_volume_path" "$BACKUP_DIR/timestamp"
success "Restore complete"
}
has_backup() {
[ -f "$BACKUP_DIR/timestamp" ]
}
+57
View File
@@ -0,0 +1,57 @@
# unleash/lib/colors.sh — UI helpers and color system
RED='\033[1;31m'
GRN='\033[1;32m'
BLU='\033[1;34m'
YEL='\033[1;33m'
CYAN='\033[1;36m'
MAG='\033[1;35m'
NC='\033[0m'
error_exit() {
echo -e "${RED}ERROR: $1${NC}" >&2
exit 1
}
warn() {
echo -e "${YEL}WARNING: $1${NC}" >&2
}
success() {
echo -e "${GRN}\u2713 $1${NC}"
}
info() {
echo -e "${BLU}\u2139 $1${NC}"
}
step() {
echo -e "${CYAN}\u25b8 $1${NC}"
}
header() {
local title="$1"
echo ""
echo -e "${CYAN}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ ${title}${NC}"
echo -e "${CYAN}╚═══════════════════════════════════════════════╝${NC}"
echo ""
}
prompt_default() {
local var_name="$1"
local prompt_text="$2"
local default="$3"
local value
read -p "$prompt_text (default '$default'): " value
value="${value:=$default}"
eval "$var_name=\"$value\""
}
confirm() {
local prompt="$1"
local response
read -p "$prompt (y/N): " response
[[ "$response" =~ ^[Yy]$ ]]
}
+103
View File
@@ -0,0 +1,103 @@
# unleash/lib/detect.sh — Volume, mode, and environment detection
is_recovery() {
[ -d "/System/Installation" ] && return 0
local vol
vol=$(diskutil info / 2>/dev/null | awk -F': *' '/Volume Name/{print $2}' | xargs)
case "$vol" in
"Recovery"*|"macOS Base"*|"macOS Installer"*) return 0 ;;
esac
return 1
}
is_root() {
[[ $EUID -eq 0 ]]
}
resolve_data_volume() {
step "Locating Data volume by APFS role..."
local id mount_pt
id=$(diskutil apfs list 2>/dev/null \
| awk '/\(Data\)/ && match($0, /disk[0-9]+s[0-9]+/) {print substr($0, RSTART, RLENGTH); exit}')
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
info "APFS role detection failed — trying name-based..."
id=$(diskutil list 2>/dev/null \
| awk '/[[:space:]]Data[[:space:]]/{for(i=1;i<=NF;i++) if($i ~ /^disk[0-9]+s[0-9]+$/) v=$i} END{print v}')
fi
if [ -z "$id" ] || ! diskutil info "/dev/$id" >/dev/null 2>&1; then
warn "Auto-detection failed. Available disks:"
diskutil list >&2
echo ""
read -p "Enter Data volume identifier (e.g. disk3s1): " id </dev/tty
id="${id#/dev/}"
fi
[ -n "$id" ] || error_exit "No Data volume identifier provided."
local data_dev="/dev/$id"
diskutil info "$data_dev" >/dev/null 2>&1 || error_exit "Not a valid disk: $data_dev"
info "Data volume device: $data_dev"
_mount_point() {
diskutil info "$data_dev" 2>/dev/null \
| awk -F': *' '/Mount Point/{print $2}' | sed 's/[[:space:]]*$//'
}
mount_pt=$(_mount_point)
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
info "Not mounted — mounting..."
diskutil mount "$data_dev" 2>/dev/null || true
mount_pt=$(_mount_point)
fi
if [ -z "$mount_pt" ] || [ ! -d "$mount_pt" ]; then
warn "FileVault-locked — need to unlock."
echo -e "${YEL}Enter password of a user on this Mac (or FileVault recovery key):${NC}" >&2
diskutil apfs unlockVolume "$data_dev" 2>/dev/null \
|| error_exit "Failed to unlock. Re-run with valid credentials."
mount_pt=$(_mount_point)
fi
[ -d "$mount_pt" ] || error_exit "Mount point not found after mount/unlock."
[ -d "$mount_pt/private/var/db/dslocal/nodes/Default" ] \
|| error_exit "Not a macOS Data volume (no dslocal node at $mount_pt)."
success "Data volume: $mount_pt"
echo "$mount_pt"
}
detect_system_volume() {
local data_mount="$1"
local vol
for vol in /Volumes/*; do
if [ -d "$vol/System" ] && [ "$vol" != "$data_mount" ]; then
basename "$vol"
return 0
fi
done
echo ""
}
resolve_target_volumes() {
local base_name data_name
read -p "Enter target system volume name (default 'Macintosh HD'): " base_name
base_name="${base_name:=Macintosh HD}"
read -p "Enter target data volume name (default 'Macintosh HD - Data'): " data_name
data_name="${data_name:=Macintosh HD - Data}"
local sys_path="/Volumes/$base_name"
local data_path="/Volumes/$data_name"
[ -d "$sys_path" ] || error_exit "System volume not found: $sys_path"
[ -d "$data_path" ] || error_exit "Data volume not found: $data_path"
echo "$sys_path|$data_path"
}
+66
View File
@@ -0,0 +1,66 @@
# unleash/lib/dscl.sh — Directory Services operations
dscl_node() {
local data_mount="$1"
echo "$data_mount/private/var/db/dslocal/nodes/Default"
}
check_user_exists() {
local node="$1"
local username="$2"
dscl -f "$node" localhost -read "/Local/Default/Users/$username" >/dev/null 2>&1
}
find_available_uid() {
local node="$1"
local uid=501
while [ $uid -lt 600 ]; do
dscl -f "$node" localhost -search /Local/Default/Users UniqueID $uid 2>/dev/null \
| grep -q "UniqueID" || { echo $uid; return 0; }
uid=$((uid + 1))
done
echo 501
}
delete_user() {
local node="$1"
local data_mount="$2"
local username="$3"
dscl -f "$node" localhost -delete "/Local/Default/Users/$username" 2>/dev/null || true
rm -rf "$data_mount/Users/$username" 2>/dev/null || true
}
create_admin_user() {
local node="$1"
local data_mount="$2"
local username="$3"
local realname="$4"
local password="$5"
local uid="$6"
info "Creating admin account: $username"
dscl -f "$node" localhost -create "/Local/Default/Users/$username" 2>/dev/null \
|| error_exit "Failed to create user"
dscl -f "$node" localhost -create "/Local/Default/Users/$username" UserShell "/bin/zsh" 2>/dev/null
dscl -f "$node" localhost -create "/Local/Default/Users/$username" RealName "$realname" 2>/dev/null
dscl -f "$node" localhost -create "/Local/Default/Users/$username" UniqueID "$uid" 2>/dev/null
dscl -f "$node" localhost -create "/Local/Default/Users/$username" PrimaryGroupID "20" 2>/dev/null
dscl -f "$node" localhost -create "/Local/Default/Users/$username" NFSHomeDirectory "/Users/$username" 2>/dev/null
dscl -f "$node" localhost -passwd "/Local/Default/Users/$username" "$password" 2>/dev/null \
|| error_exit "Failed to set password"
dscl -f "$node" localhost -append "/Local/Default/Groups/admin" GroupMembership "$username" 2>/dev/null \
|| error_exit "Failed to grant admin"
mkdir -p "$data_mount/Users/$username"
success "Admin '$username' created (UID $uid)"
}
add_to_filevault() {
local username="$1"
if command -v fdesetup &>/dev/null \
&& fdesetup supportsauthorizedusers 2>/dev/null | grep -q true; then
fdesetup add -usertoadd "$username" 2>/dev/null || true
fi
}
+79
View File
@@ -0,0 +1,79 @@
# unleash/lib/status.sh — Verify and status check
check_mdm_status() {
local data_mount="$1"
local hosts="$data_mount/private/etc/hosts"
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
header "MDM Status Report"
step "DEP markers ($cfg)"
if [ -d "$cfg" ]; then
for f in \
.cloudConfigHasActivationRecord \
.cloudConfigRecordFound \
.cloudConfigRecordNotFound \
.cloudConfigProfileInstalled \
.cloudConfigTimerCheck; do
if [ -f "$cfg/$f" ]; then
echo -e " ${GRN}$f${NC} — present"
else
echo -e " ${YEL}$f${NC} — absent"
fi
done
else
warn "Settings directory not found"
fi
echo ""
step "Blocked domains in hosts"
if [ -f "$hosts" ]; then
local matches
matches=$(grep -iE 'iprofiles|enrollment|mdm|acmdm' "$hosts" 2>/dev/null)
if [ -n "$matches" ]; then
echo "$matches" | while IFS= read -r line; do
echo -e " ${GRN}$line${NC}"
done
else
echo -e " ${YEL}(none)${NC}"
fi
else
echo -e " ${YEL}(hosts not found)${NC}"
fi
echo ""
step "Enrollment daemon status"
if [ -f "$ldp" ]; then
/usr/libexec/PlistBuddy -c "Print" "$ldp" 2>/dev/null || echo -e " ${YEL}(empty/corrupt)${NC}"
else
echo -e " ${YEL}(no override)${NC}"
fi
echo ""
step "Profiles enrollment status"
if command -v profiles &>/dev/null; then
profiles status -type enrollment 2>/dev/null \
|| echo -e " ${YEL}Cannot check (expected in Recovery)${NC}"
else
echo -e " ${YEL}'profiles' not available${NC}"
fi
echo ""
step "Backup status"
if has_backup; then
echo -e " ${GRN}Backup exists:${NC} $(cat "$BACKUP_DIR/timestamp")"
else
echo -e " ${YEL}No backup${NC}"
fi
echo ""
if [ -f "$cfg/.cloudConfigRecordFound" ]; then
local org
org=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -iA1 OrganizationName | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
[ -n "$org" ] && echo -e "${YEL}Active DEP record found — device assigned to: $org${NC}"
else
echo -e "${GRN}No active DEP record.${NC}"
fi
}
+138
View File
@@ -0,0 +1,138 @@
# unleash/lib/suppress.sh — Core MDM suppression logic
# All paths target the Data volume (SSV-safe).
PB=/usr/libexec/PlistBuddy
suppress_enrollment() {
local data_mount="$1"
local hosts="$data_mount/private/etc/hosts"
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
local setupdone="$data_mount/private/var/db/.AppleSetupDone"
step "Reading DEP activation record..."
local mdm_host="" org=""
if [ -f "$cfg/.cloudConfigRecordFound" ]; then
mdm_host=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -ioE 'https?://[a-z0-9._-]+' | sed -E 's#https?://##' \
| sort -u | grep -viE '(^|\.)apple\.com$' | head -1)
org=$(plutil -convert xml1 -o - "$cfg/.cloudConfigRecordFound" 2>/dev/null \
| grep -iA1 OrganizationName | tail -1 | sed -E 's/.*<string>(.*)<\/string>.*/\1/')
[ -n "$org" ] && info "Device assigned in ABM to: $org"
[ -n "$mdm_host" ] && info "Org MDM host: $mdm_host"
else
info "No DEP activation record present."
fi
step "Blocking enrollment domains (Data volume hosts)..."
[ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; }
grep -q "Added by unleash" "$hosts" 2>/dev/null || {
echo "" >>"$hosts"
echo "# Added by unleash — DEP enrollment block" >>"$hosts"
}
local domains=(
iprofiles.apple.com
deviceenrollment.apple.com
mdmenrollment.apple.com
acmdm.apple.com
)
[ -n "$mdm_host" ] && domains+=("$mdm_host")
local d
for d in "${domains[@]}"; do
grep -qiE "[[:space:]]$d(\$|[[:space:]])" "$hosts" 2>/dev/null \
&& { info "$d already blocked"; continue; }
printf '0.0.0.0 %s\n:: %s\n' "$d" "$d" >>"$hosts"
success "blocked $d"
done
step "Resetting DEP markers..."
mkdir -p "$cfg"
rm -f "$cfg/.cloudConfigHasActivationRecord" \
"$cfg/.cloudConfigRecordFound" \
"$cfg/.cloudConfigTimerCheck" \
"$cfg/com.apple.mdm.depnag.plist" \
"$cfg/com.apple.mdm.prelogin.plist" 2>/dev/null
touch "$cfg/.cloudConfigRecordNotFound" \
"$cfg/.cloudConfigProfileInstalled"
success "Cached record cleared; bypass markers set"
step "Disabling enrollment daemon..."
mkdir -p "$(dirname "$ldp")"
[ -f "$ldp" ] || printf '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict/></plist>\n' >"$ldp"
for label in com.apple.ManagedClient.enroll com.apple.mdmclient.daemon.runatboot; do
$PB -c "Add :$label bool true" "$ldp" 2>/dev/null \
|| $PB -c "Set :$label true" "$ldp" 2>/dev/null
done
success "Enrollment daemon disabled"
touch "$setupdone" 2>/dev/null || true
}
suppress_only_mode() {
local data_mount="$1"
echo ""
info "Suppress-only mode: no user will be created."
suppress_enrollment "$data_mount"
echo ""
echo -e "${GRN}============================================${NC}"
echo -e "${GRN} Enrollment Suppressed ${NC}"
echo -e "${GRN}============================================${NC}"
echo ""
echo -e "${CYAN}Reboot to apply.${NC}"
echo -e "${YEL}After a macOS update: re-run.${NC}"
echo -e "${YEL}Never run 'profiles renew' or Erase All Content & Settings.${NC}"
}
full_bypass_mode() {
local data_mount="$1"
local node
node=$(dscl_node "$data_mount")
echo ""
step "Creating temporary admin account"
prompt_default realName "Full name" "Apple"
local username
while true; do
prompt_username username
if check_user_exists "$node" "$username"; then
warn "User '$username' already exists."
if confirm "Delete and recreate?"; then
delete_user "$node" "$data_mount" "$username"
break
else
echo -e "${YEL}Choose a different username.${NC}"
fi
else
break
fi
done
local passw
prompt_password passw
local uid
uid=$(find_available_uid "$node")
info "Using UID $uid"
create_admin_user "$node" "$data_mount" "$username" "$realName" "$passw" "$uid"
touch "$data_mount/private/var/db/.AppleSetupDone"
success "Setup Assistant will be skipped"
add_to_filevault "$username"
suppress_enrollment "$data_mount"
echo ""
echo -e "${GRN}============================================${NC}"
echo -e "${GRN} MDM Bypass Complete ${NC}"
echo -e "${GRN}============================================${NC}"
echo ""
echo -e "${CYAN}Login:${NC} ${YEL}$username${NC} / ${YEL}$passw${NC}"
echo -e "${YEL}After macOS update: re-run. Never 'profiles renew'.${NC}"
}
+48
View File
@@ -0,0 +1,48 @@
# unleash/lib/validate.sh — Input validation helpers
validate_username() {
local u="$1"
[ -z "$u" ] && { echo "Username cannot be empty" >&2; return 1; }
[ ${#u} -gt 31 ] && { echo "Username too long (max 31 chars)" >&2; return 1; }
[[ "$u" =~ ^[a-zA-Z0-9_-]+$ ]] \
|| { echo "Use only letters, numbers, underscore, hyphen" >&2; return 1; }
[[ "$u" =~ ^[a-zA-Z_] ]] \
|| { echo "Must start with a letter or underscore" >&2; return 1; }
return 0
}
validate_password() {
[ -z "$1" ] && { echo "Password cannot be empty" >&2; return 1; }
[ ${#1} -lt 4 ] && { echo "Minimum 4 characters" >&2; return 1; }
return 0
}
prompt_username() {
local var_name="$1"
local value
while true; do
read -p "Username (default 'Apple'): " value
value="${value:=Apple}"
if msg=$(validate_username "$value"); then
eval "$var_name=\"$value\""
return 0
else
warn "$msg"
fi
done
}
prompt_password() {
local var_name="$1"
local value
while true; do
read -p "Password (default '1234'): " value
value="${value:=1234}"
if msg=$(validate_password "$value"); then
eval "$var_name=\"$value\""
return 0
else
warn "$msg"
fi
done
}