feat(admin): add a Recovery-only local account command (#13)
Add a Recovery-only local admin command
This commit is contained in:
@@ -66,6 +66,21 @@ Creates a temporary admin account and suppresses MDM. What it does:
|
|||||||
|
|
||||||
Same as bypass minus the user creation. Useful after a clean bypass breaks from a macOS update.
|
Same as bypass minus the user creation. Useful after a clean bypass breaks from a macOS update.
|
||||||
|
|
||||||
|
### admin — Create admin user only (Recovery only)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./unleash admin
|
||||||
|
```
|
||||||
|
|
||||||
|
Creates a hidden local administrator account on the system without performing an MDM bypass or suppression. What it does:
|
||||||
|
|
||||||
|
1. Finds and mounts the macOS Data volume
|
||||||
|
2. Unlocks FileVault if needed
|
||||||
|
3. Creates an admin user with a custom username and password
|
||||||
|
4. Attempts FileVault integration when available; verify it after reboot
|
||||||
|
5. Hides the account from the macOS login window via dscl
|
||||||
|
6. Conceals the user's home directory in `/Users` using filesystem flags
|
||||||
|
|
||||||
### heal — Check and re-apply
|
### heal — Check and re-apply
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+15
@@ -21,6 +21,21 @@ find_available_uid() {
|
|||||||
echo 501
|
echo 501
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hide_user() {
|
||||||
|
local node="$1"
|
||||||
|
local data_mount="$2"
|
||||||
|
local username="$3"
|
||||||
|
|
||||||
|
info "Hiding user account: $username"
|
||||||
|
|
||||||
|
check_user_exists "$node" "$username" || error_exit "Could not find user '$username'"
|
||||||
|
|
||||||
|
dscl -f "$node" localhost -create "/Local/Default/Users/$username" IsHidden "1" 2>/dev/null
|
||||||
|
|
||||||
|
chflags hidden "$data_mount/Users/$username"
|
||||||
|
success "User '$username' hidden"
|
||||||
|
}
|
||||||
|
|
||||||
delete_user() {
|
delete_user() {
|
||||||
local node="$1"
|
local node="$1"
|
||||||
local data_mount="$2"
|
local data_mount="$2"
|
||||||
|
|||||||
@@ -153,6 +153,62 @@ suppress_only_mode() {
|
|||||||
echo -e "${YEL}Never run 'profiles renew' or Erase All Content & Settings.${NC}"
|
echo -e "${YEL}Never run 'profiles renew' or Erase All Content & Settings.${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
admin_only_mode() {
|
||||||
|
local data_mount="$1"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
info "[DRY RUN] Would create a local admin user on $data_mount"
|
||||||
|
info "[DRY RUN] - Create local user"
|
||||||
|
info "[DRY RUN] - Grant user admin permissions"
|
||||||
|
info "[DRY RUN] - Hide newly created admin account"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local node
|
||||||
|
node=$(dscl_node "$data_mount")
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
step "Creating local 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"
|
||||||
|
|
||||||
|
add_to_filevault "$username"
|
||||||
|
|
||||||
|
hide_user "$node" "$data_mount" "$username"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GRN}============================================${NC}"
|
||||||
|
echo -e "${GRN} Local Admin Created ${NC}"
|
||||||
|
echo -e "${GRN}============================================${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${CYAN}Reboot to apply.${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
full_bypass_mode() {
|
full_bypass_mode() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
@test "admin rejects normal mode before resolving a target volume" {
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
local script="$BATS_TEST_DIRNAME/../$entrypoint"
|
||||||
|
run bash -u -c '
|
||||||
|
source <(sed '\''/^main "\$@"$/d'\'' "$1")
|
||||||
|
is_recovery() { return 1; }
|
||||||
|
resolve_data_volume() { echo TARGET_WAS_ACCESSED; }
|
||||||
|
admin_only_mode() { echo ADMIN_FLOW_WAS_STARTED; }
|
||||||
|
cmd_admin
|
||||||
|
' "$script" "$script"
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"Admin creation must run from Recovery mode"* ]]
|
||||||
|
[[ "$output" != *"TARGET_WAS_ACCESSED"* ]]
|
||||||
|
[[ "$output" != *"ADMIN_FLOW_WAS_STARTED"* ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "admin dry run returns before accessing account or enrollment state" {
|
||||||
|
local entrypoint
|
||||||
|
for entrypoint in unleash unleash-standalone.sh; do
|
||||||
|
local script="$BATS_TEST_DIRNAME/../$entrypoint"
|
||||||
|
run bash -u -c '
|
||||||
|
source <(sed '\''/^main "\$@"$/d'\'' "$1")
|
||||||
|
DRY_RUN=true
|
||||||
|
is_recovery() { return 0; }
|
||||||
|
resolve_data_volume() { echo TARGET_WAS_ACCESSED; }
|
||||||
|
dscl_node() { echo ACCOUNT_STATE_WAS_ACCESSED; return 1; }
|
||||||
|
cmd_admin
|
||||||
|
' "$script" "$script"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"[DRY RUN] Would create a local admin user"* ]]
|
||||||
|
[[ "$output" != *"ACCOUNT_STATE_WAS_ACCESSED"* ]]
|
||||||
|
[[ "$output" != *"TARGET_WAS_ACCESSED"* ]]
|
||||||
|
done
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ show_cmd_help() {
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
bypass) echo "Bypass MDM from Recovery. Creates admin user." ;;
|
bypass) echo "Bypass MDM from Recovery. Creates admin user." ;;
|
||||||
suppress) echo "Suppress enrollment without creating a user." ;;
|
suppress) echo "Suppress enrollment without creating a user." ;;
|
||||||
|
admin) echo "Create an admin user without suppressing enrollment." ;;
|
||||||
heal) echo "Re-apply suppression after macOS updates." ;;
|
heal) echo "Re-apply suppression after macOS updates." ;;
|
||||||
persist) echo "Install auto-heal LaunchDaemon." ;;
|
persist) echo "Install auto-heal LaunchDaemon." ;;
|
||||||
unpersist) echo "Remove auto-heal LaunchDaemon." ;;
|
unpersist) echo "Remove auto-heal LaunchDaemon." ;;
|
||||||
@@ -77,6 +78,7 @@ Bypass / suppress / monitor MDM enrollment on macOS.
|
|||||||
Core:
|
Core:
|
||||||
bypass Full MDM bypass from Recovery (creates admin user)
|
bypass Full MDM bypass from Recovery (creates admin user)
|
||||||
suppress Silence enrollment, no user created
|
suppress Silence enrollment, no user created
|
||||||
|
admin Create an admin user without suppressing enrollment
|
||||||
heal Check + re-apply suppression after macOS updates
|
heal Check + re-apply suppression after macOS updates
|
||||||
|
|
||||||
Persistence:
|
Persistence:
|
||||||
@@ -146,6 +148,7 @@ ALIASES
|
|||||||
wl whitelist
|
wl whitelist
|
||||||
sv suppress
|
sv suppress
|
||||||
by bypass
|
by bypass
|
||||||
|
adm admin
|
||||||
mn monitor
|
mn monitor
|
||||||
mn-install monitor-install
|
mn-install monitor-install
|
||||||
mn-uninstall monitor-uninstall
|
mn-uninstall monitor-uninstall
|
||||||
@@ -198,6 +201,20 @@ cmd_backup() {
|
|||||||
backup_state "$data_mount"
|
backup_state "$data_mount"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd_admin() {
|
||||||
|
if ! is_recovery; then
|
||||||
|
error_exit "Admin creation must run from Recovery mode."
|
||||||
|
fi
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
admin_only_mode "the selected Data volume"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
header "Create Local Admin User"
|
||||||
|
local data_mount
|
||||||
|
data_mount=$(resolve_data_volume)
|
||||||
|
admin_only_mode "$data_mount"
|
||||||
|
}
|
||||||
|
|
||||||
cmd_restore() {
|
cmd_restore() {
|
||||||
header "Restore"
|
header "Restore"
|
||||||
restore_state
|
restore_state
|
||||||
@@ -434,6 +451,7 @@ cmd_interactive_recovery() {
|
|||||||
local options=(
|
local options=(
|
||||||
"Full bypass (create admin + suppress MDM)"
|
"Full bypass (create admin + suppress MDM)"
|
||||||
"Suppress enrollment only"
|
"Suppress enrollment only"
|
||||||
|
"Create local admin user only"
|
||||||
"Auto-heal"
|
"Auto-heal"
|
||||||
"Install pf firewall"
|
"Install pf firewall"
|
||||||
"Remove pf firewall"
|
"Remove pf firewall"
|
||||||
@@ -456,6 +474,9 @@ cmd_interactive_recovery() {
|
|||||||
"Suppress enrollment only")
|
"Suppress enrollment only")
|
||||||
suppress_only_mode "$data_mount"
|
suppress_only_mode "$data_mount"
|
||||||
;;
|
;;
|
||||||
|
"Create local admin user only")
|
||||||
|
admin_only_mode "$data_mount"
|
||||||
|
;;
|
||||||
"Auto-heal")
|
"Auto-heal")
|
||||||
heal_suppress "$data_mount"
|
heal_suppress "$data_mount"
|
||||||
;;
|
;;
|
||||||
@@ -573,6 +594,7 @@ main() {
|
|||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
bypass|by) cmd_bypass ;;
|
bypass|by) cmd_bypass ;;
|
||||||
suppress|sv) cmd_suppress ;;
|
suppress|sv) cmd_suppress ;;
|
||||||
|
admin|adm) cmd_admin ;;
|
||||||
heal) cmd_heal ;;
|
heal) cmd_heal ;;
|
||||||
persist) cmd_persist ;;
|
persist) cmd_persist ;;
|
||||||
unpersist) cmd_unpersist ;;
|
unpersist) cmd_unpersist ;;
|
||||||
|
|||||||
@@ -414,6 +414,21 @@ create_admin_user() {
|
|||||||
success "Admin '$username' created (UID $uid)"
|
success "Admin '$username' created (UID $uid)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hide_user() {
|
||||||
|
local node="$1"
|
||||||
|
local data_mount="$2"
|
||||||
|
local username="$3"
|
||||||
|
|
||||||
|
info "Hiding user account: $username"
|
||||||
|
|
||||||
|
check_user_exists "$node" "$username" || error_exit "Could not find user '$username'"
|
||||||
|
|
||||||
|
dscl -f "$node" localhost -create "/Local/Default/Users/$username" IsHidden "1" 2>/dev/null
|
||||||
|
|
||||||
|
chflags hidden "$data_mount/Users/$username"
|
||||||
|
success "User '$username' hidden"
|
||||||
|
}
|
||||||
|
|
||||||
add_to_filevault() {
|
add_to_filevault() {
|
||||||
local username="$1"
|
local username="$1"
|
||||||
if command -v fdesetup &>/dev/null \
|
if command -v fdesetup &>/dev/null \
|
||||||
@@ -577,6 +592,62 @@ suppress_only_mode() {
|
|||||||
echo -e "${YEL}Never run 'profiles renew' or Erase All Content & Settings.${NC}"
|
echo -e "${YEL}Never run 'profiles renew' or Erase All Content & Settings.${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
admin_only_mode() {
|
||||||
|
local data_mount="$1"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
info "[DRY RUN] Would create a local admin user on $data_mount"
|
||||||
|
info "[DRY RUN] - Create local user"
|
||||||
|
info "[DRY RUN] - Grant user admin permissions"
|
||||||
|
info "[DRY RUN] - Hide newly created admin account"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local node
|
||||||
|
node=$(dscl_node "$data_mount")
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
step "Creating local 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"
|
||||||
|
|
||||||
|
add_to_filevault "$username"
|
||||||
|
|
||||||
|
hide_user "$node" "$data_mount" "$username"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GRN}============================================${NC}"
|
||||||
|
echo -e "${GRN} Local Admin Created ${NC}"
|
||||||
|
echo -e "${GRN}============================================${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${CYAN}Reboot to apply.${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
full_bypass_mode() {
|
full_bypass_mode() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
|
|
||||||
@@ -2741,6 +2812,7 @@ show_cmd_help() {
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
bypass) echo "Bypass MDM from Recovery. Creates admin user." ;;
|
bypass) echo "Bypass MDM from Recovery. Creates admin user." ;;
|
||||||
suppress) echo "Suppress enrollment without creating a user." ;;
|
suppress) echo "Suppress enrollment without creating a user." ;;
|
||||||
|
admin) echo "Create an admin user without suppressing enrollment." ;;
|
||||||
heal) echo "Re-apply suppression after macOS updates." ;;
|
heal) echo "Re-apply suppression after macOS updates." ;;
|
||||||
persist) echo "Install auto-heal LaunchDaemon." ;;
|
persist) echo "Install auto-heal LaunchDaemon." ;;
|
||||||
unpersist) echo "Remove auto-heal LaunchDaemon." ;;
|
unpersist) echo "Remove auto-heal LaunchDaemon." ;;
|
||||||
@@ -2796,6 +2868,7 @@ Bypass / suppress / monitor MDM enrollment on macOS.
|
|||||||
Core:
|
Core:
|
||||||
bypass Full MDM bypass from Recovery (creates admin user)
|
bypass Full MDM bypass from Recovery (creates admin user)
|
||||||
suppress Silence enrollment, no user created
|
suppress Silence enrollment, no user created
|
||||||
|
admin Create a local admin user without suppressing enrollment
|
||||||
heal Check + re-apply suppression after macOS updates
|
heal Check + re-apply suppression after macOS updates
|
||||||
|
|
||||||
Persistence:
|
Persistence:
|
||||||
@@ -2865,6 +2938,7 @@ ALIASES
|
|||||||
wl whitelist
|
wl whitelist
|
||||||
sv suppress
|
sv suppress
|
||||||
by bypass
|
by bypass
|
||||||
|
adm admin
|
||||||
mn monitor
|
mn monitor
|
||||||
mn-install monitor-install
|
mn-install monitor-install
|
||||||
mn-uninstall monitor-uninstall
|
mn-uninstall monitor-uninstall
|
||||||
@@ -2910,6 +2984,20 @@ cmd_suppress() {
|
|||||||
suppress_only_mode "$data_mount"
|
suppress_only_mode "$data_mount"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd_admin() {
|
||||||
|
if ! is_recovery; then
|
||||||
|
error_exit "Admin creation must run from Recovery mode."
|
||||||
|
fi
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
admin_only_mode "the selected Data volume"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
header "Create Local Admin User"
|
||||||
|
local data_mount
|
||||||
|
data_mount=$(resolve_data_volume)
|
||||||
|
admin_only_mode "$data_mount"
|
||||||
|
}
|
||||||
|
|
||||||
cmd_backup() {
|
cmd_backup() {
|
||||||
header "Backup"
|
header "Backup"
|
||||||
local data_mount
|
local data_mount
|
||||||
@@ -3153,6 +3241,7 @@ cmd_interactive_recovery() {
|
|||||||
local options=(
|
local options=(
|
||||||
"Full bypass (create admin + suppress MDM)"
|
"Full bypass (create admin + suppress MDM)"
|
||||||
"Suppress enrollment only"
|
"Suppress enrollment only"
|
||||||
|
"Create local admin user only"
|
||||||
"Auto-heal"
|
"Auto-heal"
|
||||||
"Install pf firewall"
|
"Install pf firewall"
|
||||||
"Remove pf firewall"
|
"Remove pf firewall"
|
||||||
@@ -3175,6 +3264,9 @@ cmd_interactive_recovery() {
|
|||||||
"Suppress enrollment only")
|
"Suppress enrollment only")
|
||||||
suppress_only_mode "$data_mount"
|
suppress_only_mode "$data_mount"
|
||||||
;;
|
;;
|
||||||
|
"Create local admin user only")
|
||||||
|
admin_only_mode "$data_mount"
|
||||||
|
;;
|
||||||
"Auto-heal")
|
"Auto-heal")
|
||||||
heal_suppress "$data_mount"
|
heal_suppress "$data_mount"
|
||||||
;;
|
;;
|
||||||
@@ -3292,6 +3384,7 @@ main() {
|
|||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
bypass|by) cmd_bypass ;;
|
bypass|by) cmd_bypass ;;
|
||||||
suppress|sv) cmd_suppress ;;
|
suppress|sv) cmd_suppress ;;
|
||||||
|
admin|adm) cmd_admin ;;
|
||||||
heal) cmd_heal ;;
|
heal) cmd_heal ;;
|
||||||
persist) cmd_persist ;;
|
persist) cmd_persist ;;
|
||||||
unpersist) cmd_unpersist ;;
|
unpersist) cmd_unpersist ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user