ClawSkills logoClawSkills

ClawScan

ClawHub 技能的安全扫描器。在安装前审查第三方技能 — 检测危险模式、可疑代码和有风险的依赖项。

介绍

# 🛡️ SkillGuard — ClawHub Security Scanner

> **“信任,但要核实。”**

ClawHub 没有审核流程。任何代理都可以发布任何技能。SkillGuard 提供了缺失的安全层 —— 在触及您的系统之前扫描技能的危险模式、漏洞依赖和可疑行为。

---

## 🚨 为什么这很重要

第三方技能可能:

| 风险 | 影响 | |------|--------| | **执行任意代码** | 完全系统沦陷 | | **访问您的文件系统** | 数据窃取,勒索软件 | | **读取环境变量** | API 密钥窃取 ($$$) | | **通过 HTTP 外泄数据** | 隐私泄露 | | **安装恶意依赖** | 供应链攻击 | | **植入后门** | 长期沦陷 | | **提权** | Root 访问权限 |

**一个恶意技能 = 游戏结束。**

SkillGuard 帮助您在安装前捕获威胁。

---

## 📦 安装

```bash clawhub install clawscan ```

或手动安装: ```bash git clone https://github.com/G0HEAD/skillguard cd skillguard chmod +x scripts/skillguard.py ```

### 需求 - Python 3.8+ - `clawhub` CLI(用于远程扫描)

---

## 🚀 快速开始

```bash # Scan a skill BEFORE installing python3 scripts/skillguard.py scan some-random-skill

# Scan a local folder (your own skills or downloaded) python3 scripts/skillguard.py scan-local ./path/to/skill

# Audit ALL your installed skills python3 scripts/skillguard.py audit-installed

# Generate detailed security report python3 scripts/skillguard.py report some-skill --format markdown

# Check dependencies for known vulnerabilities python3 scripts/skillguard.py deps ./path/to/skill ```

---

## 🔍 SkillGuard 检测内容

### 🔴 严重 —— 阻止安装

这些模式表明存在严重的安全风险:

| 类别 | 模式 | 风险 | |----------|----------|------| | **代码执行** | `eval()`, `exec()`, `compile()` | 任意代码执行 | | **Shell 注入** | `subprocess(shell=True)`, `os.system()`, `os.popen()` | 命令注入 | | **子进程** | `child_process.exec()`, `child_process.spawn()` | Shell 访问 (Node.js) | | **凭据窃取** | 访问 `~/.ssh/`, `~/.aws/`, `~/.config/` | 私钥/凭据窃取 | | **系统文件** | `/etc/passwd`, `/etc/shadow` | 系统沦陷 | | **递归删除** | `rm -rf`, `shutil.rmtree('/')` | 数据破坏 | | **权限提升** | `sudo`, `setuid`, `chmod 777` | Root 访问权限 | | **反向 Shell** | Socket + subprocess 模式 | 远程访问 | | **加密货币挖矿** | 矿池 URL, `stratum://` | 资源窃取 |

### 🟡 警告 —— 安装前请审查

这些模式可能是合法的,但值得检查:

| 类别 | 模式 | 关注点 | |----------|----------|---------| | **网络请求** | `requests.post()`, `fetch()` POST | 数据发往何处? | | **环境访问** | `os.environ`, `process.env` | 哪些变量? | | **文件写入** | `open(..., 'w')`, `writeFile()` | 正在保存什么? | | **Base64 编码** | `base64.encode()`, `btoa()` | 混淆的载荷? | | **外部 IP** | 硬编码 IP 地址 | 外泄端点? | | **批量文件操作** | `shutil.copytree()`, `glob` | 大规模数据访问? | | **持久化** | `crontab`, `systemctl`, `.bashrc` | 开机自启? | | **包安装** | `pip install`, `npm install` | 供应链风险 |

### 🟢 信息 —— 已记录但属正常

| 类别 | 模式 | 说明 | |----------|----------|------| | **文件读取** | `open(..., 'r')`, `readFile()` | 技能预期行为 | | **JSON 解析** | `json.load()`, `JSON.parse()` | 数据处理 | | **日志记录** | `print()`, `console.log()` | 调试 | | **标准导入** | `import os`, `import sys` | 常用库 |

---

## 📊 扫描输出示例

