T06 · System Persistence
Error
- Location
- SKILL.md:91
- Finding
- Boot-Persistent System Service Installed with Elevated Privileges<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:91-117` **Vulnerability Type**: Boot-enabled systemd service registration **Risk Level**: High ### Vulnerable Code ```ini Create `/etc/systemd/system/kkclaw.service`: [Unit] Description=KKClaw Server After=network.target [Service] Type=simple User=pi WorkingDirectory=/home/pi/kkclaw ExecStart=/usr/bin/node /home/pi/kkclaw/main.js start Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` ```bash sudo systemctl daemon-reload sudo systemctl enable kkclaw sudo systemctl start kkclaw ``` ### Technical Analysis The installation instructions direct the user to create a system-wide systemd unit under `/etc/systemd/system`, reload systemd with `sudo`, enable the unit at boot, and start it immediately. The combination of `WantedBy=multi-user.target`, `systemctl enable`, and `Restart=always` provides execution across reboots and automatic relaunch after process termination. Persistent execution is consistent with the advertised always-on server use case, but it is not necessary for the core heartbeat, connection, queue, or model-switching functionality. The application can perform those functions as an ordinary foreground process or through a user-level service. Consequently, system-wide registration using administrative privileges exceeds the minimum privileges necessary for the Skill's core functionality. The service itself runs as `pi`, not as root, which limits direct runtime privileges. However, it executes JavaScript from `/home/pi/kkclaw/main.js`. If that user-writable entry point or its parent directory is subsequently modified, the replacement code will execute automatically at boot and be relaunched by systemd. The unit also lacks standard systemd hardening controls such as `NoNewPrivileges`, `ProtectSystem`, `ProtectHome`, `PrivateTmp`, capability restrictions, and syscall filtering. ### Attack Path 1. The operator follows the documentation and creates the service un ...[truncated 1221 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Make persistent installation explicitly optional rather than part of the default setup. 2. Default to foreground execution with `kkclaw-server start`. 3. Prefer a user-level systemd service installed under `~/.config/systemd/user/` and managed with `systemctl --user`. 4. If a system service is necessary, create a dedicated, non-login service account instead of using a general-purpose `pi` account. 5. Deploy application code into a root-owned, non-user-writable directory such as `/opt/kkclaw`, while keeping only required state directories writable by the service account. 6. Add systemd sandboxing controls, for example: ```ini [Service] User=kkclaw Group=kkclaw NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict ProtectHome=true ProtectKernelTunables=true ProtectKernelModules=true ProtectControlGroups=true RestrictSUIDSGID=true LockPersonality=true CapabilityBoundingSet= AmbientCapabilities= ReadWritePaths=/var/lib/kkclaw ``` 7. Use `Restart=on-failure` with restart-rate limits instead of unconditional `Restart=always`. 8. Document how to stop, disable, and remove the service and how to verify that persistence has been removed. 9. Avoid requiring `sudo` except for an explicitly selected system-wide installation mode. ]]>
