T09 · Insecure Skill Coding Practices
- Location
SKILL.md:19- Finding
Command and Python Code Injection Through the Documented Calculator Command
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 19-24
Vulnerability Type: User-controlled input embedded in shell and Python source code
Risk Level: CriticalVulnerable Code:
markdown ## calculator 当用户要求计算数学表达式时,使用 `exec` 工具执行以下命令进行计算: ```powershell py -c "print(eval('EXPRESSION'))"将 EXPRESSION 替换为用户提供的表达式。
text ### Technical Analysis The instructions require the Agent to replace `EXPRESSION` directly with a user-provided value inside a quoted `py -c` program. The input therefore crosses two unsafe interpretation boundaries: 1. The command shell parses the constructed command. 2. Python parses the interpolated value as executable source code. No escaping, strict validation, argument separation, or arithmetic-only parsing is applied. A crafted expression containing quote characters and Python syntax can terminate the intended string passed to `eval`, append additional Python operations, and alter the remainder of the generated program. Depending on shell metacharacter handling, the same construction may also expose a shell-command injection boundary. The use of `eval` compounds the issue because the calculator accepts executable Python syntax rather than a constrained mathematical grammar. ### Attack Path 1. An attacker submits a crafted value while presenting it as a mathematical expression. 2. The Agent follows `SKILL.md` and substitutes the value directly for `EXPRESSION`. 3. The resulting text is passed to the `exec` tool as a PowerShell command. 4. The crafted input escapes the intended Python string or otherwise changes the generated Python source. 5. The injected Python operations execute with the privileges and filesystem access of the Agent process. ### Impact Assessment Successful exploitation can execute arbitrary Python operations with the Agent's effective operating-system privileges. This may permit reading or modifying accessible files, launching proce ...[truncated 246 chars]- Remediation
View remediation
Remediation Suggestions
- Remove the dynamically constructed
py -ccommand and do not interpolate user input into shell commands or Python source. - Route calculations through a dedicated implementation that parses an arithmetic grammar.
- Use Python's
ast.parsein expression mode and allow only explicitly approved nodes, such as numeric constants and selected unary and binary arithmetic operators. - Reject names, attribute access, function calls, comprehensions, indexing, containers, and all other non-arithmetic syntax.
- Impose limits on input length, nesting depth, integer size, exponent size, and execution time to prevent resource exhaustion.
- If a subprocess is unavoidable, pass arguments as a structured argument array without invoking a shell and provide the expression through a non-code data channel.
- Update
SKILL.mdso it invokes only the hardened calculator implementation.
- Remove the dynamically constructed