``` ╔══════════════════════════════════════════════════════════════╗ ║ 🛡️ SKILLGUARD SECURITY REPORT ║ ╠══════════════════════════════════════════════════════════════╣ ║ Skill: suspicious-helper v1.2.0 ║ ║ Author: unknown-user ║ ║ Files: 8 analyzed ║ ║ Scan Time: 2024-02-03 05:30:00 UTC ║ ╚══════════════════════════════════════════════════════════════╝

📁 FILES SCANNED ──────────────────────────────────────────────────────────────── ✓ SKILL.md (541 bytes) ✓ scripts/main.py (2.3 KB) ✓ scripts/utils.py (1.1 KB) ✓ scripts/network.py (890 bytes) ✓ config.json (234 bytes) ✓ requirements.txt (89 bytes) ✓ package.json (312 bytes) ✓ install.sh (156 bytes)

🔴 CRITICAL ISSUES (3) ──────────────────────────────────────────────────────────────── [CRIT-001] scripts/main.py:45 │ Pattern: eval() with external input │ Risk: Arbitrary code execution │ Code: result = eval(user_input) │ [CRIT-002] scripts/utils.py:23 │ Pattern: subprocess with shell=True │ Risk: Command injection vulnerability │ Code: subprocess.run(cmd, shell=True) │ [CRIT-003] install.sh:12 │ Pattern: Recursive delete with variable │ Risk: Potential data destruction │ Code: rm -rf $TARGET_DIR/*

🟡 WARNINGS (5) ──────────────────────────────────────────────────────────────── [WARN-001] scripts/network.py:15 — HTTP POST to external URL [WARN-002] scripts/main.py:78 — Reads OPENAI_API_KEY [WARN-003] requirements.txt:3 — Unpinned dependency: requests [WARN-004] scripts/utils.py:45 — Base64 encoding detected [WARN-005] config.json — Hardcoded IP: 192.168.1.100

🟢 INFO (2) ──────────────────────────────────────────────────────────────── [INFO-001] scripts/main.py:10 — Standard file read operations [INFO-002] requirements.txt — 3 dependencies declared

📦 DEPENDENCY ANALYSIS ──────────────────────────────────────────────────────────────── requirements.txt: ⚠️ requests (unpinned - specify version!) ✓ json (stdlib) ✓ pathlib (stdlib)

package.json: ⚠️ [email protected] (CVE-2021-3749 - upgrade to 0.21.2+)

════════════════════════════════════════════════════════════════ VERDICT: 🚫 DANGEROUS ════════════════════════════════════════════════════════════════ ⛔ DO NOT INSTALL THIS SKILL 3 critical security issues found: • Arbitrary code execution via eval() • Command injection via shell=True • Dangerous file deletion pattern Manual code review required before any use. ════════════════════════════════════════════════════════════════ ```

---

## 🎯 命令参考

### `scan <skill-name>` 在安装前从 ClawHub 获取并扫描技能。

```bash skillguard scan cool-automation-skill skillguard scan cool-automation-skill --verbose skillguard scan cool-automation-skill --json > report.json ```

### `scan-local <path>` 扫描本地技能目录。

```bash skillguard scan-local ./my-skill skillguard scan-local ~/downloads/untrusted-skill --strict ```

### `audit-installed` 扫描您工作区中的所有技能。

```bash skillguard audit-installed skillguard audit-installed --fix # Attempt to fix issues ```

### `deps <path>` 分析已知漏洞的依赖项。

```bash skillguard deps ./skill-folder skillguard deps ./skill-folder --update-db # Refresh vuln database ```

### `report <skill> [--format]` 生成详细的安全报告。

```bash skillguard report suspicious-skill --format markdown > report.md skillguard report suspicious-skill --format json > report.json skillguard report suspicious-skill --format html > report.html ```

### `allowlist <skill>` 将技能标记为已手动审查并受信任。

```bash skillguard allowlist my-trusted-skill skillguard allowlist --list # Show all trusted skills skillguard allowlist --remove old-skill ```

### `watch` 监控新技能版本并自动扫描更新。

```bash skillguard watch --interval 3600 # Check every hour ```

---

## ⚙️ 配置

创建 `~/.skillguard/config.json`:

