scagogogo/cwe-skills

GitHub: scagogogo/cwe-skills

面向 CWE 数据的多接入方式集成层,为 AI Agent 与开发者提供弱点枚举的解析、查询与关系导航能力。

Stars: 3 | Forks: 0

# CWE Skills — AI 原生 CWE 集成 [![Go Reference](https://pkg.go.dev/badge/github.com/scagogogo/cwe-skills.svg)](https://pkg.go.dev/github.com/scagogogo/cwe-skills) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/f0c8b461c6071233.svg)](https://github.com/scagogogo/cwe-skills/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) **[CWE (Common Weakness Enumeration)](https://cwe.mitre.org/) 的 AI 原生集成层** — 提供四种接入方式:**Skills**、Go SDK、CLI 和 MCP。 ## 🚀 四种集成方式 | # | 方式 | 最适用于 | 一行代码设置 | |---|--------|----------|----------------| | 1 | **Skills** | AI agents (Claude, GPT 等) | 复制下方的 prompt | | 2 | **Go SDK** | Go 应用和库 | `go get github.com/scagogogo/cwe-skills` | | 3 | **CLI** | Shell 脚本和开发工作流 | 从 [Releases](https://github.com/scagogogo/cwe-skills/releases/latest) 下载 | | 4 | **MCP** | 兼容 MCP 的 AI 工具 | *(即将推出)* | ## 1. Skills — AI Agent 集成 将此代码块复制并粘贴到您的 AI agent 的系统 prompt 或 Skills 配置中: ``` ## CWE 技能 You have access to the `cwe` CLI tool for CWE (Common Weakness Enumeration) operations. ### 安装 ```bash # 下载预构建的二进制文件 (Linux/macOS/Windows) curl -sL https://github.com/scagogogo/cwe-skills/releases/latest/download/cwe-skills_latest_linux_x86_64.tar.gz | tar xz && sudo mv cwe /usr/local/bin/ # 或者从源码构建: git clone https://github.com/scagogogo/cwe-skills.git && cd cwe-skills && go build -o cwe ./cmd/cwe/ && sudo mv cwe /usr/local/bin/ ``` ### 核心命令 | 命令 | 功能描述 | |---------|-------------| | `cwe parse CWE-79` | 解析 CWE ID | | `cwe validate CWE-79` | 验证 CWE ID 格式 | | `cwe show CWE-79` | 从 MITRE API 获取弱点详情 | | `cwe wellknown check CWE-79` | 检查是否在 Top 25 / OWASP / SANS 列表中 | | `cwe enum abstraction` | 列出有效的枚举值 | | `cwe search --xml --keyword Injection` | 搜索离线 XML 目录 | | `cwe filter --xml --abstraction Base --status Stable` | 多条件过滤 | | `cwe registry get CWE-79 --xml ` | 从本地注册表获取条目 | | `cwe nav ancestors CWE-79 --xml ` | 离线导航关系 | | `cwe nav shortest-path CWE-79 CWE-1 --xml ` | 查找两个 CWE 之间的最短路径 | | `cwe tree build CWE-1 --xml ` | 构建层级树 | | `cwe stats --xml ` | 从 XML 目录生成统计信息 | ### 输出 所有命令均支持 `-o json` 以输出结构化 JSON 数据。示例:`cwe parse CWE-79 -o json` ### Go SDK ``` import cwepkg "github.com/scagogogo/cwe-skills" id, _ := cwepkg.ParseCWEID("CWE-79") cwepkg.IsInTop25(79) // true client := cwepkg.NewAPIClient() weakness, _ := client.GetWeakness(ctx, 79) ``` ### Skills 文档 渐进式功能文档:https://github.com/scagogogo/cwe-skills/tree/main/docs/skills ``` --- ## 2. Go SDK ```go import ( "context" cwepkg "github.com/scagogogo/cwe-skills" ) // Parse & validate CWE IDs id, _ := cwepkg.ParseCWEID("CWE-79") if cwepkg.IsCWEID("CWE-89") { /* valid */ } // Query MITRE REST API client := cwepkg.NewAPIClient() defer client.Close() weakness, _ := client.GetWeakness(context.Background(), 79) parents, _ := client.GetParents(context.Background(), 79) // Local registry from XML registry, _ := cwepkg.NewXMLParser().ParseFile("cwec_v4.15.xml") registry.BuildIndexes() // Navigate relationships nav := cwepkg.NewNavigator(registry) ancestors := nav.Ancestors(79) path := nav.ShortestPath(79, 1) // Build hierarchy tree tree := cwepkg.BuildTree(registry, 1) leaves := tree.LeafNodes() // Search & filter results := cwepkg.FindByKeyword(registry, "Injection") filtered := cwepkg.Filter(results, cwepkg.FilterOption{ Abstraction: cwepkg.AbstractionBase, Status: cwepkg.StatusStable, }) // Well-known lists cwepkg.IsInTop25(79) // true cwepkg.IsInOWASPTop10(79) // true cwepkg.IsInSANSTop25(79) // true // Serialization jsonData, _ := registry.ExportJSON() csvData, _ := registry.ExportCSV() ``` **安装**:`go get github.com/scagogogo/cwe-skills` ## 3. CLI ### 安装 **从 Release 安装**(推荐): ``` # Linux (amd64) curl -sL https://github.com/scagogogo/cwe-skills/releases/latest/download/cwe-skills_latest_linux_x86_64.tar.gz | tar xz sudo mv cwe /usr/local/bin/ # macOS (Apple Silicon) curl -sL https://github.com/scagogogo/cwe-skills/releases/latest/download/cwe-skills_latest_darwin_aarch64.tar.gz | tar xz sudo mv cwe /usr/local/bin/ # Windows (PowerShell) Invoke-WebRequest -Uri https://github.com/scagogogo/cwe-skills/releases/latest/download/cwe-skills_latest_windows_x86_64.zip -OutFile cwe.zip Expand-Archive cwe.zip ``` **从源码安装**: ``` git clone https://github.com/scagogogo/cwe-skills.git cd cwe-skills && go build -o cwe ./cmd/cwe/ ``` **从包管理器安装**: ``` brew install scagogogo/tap/cwe-skills # Homebrew scoop install cwe-skills # Scoop (Windows) go install github.com/scagogogo/cwe-skills/cmd/cwe@latest # Go ``` ### 快速示例 ``` # CWE ID 操作 cwe parse CWE-79 89 cwe-352 cwe validate CWE-79 CWE-89 cwe format 79 89 352 cwe extract "Affected by CWE-79 and CWE-89" cwe compare CWE-79 CWE-89 # 已知列表 cwe wellknown top25 cwe wellknown owasp cwe wellknown check CWE-79 # MITRE API (在线) cwe show CWE-79 cwe relations parents CWE-79 cwe api-version # 本地搜索与过滤 (离线) cwe search --xml cwec_latest.xml --keyword Injection --sort name cwe filter --xml cwec_latest.xml --abstraction Base --status Stable --likelihood High # 本地注册表 (离线) cwe registry load --xml cwec_latest.xml cwe registry get CWE-79 --xml cwec_latest.xml cwe registry ancestors CWE-79 --xml cwec_latest.xml cwe registry export --xml cwec_latest.xml --format json # 本地导航 (离线) cwe nav siblings CWE-79 --xml cwec_latest.xml cwe nav peers CWE-79 --xml cwec_latest.xml cwe nav shortest-path CWE-79 CWE-1 --xml cwec_latest.xml cwe nav is-ancestor CWE-1 CWE-79 --xml cwec_latest.xml cwe nav depth CWE-79 CWE-1 --xml cwec_latest.xml # Tree 操作 (离线) cwe tree build CWE-1 --xml cwec_latest.xml cwe tree forest --xml cwec_latest.xml cwe tree path CWE-79 --xml cwec_latest.xml cwe tree leaves CWE-1 --xml cwec_latest.xml # 枚举类型 cwe enum abstraction cwe enum status cwe enum relationship # 每个命令的 JSON 输出 cwe parse CWE-79 -o json cwe wellknown check CWE-79 -o json ``` ### 命令参考 | 命令 | 描述 | |---------|-------------| | `cwe version` | 显示版本信息 | | `cwe parse/validate/format/extract/compare` | CWE ID 实用工具 | | `cwe enum ` | 列出枚举值 | | `cwe wellknown top25/owasp/sans/check` | 知名列表 | | `cwe show [IDs...]` | 从 MITRE API 获取 | | `cwe relations parents/children/ancestors/descendants` | API 关系查询 | | `cwe api-version` | 检查 MITRE API 版本 | | `cwe search --xml [flags]` | 搜索离线 XML | | `cwe filter --xml [flags]` | 多条件过滤 | | `cwe stats --xml ` | 统计信息 | | `cwe registry --xml ` | 注册表操作 | | `cwe nav --xml ` | 关系导航 | | `cwe tree --xml ` | 树操作 | ## 4. MCP *(MCP server 即将推出 — 请在 [Issues](https://github.com/scagogogo/cwe-skills/issues) 中追踪进度)* ## Skills 文档 面向 AI agents 和开发者的渐进式 Skills 文档 — 从基础到进阶: | # | Skill | 描述 | |---|-------|-------------| | 1 | [CWE ID 解析与验证](docs/skills/01-cwe-id-parsing-validation.md) | 解析、验证、格式化 CWE ID | | 2 | [CWE ID 提取与比较](docs/skills/02-cwe-id-extraction-comparison.md) | 从文本中提取、比较 ID | | 3 | [知名列表](docs/skills/03-well-known-lists.md) | CWE Top 25, OWASP Top 10, SANS Top 25 | | 4 | [枚举类型](docs/skills/04-enumeration-types.md) | Abstraction, Status, Relationship 类型 | | 5 | [API:获取弱点详情](docs/skills/05-api-show-weakness.md) | 从 MITRE API 获取 | | 6 | [API:关系查询](docs/skills/06-api-relationships.md) | 通过 API 查询 Parent/child/ancestor/descendant | | 7 | [API:版本检查](docs/skills/07-api-version.md) | 检查 MITRE API 版本 | | 8 | [本地:搜索与过滤](docs/skills/08-local-search-filter.md) | 搜索与多条件过滤 | | 9 | [本地:注册表操作](docs/skills/09-local-registry.md) | 加载、查询、导出本地数据 | | 10 | [本地:关系导航](docs/skills/10-local-navigation.md) | 离线导航关系 | | 11 | [本地:树构建](docs/skills/11-local-tree.md) | 构建与遍历层级树 | | 12 | [SDK:序列化](docs/skills/12-sdk-serialization.md) | JSON, XML, CSV 导入/导出 | → **[完整 Skills 索引](docs/skills/README.md)** ## 支持的平台 提供 30 多种平台的预编译二进制文件:Linux (amd64/386/arm64/arm/mips/ppc64/s390x/riscv64)、macOS (Intel/Apple Silicon)、Windows (amd64/386/arm64)、FreeBSD、NetBSD、OpenBSD、AIX、Illumos、Solaris。 ## 功能 - **完整的 CWE 数据模型**:Weaknesses, Categories, Views, Compound Elements - **类型化枚举**:Abstraction, Status, Relationship, Consequence, View 类型 - **CWE ID 实用工具**:解析、格式化、验证、提取、比较 - **知名列表**:CWE Top 25, OWASP Top 10, SANS Top 25 - **MITRE REST API 客户端**:速率限制、重试、结构化错误 - **XML 目录解析器**:离线解析 MITRE XML - **内存注册表**:利用关系索引进行存储、查询 - **搜索与过滤**:关键字、abstraction、status、likelihood、scope、排序、分组 - **关系导航**:Parents, children, ancestors, descendants, siblings, peers, chains, composites、最短路径、关系深度 - **树构建**:构建、遍历、查找路径、列出叶子节点 - **序列化**:JSON, XML, CSV 导入/导出 - **40 多个 CLI 子命令**:支持文本/JSON 双格式输出 - **零依赖**:核心 SDK 仅使用 Go 标准库 ## 许可证 MIT License - 详情请参阅 [LICENSE](LICENSE)。
标签:AI智能体, EVTX分析, Go语言, GPT, MCP, 文档结构分析, 日志审计, 漏洞管理, 程序破解, 网络安全, 隐私保护