- Add CONTRIBUTING.md with guidelines for PRs and issues - Add CODE_OF_CONDUCT.md (Contributor Covenant v2.1) - Add SECURITY.md with vulnerability reporting policy - Add CHANGELOG.md for version tracking - Add GitHub issue templates (bug, feature, compatibility) - Add GitHub Actions CI (ShellCheck, syntax check, markdown lint) - Add .gitignore for backup dirs and OS artifacts - Update README with badges and new commands - Bump version to 1.1.0 - Update comparison table with new features
413 lines
10 KiB
Bash
Executable File
413 lines
10 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# unleash — Unified MDM bypass tool for macOS.
|
|
# One script to rule them all: bypass, suppress, backup, restore, dualboot, status.
|
|
#
|
|
# Usage:
|
|
# ./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 firewall Block Apple MDM IP ranges via pf (kernel-level)
|
|
# ./unleash firewall-off Remove pf firewall MDM block
|
|
# ./unleash harden Live-OS hardening (kill MDM, remove profiles)
|
|
# ./unleash audit Deep MDM audit (profiles, certs, agents, processes)
|
|
# ./unleash whitelist Selective block (block MDM only, keep iCloud/App Store)
|
|
# ./unleash backup Backup current state
|
|
# ./unleash restore Restore from backup
|
|
# ./unleash dualboot Target a different volume (needs sudo)
|
|
# ./unleash status Check current MDM status
|
|
# ./unleash version Show version
|
|
#
|
|
# Put this on an external SSD and run from Recovery.
|
|
# No curl, no downloads, no typing URLs.
|
|
|
|
VERSION="1.1.0"
|
|
|
|
# Determine script location (works with symlinks and source)
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
LIB_DIR="$SCRIPT_DIR/lib"
|
|
|
|
# Source library modules
|
|
for _lib in colors detect validate dscl suppress backup status heal firewall harden whitelist; do
|
|
_lib_path="$LIB_DIR/$_lib.sh"
|
|
if [ -f "$_lib_path" ]; then
|
|
# shellcheck disable=SC1090
|
|
source "$_lib_path"
|
|
else
|
|
echo "ERROR: Library not found: $_lib_path" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# ------------------------------------------------------------------
|
|
# Command handlers
|
|
# ------------------------------------------------------------------
|
|
cmd_version() {
|
|
echo "unleash v$VERSION"
|
|
exit 0
|
|
}
|
|
|
|
cmd_bypass() {
|
|
if is_recovery; then
|
|
header "unleash — Full MDM Bypass"
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
full_bypass_mode "$data_mount"
|
|
else
|
|
error_exit "Full bypass must run from Recovery mode."
|
|
fi
|
|
}
|
|
|
|
cmd_suppress() {
|
|
header "unleash — Suppress Enrollment Only"
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
suppress_only_mode "$data_mount"
|
|
}
|
|
|
|
cmd_backup() {
|
|
header "unleash — Backup State"
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
backup_state "$data_mount"
|
|
}
|
|
|
|
cmd_restore() {
|
|
header "unleash — Restore State"
|
|
restore_state
|
|
}
|
|
|
|
cmd_dualboot() {
|
|
header "unleash — Dual-Boot Mode"
|
|
if ! is_root; then
|
|
error_exit "Dual-boot mode requires sudo: sudo ./unleash dualboot"
|
|
fi
|
|
|
|
local volumes
|
|
volumes=$(resolve_target_volumes)
|
|
local sys_path="${volumes%%|*}"
|
|
local data_path="${volumes##*|}"
|
|
|
|
info "Target system: $sys_path"
|
|
info "Target data: $data_path"
|
|
|
|
local node
|
|
node=$(dscl_node "$data_path")
|
|
|
|
echo ""
|
|
step "Creating admin account on target"
|
|
|
|
prompt_default realName "Full name" "Apple"
|
|
|
|
local username
|
|
prompt_username username
|
|
|
|
local passw
|
|
prompt_password passw
|
|
|
|
local uid
|
|
uid=$(find_available_uid "$node")
|
|
|
|
create_admin_user "$node" "$data_path" "$username" "$realName" "$passw" "$uid"
|
|
touch "$data_path/private/var/db/.AppleSetupDone"
|
|
|
|
step "Blocking domains on target..."
|
|
local hosts_file="$data_path/private/etc/hosts"
|
|
[ -f "$hosts_file" ] || touch "$hosts_file"
|
|
echo "0.0.0.0 deviceenrollment.apple.com" >>"$hosts_file"
|
|
echo "0.0.0.0 mdmenrollment.apple.com" >>"$hosts_file"
|
|
echo "0.0.0.0 iprofiles.apple.com" >>"$hosts_file"
|
|
success "MDM domains blocked"
|
|
|
|
local config_path="$data_path/private/var/db/ConfigurationProfiles/Settings"
|
|
mkdir -p "$config_path"
|
|
rm -f "$config_path/.cloudConfigHasActivationRecord" \
|
|
"$config_path/.cloudConfigRecordFound"
|
|
touch "$config_path/.cloudConfigProfileInstalled" \
|
|
"$config_path/.cloudConfigRecordNotFound"
|
|
success "Configuration profiles reset"
|
|
|
|
echo ""
|
|
echo -e "${GRN}============================================${NC}"
|
|
echo -e "${GRN} Dual-Boot Bypass Applied ${NC}"
|
|
echo -e "${GRN}============================================${NC}"
|
|
echo ""
|
|
echo -e "${CYAN}Boot into the target installation and login:${NC}"
|
|
echo -e "${YEL} User: $username${NC}"
|
|
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_firewall() {
|
|
header "unleash — pf Firewall MDM Block"
|
|
if ! is_root; then
|
|
error_exit "Firewall requires sudo: sudo ./unleash firewall"
|
|
fi
|
|
if is_recovery; then
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
install_pf_mdm_block "$data_mount"
|
|
else
|
|
install_pf_mdm_block ""
|
|
fi
|
|
}
|
|
|
|
cmd_firewall_off() {
|
|
header "unleash — Remove pf Firewall"
|
|
if ! is_root; then
|
|
error_exit "Requires sudo: sudo ./unleash firewall-off"
|
|
fi
|
|
if is_recovery; then
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
remove_pf_mdm_block "$data_mount"
|
|
else
|
|
remove_pf_mdm_block ""
|
|
fi
|
|
}
|
|
|
|
cmd_harden() {
|
|
header "unleash — Live-OS Hardening"
|
|
if ! is_root; then
|
|
error_exit "Hardening requires sudo: sudo ./unleash harden"
|
|
fi
|
|
if is_recovery; then
|
|
info "Hardening from Recovery will skip live-OS checks"
|
|
harden_live_os
|
|
else
|
|
harden_live_os
|
|
fi
|
|
}
|
|
|
|
cmd_audit() {
|
|
header "unleash — Deep MDM Audit"
|
|
if ! is_root; then
|
|
error_exit "Audit requires sudo: sudo ./unleash audit"
|
|
fi
|
|
deep_status
|
|
}
|
|
|
|
cmd_whitelist() {
|
|
header "unleash — Selective MDM Block"
|
|
if ! is_root; then
|
|
error_exit "Whitelist requires sudo: sudo ./unleash whitelist"
|
|
fi
|
|
if is_recovery; then
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
install_selective_block "$data_mount"
|
|
else
|
|
install_selective_block ""
|
|
fi
|
|
}
|
|
|
|
cmd_status() {
|
|
if is_recovery; then
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
check_mdm_status "$data_mount"
|
|
else
|
|
error_exit "Status check must run from Recovery mode."
|
|
fi
|
|
}
|
|
|
|
cmd_interactive_recovery() {
|
|
header "unleash — Recovery Mode"
|
|
|
|
local data_mount
|
|
data_mount=$(resolve_data_volume)
|
|
echo ""
|
|
|
|
PS3="Choose an option: "
|
|
local options=(
|
|
"Full bypass (create admin + suppress MDM)"
|
|
"Suppress enrollment only (no user)"
|
|
"Auto-heal (check and re-suppress)"
|
|
"Install pf firewall (blocks all Apple services)"
|
|
"Remove pf firewall"
|
|
"Install selective block (iCloud-safe)"
|
|
"Live-OS harden (kill MDM processes)"
|
|
"Deep MDM audit"
|
|
"Backup current state"
|
|
"Restore from backup"
|
|
"Check MDM status"
|
|
"Reboot"
|
|
"Exit"
|
|
)
|
|
select opt in "${options[@]}"; do
|
|
case $opt in
|
|
"Full bypass (create admin + suppress MDM)")
|
|
full_bypass_mode "$data_mount"
|
|
echo -e "${CYAN}Reboot to apply changes.${NC}"
|
|
;;
|
|
"Suppress enrollment only (no user)")
|
|
suppress_only_mode "$data_mount"
|
|
;;
|
|
"Auto-heal (check and re-suppress)")
|
|
heal_suppress "$data_mount"
|
|
;;
|
|
"Install pf firewall (blocks all Apple services)")
|
|
install_pf_mdm_block "$data_mount"
|
|
;;
|
|
"Remove pf firewall")
|
|
remove_pf_mdm_block "$data_mount"
|
|
;;
|
|
"Install selective block (iCloud-safe)")
|
|
install_selective_block "$data_mount"
|
|
;;
|
|
"Live-OS harden (kill MDM processes)")
|
|
harden_live_os
|
|
;;
|
|
"Deep MDM audit")
|
|
deep_status
|
|
;;
|
|
"Backup current state")
|
|
backup_state "$data_mount"
|
|
;;
|
|
"Restore from backup")
|
|
restore_state
|
|
;;
|
|
"Check MDM status")
|
|
check_mdm_status "$data_mount"
|
|
;;
|
|
"Reboot")
|
|
info "Rebooting..."
|
|
reboot
|
|
;;
|
|
"Exit")
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}Invalid option $REPLY${NC}"
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
cmd_interactive_normal() {
|
|
header "unleash"
|
|
echo -e "${YEL}Not in Recovery mode. Limited options.${NC}"
|
|
echo ""
|
|
|
|
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"
|
|
;;
|
|
"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"
|
|
;;
|
|
"Restore from backup")
|
|
restore_state
|
|
;;
|
|
"Exit")
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}Invalid option $REPLY${NC}"
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
# ------------------------------------------------------------------
|
|
# CLI dispatch
|
|
# ------------------------------------------------------------------
|
|
main() {
|
|
case "${1:-}" in
|
|
bypass) cmd_bypass ;;
|
|
suppress) cmd_suppress ;;
|
|
heal) cmd_heal ;;
|
|
persist) cmd_persist ;;
|
|
unpersist) cmd_unpersist ;;
|
|
firewall) cmd_firewall ;;
|
|
firewall-off) cmd_firewall_off ;;
|
|
harden) cmd_harden ;;
|
|
audit) cmd_audit ;;
|
|
whitelist) cmd_whitelist ;;
|
|
backup) cmd_backup ;;
|
|
restore) cmd_restore ;;
|
|
dualboot) cmd_dualboot ;;
|
|
status) cmd_status ;;
|
|
version|-v|--version) cmd_version ;;
|
|
help|-h|--help)
|
|
head -50 "$0" | grep -E '^# |^# \$'
|
|
exit 0
|
|
;;
|
|
"")
|
|
if is_recovery; then
|
|
cmd_interactive_recovery
|
|
else
|
|
cmd_interactive_normal
|
|
fi
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown command: $1${NC}" >&2
|
|
echo "Usage: $0 {bypass|suppress|heal|persist|unpersist|firewall|firewall-off|harden|audit|whitelist|backup|restore|dualboot|status|version|help}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|