T09 · Insecure Skill Coding Practices
- Location
ADVANCED.md:133- Finding
Shell Command Injection Through Untrusted PMID Input
- Content
View full analysis
abstract_{}.txt sleep 0.3 ' ``` From `EXAMPLES.md`: ```bash # Download abstracts in parallel cat pmids.txt | xargs -P 5 -I {} bash -c 'efetch -db pubmed -id {} -format abstract > {}.txt; sleep 0.3' ``` ### Technical Analysis Each line from `pmids.txt` is substituted directly into shell source passed to `bash -c`. The substituted value is not quoted, validated, or passed as a positional argument. Shell metacharacters in a crafted line are therefore interpreted as shell syntax rather than as part of a PubMed identifier. For example, a line containing a command separator can terminate the intended `efetch` command and introduce an additional command. Both the `-id` value and output filename are injection points. The documented use case only requires numeric PubMed identifiers, so accepting arbitrary shell syntax exceeds the minimum input privileges necessary for the declared functionality. ### Attack Path 1. An attacker creates, supplies, or modifies a `pmids.txt` file. 2. The file contains a line with shell metacharacters and an attacker-selected command. 3. A user or Agent runs one of the documented parallel-processing commands. 4. `xargs` substitutes the malicious line into the text of the `bash -c` program. 5. Bash parses and executes the injected command with the privileges of the user or Agent. ### Impact Assessment Successful exploitation provides arbitrary command execution under the invoking account. Depending on that account's permissions, an attacker could: - Read or modify files available to the Agent. - Access environment variables and locally stored API cre ...[truncated 324 chars]- Remediation
View remediation
"${pmid}.txt" sleep 0.3 ' _ '{}' ``` - Reject the entire input or report the offending line when invalid data is encountered rather than silently processing it. - Prefer a shell loop or a purpose-built parallel execution mechanism that does not require dynamically generated shell source. ]]>
