T06 · System Persistence
Error
- Location
- scripts/setup.sh:23
- Finding
- Persistent Systemd User Service Installed and Enabled by Default<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup.sh:23-45` **Vulnerability Type**: Cross-session service persistence **Risk Level**: High ### Vulnerable Code ```bash # Create systemd user service mkdir -p "$SERVICE_DIR" cat > "$SERVICE_FILE" <<EOF [Unit] Description=LAN Media Server (port $PORT) After=network.target [Service] ExecStart=$NODE_BIN $SERVER_SCRIPT Restart=always RestartSec=3 Environment=NODE_ENV=production Environment="MEDIA_PORT=$PORT" Environment="MEDIA_ROOT=$MEDIA_ROOT" [Install] WantedBy=default.target EOF echo "📝 Created service: $SERVICE_FILE" # Enable and start systemctl --user daemon-reload systemctl --user enable media-server.service systemctl --user restart media-server.service ``` ### Technical Analysis The setup script creates a systemd user service under `~/.config/systemd/user`, configures it with `Restart=always`, and enables it under `default.target`. This causes the server to continue running after the original skill invocation and to restart following failures. If user lingering is enabled, it may also start and remain active without an interactive login. The behavior is disclosed in the documentation, but it is still a cross-session persistence mechanism. It also leaves a network-facing process active until the user explicitly disables it. Because `ExecStart` points directly to the skill's server script, later modification or replacement of that script changes what the persistent service executes. ### Attack Path 1. The user follows the documented instruction and runs `bash scripts/setup.sh`. 2. The script writes `media-server.service` into the user's systemd configuration. 3. It reloads systemd, enables the unit, and starts it immediately. 4. The service listens for network requests and is automatically restarted after termination or failure. 5. If the referenced script is subsequently altered, systemd executes the altered code when the service restarts. ### Impact Assessment The service execut ...[truncated 394 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Run the media server as an explicit, transient foreground process by default. - Do not enable the systemd service automatically during initial setup. - If persistent operation is necessary, require a separate opt-in command and clearly explain its lifetime and network exposure. - Consider using `systemd-run --user` with a limited runtime for temporary sharing sessions. - Add a documented uninstallation command that stops and disables the service, removes the unit file, and reloads systemd: ```bash systemctl --user disable --now media-server.service rm -f "$HOME/.config/systemd/user/media-server.service" systemctl --user daemon-reload ``` - Apply systemd sandboxing controls such as `NoNewPrivileges=yes`, `PrivateTmp=yes`, `ProtectSystem=strict`, and narrowly scoped `ReadOnlyPaths`/`ReadWritePaths`. ]]>
