T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/strict-execution.sh:130
- Finding
- Arbitrary Command Injection Through the sudo-cmd Interface## Vulnerability Details **File Location**: `scripts/strict-execution.sh`, lines 130-145 and 279-289 **Vulnerability Type**: Caller-controlled shell command execution through `sh -c` **Risk Level**: High ### Vulnerable Code ```bash execute_with_sudo() { local command="$1" local password="${2:-}" log_info "Executing with sudo: $command" if [ -n "$password" ]; then echo "$password" | sudo -S -- sh -c "$command" else sudo -- sh -c "$command" fi return $? } execute_without_sudo() { local command="$1" log_info "Executing: $command" sh -c "$command" return $? } ``` The affected mode obtains the command directly from a positional argument: ```bash "sudo-cmd") if [ $# -lt 2 ]; then log_error "Missing command or description" return 1 fi local command="$1" local description="$2" local password="${3:-}" example_sudo_operation "$command" "$description" "$password" ;; ``` ### Technical Analysis The `sudo-cmd` interface accepts an entire shell program as a caller-controlled string. Both execution functions pass that string to `sh -c`, causing shell metacharacters, command substitutions, pipelines, redirections, and command separators to be interpreted. Quoting `"$command"` when passing it to `sh -c` only preserves the string as one argument to the child shell; it does not prevent that child shell from parsing the content as executable shell syntax. In the privileged branch, the parser runs under `sudo`, so every command included in the string executes with root privileges after authentication. The interactive confirmation step does not provide a technical security boundary. A deceptive description can conceal the effects of the supplied command, and the implementation neither parses nor allowlists the executable and arguments. ### Attack Path 1. An atta ...[truncated 1086 chars]
- Remediation
- ## Remediation Suggestions - Remove support for arbitrary shell command strings. - Represent commands as executable-and-argument arrays and invoke them directly without `sh -c`. - Define a strict allowlist of supported operations and executables. - Validate each argument according to its expected type rather than validating the complete command as text. - Do not attempt to sanitize shell metacharacters as a substitute for removing shell-string evaluation. - For privileged operations, invoke only the specifically approved executable: ```bash execute_with_sudo() { local -a command=("$@") sudo -- "${command[@]}" } execute_without_sudo() { local -a command=("$@") "${command[@]}" } ``` - If arbitrary administrative commands are an intentional requirement, provide them only for manual display and require the user to execute them independently in a trusted terminal. - Add tests demonstrating that separators, substitutions, redirections, and newlines are treated as literal arguments or rejected.