```json { "severity_threshold": "warning", "auto_scan_on_install": true, "block_critical": true, "trusted_authors": [ "official", "PaxSwarm", "verified-publisher" ], "allowed_domains": [ "api.openai.com", "api.anthropic.com", "api.github.com", "clawhub.ai" ], "ignored_patterns": [ "test_*.py", "*_test.js", "*.spec.ts" ], "custom_patterns": [ { "regex": "my-internal-api\\.com", "severity": "info", "description": "Internal API endpoint" } ], "vuln_db_path": "~/.skillguard/vulns.json", "report_format": "markdown", "color_output": true } ```

---

## 🔐 安全等级

扫描后,技能会被分配一个安全等级:

| 等级 | 徽章 | 含义 | 建议 | |-------|-------|---------|----------------| | **已验证** | ✅ | 受信任的作者,无问题 | 安全安装 | | **干净** | 🟢 | 未发现问题 | 可能安全 | | **需审查** | 🟡 | 仅有警告 | 安装前请阅读 | | **可疑** | 🟠 | 多处警告 | 需仔细审查 | | **危险** | 🔴 | 严重问题 | 请勿安装 | | **恶意** | ⛔ | 已知恶意软件模式 | 阻止并报告 |

---

## 🔄 集成工作流

### Pre-Install Hook ```bash # Add to your workflow skillguard scan $SKILL && clawhub install $SKILL ```

### CI/CD Pipeline ```yaml # GitHub Actions example - name: Security Scan run: | pip install skillguard skillguard scan-local ./my-skill --strict --exit-code ```

### Automated Monitoring ```bash # Cron job for daily audits 0 9 * * * /path/to/skillguard audit-installed --notify ```

---

## 📈 漏洞数据库

SkillGuard 维护一个已知漏洞的本地数据库:

```bash # Update vulnerability database skillguard update-db

# Check database status skillguard db-status

# Report a new vulnerability skillguard report-vuln --skill bad-skill --details "Description..." ```

**来源:** - CVE 数据库 (Python 包) - npm Advisory Database - GitHub Security Advisories - 社区报告

---

## 🚫 限制

SkillGuard 是 **第一道防线**,而非保证:

| 限制 | 说明 | |------------|-------------| | **代码混淆** | 坚决的攻击者可以隐藏恶意代码 | | **动态代码** | 运行时生成的代码较难分析 | | **误报** | 合法代码可能触发警告 | | **零日漏洞** | 新攻击模式无法被检测到 | | **依赖项** | 深层传递依赖扫描有限 |

**纵深防御:** 将 SkillGuard 与以下方式结合使用: - 沙箱执行环境 - 网络监控 - 定期审计 - 最小权限原则

---

## 🤝 贡献

发现了我们遗漏的危险模式?帮助改进 SkillGuard:

### 添加模式 ```json { "id": "CRIT-XXX", "regex": "dangerous_function\\(", "severity": "critical", "category": "code_execution", "description": "Dangerous function call", "cwe": "CWE-94", "remediation": "Use safe_alternative() instead", "file_types": [".py", ".js"] } ```

### 报告误报 ```bash skillguard report-fp --pattern "WARN-005" --reason "Legitimate use case" ```

---

## 📜 更新日志

### v2.0.0 (当前) - 全面的模式数据库(50+ 模式) - 依赖漏洞扫描 - 多种输出格式(JSON, Markdown, HTML) - 配置文件支持 - 受信任作者系统 - 监控更新的观察模式 - 改进的报告,包含 CWE 引用

### v1.0.0 - 初始发布 - 基本模式检测 - 本地和远程扫描 - 审计已安装的技能

---

## 📄 许可证

MIT License — 自由使用,回馈贡献。

---

## 🛡️ 保持安全

> “在代理生态系统中,信任通过透明度建立。 > 您安装的每个技能都是您选择运行的代码。 > 明智选择。时刻核实。”

*由 [PaxSwarm](https://github.com/G0HEAD) 构建 — 守护集群,从每一个技能开始* 🐦‍⬛

---

**链接:** - [ClawHub](https://clawhub.ai/skills/clawscan) - [GitHub](https://github.com/G0HEAD/skillguard) - [报告问题](https://github.com/G0HEAD/skillguard/issues) - [模式数据库](https://github.com/G0HEAD/skillguard/blob/main/patterns.json)

更多产品