用途:在本地源码树中扫描命令注入(CWE-78、OWASP A03:2021)漏洞模式。常见来源包括图片转换、压缩包解压、视频处理、DNS 查询等调用 CLI 的场景:先拼接含用户输入的字符串,再交给 shell 解释执行,其中 ; | & $() 反引号等都会变成可执行内容。
主要能力:识别 Python subprocess.run(shell=True) 插值、os.system / os.popen 非字面量参数;Node child_process.exec / execSync 模板字面量;Ruby 反引号插值与 Kernel#system(string);Go exec.Command("sh", "-c", ...) 插值;PHP system / exec / passthru / shell_exec 的 $ 插值;Java Runtime.exec(String) 拼接。CRITICAL 表示用户输入直接进入 shell 构造,HIGH 表示存在 shell 层但需确认可达性。
使用方式:需 Python 3.9+ 与本地源码树。运行 python3 ${CLAUDE_PLUGIN_ROOT}/skills/detecting-command-injection-patterns/scripts/scan_cmdi.py /path/to/repo。选项包括 --output FILE、--format json|jsonl|markdown(默认 markdown)、--min-severity SEV(默认 info)、--include-tests、--languages LIST。输出支持 JSON/JSONL/Markdown,退出码 0 干净、1 存在 high/critical、2 错误。可用于 pre-commit 或 CI 门禁,例如:
python3 ${CLAUDE_PLUGIN_ROOT}/skills/detecting-command-injection-patterns/scripts/scan_cmdi.py
--min-severity high $(git diff --name-only main...HEAD | tr '\n' ' ')
适用场景:安全审计、代码审查、CI 流水线中的自动化检测。
限制:构建脚本中插值固定常量时误报较常见,需人工确认被插值内容是否可由用户触达。修复的通用做法是改用参数列表(数组)而非单一字符串,从而绕过 shell;各语言安全写法可参考资料提到的 references/PLAYBOOK.md 与 references/THEORY.md。以上信息均来自资料,未提供的细节不在此展开。