T06 · System Persistence
Error
- Location
- SKILL.md:56
- Finding
- Persistent systemd service runs the bot with unnecessary root privileges<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 56–72 **Vulnerability Type**: System-wide persistence and excessive service privileges **Risk Level**: High ### Vulnerable Code ```bash # systemd service sudo tee /etc/systemd/system/signal-bot.service << 'EOF' [Unit] Description=Trading Signal Bot After=network.target [Service] Type=simple WorkingDirectory=/root/signals ExecStart=/usr/bin/python3 signal_bot.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target EOF sudo systemctl enable --now signal-bot ``` ### Technical Analysis The deployment instructions use `sudo` to create a system-wide systemd unit and enable it at boot. The service also uses `/root/signals` as its working directory and does not specify a `User=` or `Group=` directive. System services run as root by default when no service account is configured. `Restart=always` and `systemctl enable` cause the process to restart after failures and execute again after system reboots. Running continuously is reasonable for a real-time monitoring bot, but system-wide root persistence is not necessary for its declared functions. The bot only needs outbound network access and write access to its state and log files. The unit also lacks systemd hardening controls such as: - `NoNewPrivileges=true` - `ProtectSystem=strict` - `ProtectHome=true` - `PrivateTmp=true` - `CapabilityBoundingSet=` - `RestrictAddressFamilies=` - A dedicated, narrowly writable state directory Consequently, the bot itself and every imported Python dependency execute with root privileges. Any future compromise of the script, configuration, working directory, or dependency would inherit those privileges and the service's cross-session persistence. ### Attack Path 1. A user follows the documented deployment instructions with `sudo`. 2. A root-level service is installed under `/etc/systemd/system/`. 3. The service is enabled at boot and configured to restart indefinitely. 4. An attacker compromises ...[truncated 924 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create a dedicated unprivileged service account with no interactive login. 2. Set explicit `User=` and `Group=` directives in the unit. 3. Store code outside `/root`, such as `/opt/signal-bot`, and place writable state under `/var/lib/signal-bot`. 4. Grant write access only to the state and log locations required by the application. 5. Add systemd sandboxing directives, for example: ```ini [Service] Type=simple User=signalbot Group=signalbot WorkingDirectory=/opt/signal-bot ExecStart=/opt/signal-bot/.venv/bin/python /opt/signal-bot/scripts/signal_bot.py Restart=on-failure RestartSec=10 NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict ProtectHome=true ProtectKernelTunables=true ProtectKernelModules=true ProtectControlGroups=true LockPersonality=true RestrictSUIDSGID=true CapabilityBoundingSet= ReadWritePaths=/var/lib/signal-bot /var/log/signal-bot RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 ``` 6. Prefer a user-level systemd unit where system-wide startup is not required. 7. Clearly label persistent deployment as optional and document removal: ```bash sudo systemctl disable --now signal-bot sudo rm /etc/systemd/system/signal-bot.service sudo systemctl daemon-reload ``` 8. Protect the service working directory from modification by the runtime account. ]]>
