T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/setup_service.sh:207
- Finding
- Persistent Arbitrary Shell Command Execution with Root Privileges## Vulnerability Details **File Location**: `scripts/setup_service.sh:207-231` and `scripts/imap_idle_daemon.py:179-186` **Vulnerability Type**: Root-level arbitrary command execution through a persistent system service **Risk Level**: High ### Vulnerable Code `scripts/setup_service.sh:207-231`: ```bash # Write systemd unit cat > "$unit_file" <<EOF [Unit] Description=IMAP IDLE Watcher ($ACCOUNT) After=network-online.target Wants=network-online.target [Service] Type=simple EnvironmentFile=$env_file ExecStart=$(command -v python3) $DAEMON_SCRIPT Restart=always RestartSec=10 StandardOutput=journal StandardError=journal [Install] WantedBy=multi-user.target EOF echo " ✅ Unit file: $unit_file" # Enable and start systemctl daemon-reload systemctl enable "$SERVICE_NAME" systemctl start "$SERVICE_NAME" ``` `scripts/imap_idle_daemon.py:179-186`: ```python result = subprocess.run( ON_NEW_MAIL_CMD, shell=True, capture_output=True, text=True, timeout=300, env=env, ) ``` ### Technical Analysis The installer creates a system-wide unit under `/etc/systemd/system` and enables it at startup. The unit does not specify `User=` or `Group=`, so systemd runs the daemon as root by default. The daemon obtains `ON_NEW_MAIL_CMD` from its environment file and passes the complete string to `subprocess.run` with `shell=True`. Consequently, shell operators, command substitutions, redirections, pipelines, and multiple commands are accepted. This is intentional command functionality, but it becomes a privilege-escalation boundary violation because the handler inherits the service's root privileges. The persistence mechanism itself is consistent with the Skill's declared real-time monitoring functionality. However, running the watcher and user-defined handler as root is not necessary for connecting to an IMAP server or processing email headers. The enabled service also ca ...[truncated 1535 chars]
- Remediation
- ## Remediation Suggestions 1. Create a dedicated system account with no interactive login and run the unit using explicit `User=` and `Group=` directives. 2. Avoid accepting a shell command string. Represent the handler as a validated executable path and argument list, then invoke it with `shell=False`. 3. Reject shell metacharacters if compatibility requires accepting a textual command. 4. Install the daemon into a root-owned directory that is not writable by the service account or ordinary users. 5. Add systemd sandboxing controls, including: - `NoNewPrivileges=true` - `PrivateTmp=true` - `ProtectSystem=strict` - `ProtectHome=true` - `ProtectKernelTunables=true` - `ProtectKernelModules=true` - `ProtectControlGroups=true` - `RestrictSUIDSGID=true` - `LockPersonality=true` - `CapabilityBoundingSet=` - `ReadWritePaths=` limited to explicitly required locations 6. Use a per-user systemd service when system-wide installation is unnecessary. 7. Validate that the configured handler is an absolute path to an approved, non-writable executable. 8. Document that enabling the service creates persistence and require explicit confirmation before enabling it.
