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 - Updated README, CHANGELOG, CI for both commands - Bump 1.1.0 -> 1.2.0
This commit is contained in:
+125
@@ -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>(.*)<\/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
|
||||
}
|
||||
+113
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user