T09 · Insecure Skill Coding Practices
- Location
SKILL.md:48- Finding
Arbitrary Shell Execution Through Environment File Sourcing
- Content
View full analysis
注意:命令会自动尝试加载系统的 .env 文件获取真实密钥。你绝不能在命令中自行捏造或填写 `SILICONFLOW_API_KEY=sk-xxx` 这样的明文参数。 # 自动寻找并加载环境变量,然后使用相对路径执行脚本 if [ -f ~/.openclaw/.env ]; then source ~/.openclaw/.env; fi && PYTHONPATH=/tmp/pylibs python3 bilibili_extractor.py "<视频URL或BV号>" ``` The instructions later reinforce this behavior: ```text 执行命令模板中的 `source ~/.openclaw/.env` 会自动注入 Key。 ``` ### Technical Analysis The shell `source` command evaluates the entire contents of `~/.openclaw/.env` as executable shell syntax. The Skill only requires the value of `SILICONFLOW_API_KEY`, so evaluating arbitrary commands from the complete file exceeds the minimum privileges necessary. An environment file containing command substitutions, shell functions, redirections, or ordinary commands will execute them with the privileges of the Agent process. Sourcing the complete file can also export unrelated credentials to the Python child process, unnecessarily increasing the number of secrets available to the Skill and its dependencies. ### Attack Path 1. An attacker or compromised local process gains the ability to alter `~/.openclaw/.env`. 2. The attacker adds a shell command, command substitution, or malicious variable assignment to the file. 3. A user asks the Agent to invoke the Bilibili extraction Skill. 4. The Agent runs the documented command template. 5. `source ~/.openclaw/.env` evaluates the attacker's shell code before Python starts. 6. The injected command executes with all filesystem, network, and process privileges available to the Agent. ### Impact Assessment Successful exploitation provides arbitrary command execution under the Agent's operating-system identity. The attacker could read or modify files accessible to that account, access other secrets, initiate network connections, alter the workspac ...[truncated 173 chars]- Remediation
View remediation
