T06 · System Persistence
- Location
install_launchd.sh:5- Finding
Persistent macOS Launch Agents Execute Project-Directory Programs Across Sessions
- Content
View full analysis
Vulnerability Details
File Location:
install_launchd.sh, lines 5–89
Vulnerability Type: Persistent user-level startup services
Risk Level: HighVulnerable 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
View remediation
Remediation Suggestions
- Make launchd installation a separate, clearly documented, explicit opt-in action rather than part of a normal installation path.
- Explain before execution that three cross-session services will be created, including two continuously restarted services and one 30-second scheduled task.
- Do not install any service unless every referenced executable is present, integrity-checked, and included in the audited release.
- Install executable files into a dedicated, versioned directory with restrictive permissions instead of executing mutable files from the source checkout.
- Verify the ownership and permissions of the installation directory and scripts before registering the services.
- Avoid
KeepAliveunless continuous restart is operationally necessary. Configure throttling and bounded restart behavior when it is required. - Consider installing only the dashboard service by default and requiring separate consent for auto-heal and watchdog functionality.
- Validate generated plist files with
plutilbefore bootstrapping them. - If any bootstrap step fails, roll back all services and plist files created earlier in the operation.
- 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.
