T06 · System Persistence
Error
- Location
- install_launchd.sh:5
- Finding
- Persistent macOS Launch Agents Execute Project-Directory Programs Across Sessions## Vulnerability Details **File Location**: `install_launchd.sh`, lines 5–89 **Vulnerability Type**: Persistent user-level startup services **Risk Level**: High ### Vulnerable Code ```sh LAUNCH_DIR="$HOME/Library/LaunchAgents" mkdir -p "$LAUNCH_DIR" MONITOR_PLIST="$LAUNCH_DIR/com.studywest.openclaw.arcade-monitor.plist" AUTOHEAL_PLIST="$LAUNCH_DIR/com.studywest.openclaw.arcade-autoheal.plist" WATCHDOG_PLIST="$LAUNCH_DIR/com.studywest.openclaw.app-watchdog.plist" cat > "$MONITOR_PLIST" <<EOF ... <key>ProgramArguments</key> <array> <string>/usr/bin/python3</string> <string>-u</string> <string>$DIR/server.py</string> </array> <key>WorkingDirectory</key><string>$DIR</string> <key>RunAtLoad</key><true/> <key>KeepAlive</key><true/> ... EOF cat > "$AUTOHEAL_PLIST" <<EOF ... <key>ProgramArguments</key> <array> <string>/usr/bin/python3</string> <string>-u</string> <string>$DIR/autoheal.py</string> </array> <key>WorkingDirectory</key><string>$DIR</string> <key>RunAtLoad</key><true/> <key>KeepAlive</key><true/> ... EOF cat > "$WATCHDOG_PLIST" <<EOF ... <key>ProgramArguments</key> <array> <string>/usr/bin/python3</string> <string>-u</string> <string>$DIR/app_watchdog.py</string> </array> <key>WorkingDirectory</key><string>$DIR</string> <key>RunAtLoad</key><true/> <key>StartInterval</key><integer>30</integer> ... EOF launchctl bootstrap "gui/$UID_NOW" "$MONITOR_PLIST" launchctl bootstrap "gui/$UID_NOW" "$AUTOHEAL_PLIST" launchctl bootstrap "gui/$UID_NOW" "$WATCHDOG_PLIST" launchctl enable "gui/$UID_NOW/com.studywest.openclaw.arcade-monitor" launchctl enable "gui/$UID_NOW/com.studywest.openclaw.arcade-autoheal" launchctl enable "gui/$UID_NOW/com.studywest.openclaw.app-watchdog" launchctl kickstart -k "gui/$UID_NOW/com.studywest.openclaw.arcade-monitor" launchctl kickstart -k "gui/$UID_NOW/com.studywest.openclaw.arcade-autoheal" launchctl kickstart -k "gui/$UID_NOW/com.studywest.openclaw.app-watchd ...[truncated 2464 chars]
- Remediation
- ## Remediation Suggestions 1. Make launchd installation a separate, clearly documented, explicit opt-in action rather than part of a normal installation path. 2. Explain before execution that three cross-session services will be created, including two continuously restarted services and one 30-second scheduled task. 3. Do not install any service unless every referenced executable is present, integrity-checked, and included in the audited release. 4. Install executable files into a dedicated, versioned directory with restrictive permissions instead of executing mutable files from the source checkout. 5. Verify the ownership and permissions of the installation directory and scripts before registering the services. 6. Avoid `KeepAlive` unless continuous restart is operationally necessary. Configure throttling and bounded restart behavior when it is required. 7. Consider installing only the dashboard service by default and requiring separate consent for auto-heal and watchdog functionality. 8. Validate generated plist files with `plutil` before bootstrapping them. 9. If any bootstrap step fails, roll back all services and plist files created earlier in the operation. 10. Retain and prominently document `uninstall_launchd.sh`, and ensure it also verifies that all associated processes are stopped and generated runtime files are removed where appropriate.
