T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_file.sh:91- Finding
SFTP Batch Command Injection Through Unvalidated Paths
- Content
View full analysis
"$BATCH_FILE" << EOF get $REMOTE_PATH $OUTPUT EOF # Execute SFTP sftp -b "$BATCH_FILE" "$USER_HOST" ``` ### Technical Analysis The script derives `REMOTE_PATH` from a caller-controlled SFTP URL and writes it directly into an SFTP batch file. The caller-controlled `OUTPUT` value is inserted into the same command without validation or escaping. Shell quoting around the here-document does not make its contents safe for the SFTP batch-command parser. In particular, newline characters in either value can terminate the intended `get` command and introduce another SFTP batch instruction. OpenSSH SFTP supports commands interpreted by its own command language, including local shell execution through the `!` command. Consequently, an attacker able to influence the script arguments can turn a file-retrieval operation into arbitrary command execution under the account running the Skill. ### Attack Path 1. The attacker supplies a crafted `sftp://` or `ssh://` source to `fetch_file.sh`. 2. The source contains a newline in its remote-path component followed by an additional SFTP batch instruction. 3. The script extracts the crafted value into `REMOTE_PATH`. 4. The here-document writes both the intended `get` instruction and the injected instruction into the temporary batch file. 5. `sftp -b` parses the injected line as a separate command. 6. If a local-shell instruction is injected, the command runs with the permissions and environment of the Skill process. The output filename is another injection surface if an untrusted caller can control the second script argument. ### Impact Assessment Successful exploitation can provide ...[truncated 602 chars]- Remediation
View remediation
