T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/setup_service.sh:207- Finding
Persistent Arbitrary Shell Command Execution with Root Privileges
- Content
View full analysis
Vulnerability Details
File Location:
scripts/setup_service.sh:207-231andscripts/imap_idle_daemon.py:179-186
Vulnerability Type: Root-level arbitrary command execution through a persistent system service
Risk Level: HighVulnerable 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/systemand enables it at startup. The unit does not specifyUser=orGroup=, so systemd runs the daemon as root by default.The daemon obtains
ON_NEW_MAIL_CMDfrom its environment file and passes the complete string tosubprocess.runwithshell=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
View remediation
Remediation Suggestions
- Create a dedicated system account with no interactive login and run the unit using explicit
User=andGroup=directives. - Avoid accepting a shell command string. Represent the handler as a validated executable path and argument list, then invoke it with
shell=False. - Reject shell metacharacters if compatibility requires accepting a textual command.
- Install the daemon into a root-owned directory that is not writable by the service account or ordinary users.
- Add systemd sandboxing controls, including:
NoNewPrivileges=truePrivateTmp=trueProtectSystem=strictProtectHome=trueProtectKernelTunables=trueProtectKernelModules=trueProtectControlGroups=trueRestrictSUIDSGID=trueLockPersonality=trueCapabilityBoundingSet=ReadWritePaths=limited to explicitly required locations
- Use a per-user systemd service when system-wide installation is unnecessary.
- Validate that the configured handler is an absolute path to an approved, non-writable executable.
- Document that enabling the service creates persistence and require explicit confirmation before enabling it.
- Create a dedicated system account with no interactive login and run the unit using explicit
