T09 · Insecure Skill Coding Practices
- Location
scripts/cooldown.sh:9- Finding
Shell Command Injection Through eval-Based Command Execution
- Content
View full analysis
"$TIMESTAMP_FILE" echo "✅ Success. Timestamp updated." else echo "❌ Command failed. Timestamp NOT updated." exit 1 fi ``` ### Technical Analysis All command arguments are flattened into the `COMMAND` string and subsequently passed to `eval`. Unlike direct argument execution, `eval` causes shell metacharacters, substitutions, redirections, and command separators contained in the input to be interpreted a second time. The wrapper is intended to execute a supplied command, but `eval` exceeds what is necessary for that functionality. It destroys argument boundaries and allows data intended to be an ordinary argument to become shell syntax. This becomes exploitable whenever a trusted caller invokes the wrapper with a command containing partially untrusted values. For example, a value containing `;`, `$(...)`, backticks, or shell redirection can execute an additional command under the account running the Skill. ### Attack Path 1. An attacker supplies or influences an argument passed to `cooldown.sh`. 2. A trusted caller invokes the wrapper, for example: ```bash ./scripts/cooldown.sh monitor 60 echo 'untrusted; id > /tmp/injected' ``` 3. The script joins the command and its arguments into one string. 4. `eval` reparses that string as shell source. 5. The injected command executes with the privileges and environment of the Skill process. 6. Depending on process permissions, the attacker can read or modify accessible files, invoke network utilities, a ...[truncated 571 chars]- Remediation
View remediation
"$TIMESTAMP_FILE" else exit 1 fi ``` - Require at least one command argument and reject an empty command. - If only a fixed set of operations is needed, replace generic command execution with an explicit allowlist. - Do not build shell commands by concatenating untrusted values. - Run the wrapper under a minimally privileged service account without access to unrelated credentials or sensitive files. - Add tests using arguments containing spaces, semicolons, command substitutions, glob characters, and redirections to verify that they remain literal arguments. ]]>
