From 789985d191ddc82192547ab80a59d0ae0d3024d1 Mon Sep 17 00:00:00 2001 From: ruihan Date: Sat, 20 Jun 2026 12:06:21 -0300 Subject: [PATCH] feat: add check and monitor commands + repo About section - check: pre-format/pre-upgrade MDM assessment with clear SAFE/DETECTED output - monitor: background daemon (5min interval) with osascript notifications - monitor-stop / monitor-status: control the daemon - Updated repo description (About) and topics on GitHub - Updated README, CHANGELOG, CI for both commands - Bump 1.1.0 -> 1.2.0 --- .github/workflows/ci.yml | 2 + CHANGELOG.md | 23 ++++++- README.md | 20 +++++++ lib/check.sh | 125 +++++++++++++++++++++++++++++++++++++++ lib/monitor.sh | 113 +++++++++++++++++++++++++++++++++++ unleash | 34 +++++++++-- 6 files changed, 312 insertions(+), 5 deletions(-) create mode 100644 lib/check.sh create mode 100644 lib/monitor.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e025b9..730f7b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,8 @@ jobs: lib/firewall.sh lib/harden.sh lib/whitelist.sh + lib/check.sh + lib/monitor.sh syntax: name: Bash Syntax Check diff --git a/CHANGELOG.md b/CHANGELOG.md index 99e589e..a411201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,30 @@ # Changelog +## [1.2.0] — 2026-06-20 + +### Added +- **check**: Pre-format / pre-upgrade assessment (will this Mac lock after wipe?) +- **monitor**: Background daemon that watches MDM every 5 minutes and auto-heals +- **monitor-stop**: Stop the background monitor +- **monitor-status**: Check if monitor is running +- GitHub repo About section updated with description and topics + +## [1.1.0] — 2026-06-20 + +### Added +- Project files: CONTRIBUTING.md, CODE_OF_CONDUCT.md, SECURITY.md, CHANGELOG.md +- GitHub issue templates (bug, feature, compatibility) +- GitHub Actions CI (ShellCheck, syntax check, markdown lint) +- Badges and professional README layout + +### Changed +- Humanized code: removed AI artifacts, file headers, section comments +- README rewritten from scratch (625 → 140 lines) + ## [1.0.0] — 2026-06-20 ### Added -- Initial release of unleashes — Unified MDM Bypass for macOS +- Initial release of unleash — Unified MDM Bypass for macOS - **bypass**: Full MDM bypass with admin user creation (Recovery mode) - **suppress**: Suppress MDM enrollment without creating a user - **heal**: Auto-heal — check and re-apply suppression after macOS updates diff --git a/README.md b/README.md index 97b0bf4..4b51019 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,29 @@ No internet needed if running from an SSD. No SIP to disable. | `backup` | Save current hosts, profiles, launchd state | | `restore` | Revert from backup | | `dualboot` | Target an external macOS install | +| `check` | Pre-format report: will this Mac lock after a wipe? | +| `monitor` | Background daemon that watches MDM state and auto-heals | +| `monitor-stop` | Stop the background monitor | +| `monitor-status` | Check if monitor is running | Just `./unleash` with no argument shows an interactive menu. +### Monitor + +```bash +sudo ./unleash monitor +``` + +Runs in the background and checks MDM state every 5 minutes. If MDM tries to re-enroll, it auto-heals and sends a macOS notification. Survives reboots only if combined with `unleash persist` (which can run the monitor instead of heal). Logs to `/var/log/unleash-monitor.log`. + +### Check + +```bash +sudo ./unleash check +``` + +Answers one question: **"If I wipe this Mac, will it lock?"** Checks DEP records, profiles, enrollment state, firewall, and persistence. Also checks if a macOS upgrade is safe. + ## How it works MDM enrollment sits on four layers. Unleash hits all of them: diff --git a/lib/check.sh b/lib/check.sh new file mode 100644 index 0000000..bbc0146 --- /dev/null +++ b/lib/check.sh @@ -0,0 +1,125 @@ +run_preformat_check() { + header "Pre-Format MDM Assessment" + + local clean=true + + step "Checking DEP activation record..." + if [ -f "/private/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordFound" ]; then + local org + org=$(plutil -convert xml1 -o - "/private/var/db/ConfigurationProfiles/Settings/.cloudConfigRecordFound" 2>/dev/null \ + | grep -iA1 OrganizationName | tail -1 | sed -E 's/.*(.*)<\/string>.*/\1/') + echo -e " ${RED}ACTIVE DEP RECORD FOUND${NC}" + [ -n "$org" ] && echo -e " ${YEL}Device assigned to: $org${NC}" + clean=false + else + echo -e " ${GRN}DEP record clean${NC}" + fi + + step "Checking MDM enrollment URL for this device..." + if command -v curl &>/dev/null; then + local enroll_check + enroll_check=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 \ + "https://deviceenrollment.apple.com/" 2>/dev/null || echo "000") + if [ "$enroll_check" = "000" ] || [ "$enroll_check" = "200" ]; then + echo -e " ${YEL}deviceenrollment.apple.com reachable${NC}" + else + echo -e " ${GRN}deviceenrollment.apple.com blocked (code $enroll_check)${NC}" + fi + else + echo -e " ${YEL}curl not available, skipping URL check${NC}" + fi + + step "Checking MDM enrollment state..." + if command -v profiles &>/dev/null; then + local enroll_state + enroll_state=$(sudo profiles status -type enrollment 2>/dev/null || true) + if echo "$enroll_state" | grep -qi "enrolled"; then + echo -e " ${RED}Device is enrolled in MDM${NC}" + clean=false + else + echo -e " ${GRN}Not enrolled in MDM${NC}" + fi + fi + + step "Checking installed profiles..." + if command -v profiles &>/dev/null; then + local profile_count + profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0) + if [ "$profile_count" -gt 0 ]; then + echo -e " ${YEL}$profile_count profile(s) installed${NC}" + clean=false + else + echo -e " ${GRN}No profiles installed${NC}" + fi + fi + + step "Checking pf firewall status..." + if command -v pfctl &>/dev/null; then + if pfctl -a "com.unleash/mdm" -s rules 2>/dev/null | grep -q "block"; then + echo -e " ${GRN}Unleash pf firewall active${NC}" + else + echo -e " ${YEL}No Unleash pf firewall rules${NC}" + fi + else + echo -e " ${YEL}pfctl not available${NC}" + fi + + step "Checking persistence LaunchDaemon..." + if [ -f "/Library/LaunchDaemons/com.unleash.heal.plist" ]; then + echo -e " ${GRN}Unleash LaunchDaemon installed (auto-heal on boot)${NC}" + else + echo -e " ${YEL}No Unleash LaunchDaemon${NC}" + fi + + echo "" + echo -e "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}" + if [ "$clean" = true ]; then + echo -e "${CYAN}║${NC} ${GRN}SAFE TO FORMAT${NC} — No MDM enrollment detected ${CYAN}║${NC}" + echo -e "${CYAN}║${NC} This Mac should not lock after a wipe. ${CYAN}║${NC}" + echo -e "${CYAN}║${NC} If you want defense-in-depth anyway, run: ${CYAN}║${NC}" + echo -e "${CYAN}║${NC} ${YEL}sudo ./unleash persist && sudo ./unleash firewall${NC} ${CYAN}║${NC}" + else + echo -e "${CYAN}║${NC} ${RED}MDM DETECTED${NC} — This Mac WILL lock after format ${CYAN}║${NC}" + echo -e "${CYAN}║${NC} Run from Recovery after wipe: ${YEL}./unleash bypass${NC} ${CYAN}║${NC}" + echo -e "${CYAN}║${NC} To survive macOS updates (not full wipes): ${CYAN}║${NC}" + echo -e "${CYAN}║${NC} ${YEL}sudo ./unleash persist && sudo ./unleash firewall${NC} ${CYAN}║${NC}" + fi + echo -e "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}" +} + +check_upgrade_safety() { + header "macOS Upgrade Safety Check" + + step "Checking if suppression will survive upgrade..." + local issues=0 + + if [ -f "/Library/LaunchDaemons/com.unleash.heal.plist" ]; then + echo -e " ${GRN}Persistence installed — heal runs after reboot${NC}" + else + echo -e " ${RED}No persistence — upgrade may restore MDM${NC}" + echo -e " ${YEL}Fix: sudo ./unleash persist${NC}" + issues=$((issues + 1)) + fi + + if command -v pfctl &>/dev/null && pfctl -a "com.unleash/mdm" -s rules 2>/dev/null | grep -q "block"; then + echo -e " ${GRN}pf firewall active — survives upgrade${NC}" + else + echo -e " ${YEL}No pf firewall — upgrade may restore MDM connectivity${NC}" + echo -e " ${YEL}Fix: sudo ./unleash whitelist${NC}" + issues=$((issues + 1)) + fi + + if grep -q "iprofiles.apple.com" /private/etc/hosts 2>/dev/null; then + echo -e " ${GRN}Hosts block active${NC}" + else + echo -e " ${YEL}Hosts block not found${NC}" + issues=$((issues + 1)) + fi + + echo "" + if [ "$issues" -eq 0 ]; then + echo -e "${GRN}Upgrade should be safe — MDM suppression will survive.${NC}" + else + echo -e "${YEL}$issues issue(s) found. Run the fixes above before upgrading.${NC}" + fi +} diff --git a/lib/monitor.sh b/lib/monitor.sh new file mode 100644 index 0000000..0578ad6 --- /dev/null +++ b/lib/monitor.sh @@ -0,0 +1,113 @@ +monitor_mdm() { + header "MDM Monitor (continuous)" + + if ! is_root; then + error_exit "Monitor requires sudo: sudo ./unleash monitor" + fi + + local logfile="/var/log/unleash-monitor.log" + local pidfile="/tmp/unleash-monitor.pid" + + if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then + echo -e "${YEL}Monitor already running (PID $(cat "$pidfile"))${NC}" + echo -e "${YEL}Run 'sudo ./unleash monitor-stop' to stop it${NC}" + return 0 + fi + + echo "$$" > "$pidfile" + + local interval=300 + local consecutive_failures=0 + local last_state="" + local last_notification=0 + + echo "$(date) Monitor started (interval ${interval}s)" >> "$logfile" + + local cfg="/private/var/db/ConfigurationProfiles/Settings" + local hosts="/private/etc/hosts" + + trap 'echo "$(date) Monitor stopped" >> "$logfile"; rm -f "$pidfile"; exit 0' INT TERM + + while true; do + local state="clean" + local reason="" + + if [ -f "$cfg/.cloudConfigRecordFound" ]; then + state="dirty" + reason="DEP record found" + fi + + if [ -f "$hosts" ] && ! grep -q "iprofiles.apple.com" "$hosts" 2>/dev/null; then + state="dirty" + reason="Hosts block missing" + fi + + if command -v profiles &>/dev/null; then + local enroll_state + enroll_state=$(profiles status -type enrollment 2>/dev/null || true) + if echo "$enroll_state" | grep -qi "Enrolled via DEP"; then + state="dirty" + reason="DEP enrollment active" + fi + fi + + if [ "$state" != "$last_state" ]; then + echo "$(date) State change: $last_state -> $state ($reason)" >> "$logfile" + last_state="$state" + + local now + now=$(date +%s) + if [ "$state" = "dirty" ] && [ $((now - last_notification)) -gt 3600 ]; then + last_notification=$now + if command -v osascript &>/dev/null; then + osascript -e "display notification \"$reason\" with title \"Unleash MDM Alert\" subtitle \"MDM enrollment detected\"" 2>/dev/null || true + fi + heal_suppress "" + fi + fi + + if [ "$state" = "dirty" ]; then + consecutive_failures=$((consecutive_failures + 1)) + else + consecutive_failures=0 + fi + + if [ "$consecutive_failures" -ge 12 ]; then + echo "$(date) CRITICAL: 12 consecutive dirty checks" >> "$logfile" + if command -v osascript &>/dev/null; then + osascript -e "display dialog \"MDM keeps coming back after 12 attempts. Something is persistently re-enrolling.\" with title \"Unleash\" buttons {\"OK\"} default button \"OK\"" 2>/dev/null || true + fi + consecutive_failures=0 + fi + + sleep "$interval" & + wait $! 2>/dev/null || true + done +} + +stop_monitor() { + local pidfile="/tmp/unleash-monitor.pid" + if [ -f "$pidfile" ]; then + local pid + pid=$(cat "$pidfile") + if kill -0 "$pid" 2>/dev/null; then + kill "$pid" 2>/dev/null + echo -e "${GRN}Monitor stopped${NC}" + else + echo -e "${YEL}Monitor not running (stale PID)${NC}" + fi + rm -f "$pidfile" + else + echo -e "${YEL}Monitor not running${NC}" + fi +} + +monitor_status() { + local pidfile="/tmp/unleash-monitor.pid" + if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then + echo -e "${GRN}Monitor running (PID $(cat "$pidfile"))${NC}" + tail -5 /var/log/unleash-monitor.log 2>/dev/null || echo " (no log entries yet)" + else + echo -e "${YEL}Monitor not running${NC}" + fi +} diff --git a/unleash b/unleash index 38d0e0f..192f021 100755 --- a/unleash +++ b/unleash @@ -3,12 +3,12 @@ set -euo pipefail # Single-script MDM bypass for macOS. Recovery mode. Apple Silicon + Intel. -VERSION="1.1.0" +VERSION="1.2.0" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" LIB_DIR="$SCRIPT_DIR/lib" -for _lib in colors detect validate dscl suppress backup status heal firewall harden whitelist; do +for _lib in colors detect validate dscl suppress backup status heal firewall harden whitelist check monitor; do _lib_path="$LIB_DIR/$_lib.sh" if [ -f "$_lib_path" ]; then # shellcheck disable=SC1090 @@ -226,6 +226,28 @@ cmd_status() { fi } +cmd_check() { + header "unleash — Pre-Format Assessment" + if ! is_root; then + error_exit "Check requires sudo: sudo ./unleash check" + fi + run_preformat_check + echo "" + check_upgrade_safety +} + +cmd_monitor() { + monitor_mdm +} + +cmd_monitor_stop() { + stop_monitor +} + +cmd_monitor_status() { + monitor_status +} + cmd_interactive_recovery() { header "unleash — Recovery Mode" @@ -359,9 +381,13 @@ main() { restore) cmd_restore ;; dualboot) cmd_dualboot ;; status) cmd_status ;; + check) cmd_check ;; + monitor) cmd_monitor ;; + monitor-stop) cmd_monitor_stop ;; + monitor-status) cmd_monitor_status ;; version|-v|--version) cmd_version ;; help|-h|--help) - echo "Usage: $0 {bypass|suppress|heal|persist|unpersist|firewall|firewall-off|harden|audit|whitelist|backup|restore|dualboot|status|version|help}" + echo "Usage: $0 {bypass|suppress|heal|persist|unpersist|firewall|firewall-off|harden|audit|whitelist|check|monitor|monitor-stop|monitor-status|backup|restore|dualboot|status|version|help}" exit 0 ;; "") @@ -373,7 +399,7 @@ main() { ;; *) 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 + echo "Usage: $0 {bypass|suppress|heal|persist|unpersist|firewall|firewall-off|harden|audit|whitelist|check|monitor|monitor-stop|monitor-status|backup|restore|dualboot|status|version|help}" >&2 exit 1 ;; esac