From vuln-skills
Audits Python code for injection vulnerabilities including command execution (subprocess, os.system), SQL queries (cursor.execute, sqlalchemy.text), eval/exec calls, and template rendering (Jinja2, Mako SSTI).
How this skill is triggered — by the user, by Claude, or both
Slash command
/vuln-skills:vuln-patterns-injectionThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
当审计 Python 代码中涉及动态命令构造、SQL 拼接、eval/exec 调用、模板渲染时加载此 Skill。
当审计 Python 代码中涉及动态命令构造、SQL 拼接、eval/exec 调用、模板渲染时加载此 Skill。
通用检测模型,适用于此类漏洞的所有变体。
Sources(用户输入入口):
request.args, request.form, request.json, FastAPI Query(), Path() 参数tool_call.arguments, Agent 的 Action Input, LLM 生成的代码字符串column 参数传入聚合函数)_target_ 字段、YAML/JSON 配置中的类路径kubectl 命令参数、工具函数的用户输入InMemoryVectorStore 的 filter lambda 字符串Sinks(危险函数/操作):
eval(), exec(), compile(), __import__()(注意:开发者常误用 eval() 替代 ast.literal_eval(),如用 eval() 解析布尔值)Template(user_input).render(), Environment().from_string(user_input), Mako Template(user_input).render()subprocess.run(shell=True), subprocess.Popen(shell=True), os.system(), os.popen()sqlalchemy.text() 拼接用户输入, cursor.execute() 字符串拼接, ORM .extra(), .raw()instantiate(), importlib.import_module() + getattr()python_repl_ast 工具(LangChain), local_python_executor(smolagents)ast.parse() + exec(compile(...))(当 AST 白名单检查不完整时)Sanitization(安全屏障):
cursor.execute(sql, params) 而非字符串拼接str.lower() in ('true', '1') 替代 eval() 做布尔解析__class__, __globals__)shlex.quote() 或避免 shell=Truesubprocess.run(shlex.split(cmd), shell=False) — 避免 shell 解析检测路径:
搜索 sink 调用的 Grep 模式:
# 代码执行
grep -rn "eval(" --include="*.py"
grep -rn "exec(" --include="*.py"
# 命令执行
grep -rn "shell=True" --include="*.py"
grep -rn "os\.system\|os\.popen" --include="*.py"
# SQL 拼接
grep -rn "sqlalchemy\.text\|\.execute(" --include="*.py"
grep -rn "\.extra(\|\.raw(" --include="*.py"
# 模板注入
grep -rn "Template(" --include="*.py"
grep -rn "from_string(" --include="*.py"
# 动态实例化
grep -rn "instantiate(\|__import__(" --include="*.py"
eval(, exec(, subprocess.*shell=True, sqlalchemy.text(, os.system()eval() 用于解析布尔值/简单类型(应使用类型转换替代)allow_dangerous_code=Trueshell=True 执行用户传入的命令instantiate() / __import__() 接受用户可控的类路径eval( 和 exec( 调用,检查参数是否包含用户输入或外部数据subprocess / os.system / os.popen,检查是否使用 shell=True 且参数含用户输入sqlalchemy.text() / 原生 SQL 拼接,检查是否有未参数化的用户输入.extra(), .raw(), .min(), .max() 等接受字符串参数的方法allow_dangerous_code 配置项,检查是否硬编码为 Trueinstantiate() / _target_ 字段,检查是否有用户可控的类路径ast.parse + compile + exec 模式,检查 AST 白名单是否覆盖所有逃逸路径__class__, __globals__, __builtins__ 等 dunder 属性访问,检查沙箱是否阻止Template( / Environment().from_string( 和 Mako Template(,检查参数是否包含用户输入(SSTI 模板注入)shlex.quote 或 shlex.split 使用情况,确认命令执行是否采用列表参数 + shell=False 模式以下模式不是此类漏洞:
eval() 的参数是硬编码常量字符串 -- 无用户可控输入subprocess.run(["cmd", "arg"], shell=False) 使用列表参数且无 shell -- 参数不会被 shell 解析ast.literal_eval() 用于解析 JSON/字面量 — 只接受字面量表达式,不执行代码(但注意不要用 eval() 误替代 ast.literal_eval())sqlalchemy.text() 配合 .bindparams() 使用 -- 参数已绑定,不存在拼接.filter(Model.field == value) -- 使用 ORM 表达式 API,自动参数化instantiate() 的 _target_ 来自代码内部硬编码的配置 -- 非用户可控以下模式需要深入检查:
eval(request_value) if isinstance(value, str) else value -- 虽然做了类型检查但 eval 仍危险sqlalchemy.text(f"{user_input}") 即使被包裹在 ORM 函数中 -- ORM 包装不改变 SQL 注入本质subprocess.run(cmd, shell=True) 即使 cmd 经过了"过滤" -- 过滤可能不完整exec() 沙箱 -- 白名单遗漏可导致沙箱逃逸allow_dangerous_code 通过环境变量/配置控制 -- 需确认默认值是否安全__import__(module_path) 即使有前缀检查 -- 前缀检查可能被绕过(如 ..)详见 references/cases.md(7 个真实案例,需要时加载)。
npx claudepluginhub yhy0/ghsa-skill-builder --plugin vuln-skillsDetects SQL, command, and template injection caused by user input reaching an interpreter without parameterization. Checks concatenated query strings, shell commands, eval/exec calls, and unsafe template usage.
Audits Go code for injection vulnerabilities including OS command (CWE-78), SQL (CWE-89), template (CWE-94/77), and argument (CWE-88) via exec.Command, database/sql, text/template.
Detects SQL injection vulnerabilities by tracing user inputs through code to database queries, flagging unsafe patterns like concatenation and unparameterized ORMs. Scans frameworks including Django, Rails, Express, Go.