castellan 是一个离线、MCP 原生的威胁建模引擎,能从 YAML 规范或 IaC 文件自动生成 STRIDE/LINDDUN 威胁模型、DREAD 风险评分与合规映射,并支持 CI 门禁和 AI agent 集成。

# 🏰 castellan
### 你的威胁模型守护者。
*离线、原生支持 MCP 的威胁建模 —— 包含 STRIDE + LINDDUN 模型、DREAD 风险评分、攻击树以及 600+ 合规框架映射,可从规范说明 **或直接从你的 Infrastructure-as-Code** 生成。*
[](https://pypi.org/project/cognis-castellan/) [](https://github.com/cognis-digital/castellan/actions) [](LICENSE) [](https://github.com/cognis-digital)
*Cognis Neural Suite 的一部分。*
```
pip install cognis-castellan
castellan analyze system.yml # full STRIDE+LINDDUN model in milliseconds
castellan scan ./infra --fail-on high # model your Terraform/K8s and gate CI
```
## 为什么选择 castellan?
大多数威胁建模工具都是重量级的、纯云端的 SaaS,它们将你的架构和发现结果锁定在账户背后。**castellan 则完全相反:** 它是一个单一、快速、无依赖的引擎,完全在你的机器或 CI 中运行,使用你的 pipeline 已经在用的格式,并通过 MCP 由 AI agent 驱动。
它内置了大量**真实**的安全知识库 —— 且下方的核心数据是*由工具计算得出*的,而非凭空断言。运行 `castellan library stats` 即可自行打印这些数据。
| 指标 | castellan 内置 | 验证方式 |
|---|---:|---|
| 🎯 威胁场景 | **5,000+** | `castellan library threats` |
| 📋 安全要求 | **12,000+** | `castellan library requirements` |
| 🏛️ 映射的合规框架 | **625** | `castellan library frameworks` |
| 🧩 基础攻击模式 | **98** | 均关联 CWE/CAPEC/ATT&CK/OWASP |
| 🗂️ 资产类别 | **87** | 真实的组件分类法 |
| 🔬 方法论 | **6** | STRIDE · LINDDUN · DREAD · CIA · PASTA 风格风险 · 攻击树 |
## 它的功能
- **STRIDE** 威胁建模:仅需一份微型的 YAML 系统规范(包含元素 + 数据流 + 信任边界)。
- **LINDDUN** 隐私威胁:针对任何涉及个人数据的元素或数据流进行分析。
- **DREAD 风险评分** —— 每个威胁都会获得可复现的 0–10 风险分值、风险等级以及 CIA 影响,这些均根据结构性事实(暴露程度、信任边界交叉、声明的控制措施)推导得出。
- 针对每个处理流程和数据存储生成**攻击树**。
- 每个威胁均提供**真实参考**:CWE、CAPEC、MITRE ATT&CK 技术、OWASP Top 10 / API Top 10。
- **合规控制矩阵** —— 每个威胁均映射到涵盖 NIST 800-53、ISO/IEC 27001:2022、PCI DSS v4、OWASP ASVS、CIS Controls v8、SOC 2、GDPR、ISO 27701 等框架的具体控制措施。
- **Infrastructure-as-Code 输入,威胁模型输出** —— 指向 Terraform、CloudFormation、Kubernetes manifests 或 docker-compose,它会自动推导出模型。
- **原生支持 MCP** —— `castellan mcp` 将整个引擎作为工具暴露给 Claude Desktop、Cursor、Cognis.Studio 以及 agent 集群使用。
## 快速开始
```
pip install cognis-castellan
castellan analyze system.yml # human table
castellan analyze system.yml --format json # machine-readable
castellan analyze system.yml --format sarif # code-scanning
castellan analyze system.yml --format html -o tm.html # shareable report
castellan analyze system.yml --fail-on high # CI gate (non-zero exit)
castellan scan ./infra # auto-detect spec OR IaC
castellan import ./infra > system.yml # convert IaC to a spec you can edit
castellan compliance system.yml # the control matrix
castellan library stats # the numbers above, computed
```
### 规范格式
```
name: Acme Web Application
elements:
- name: user
type: external_entity
- name: web-api
type: process
controls: [mfa, rate-limit] # declared controls mark threats mitigated
- name: user-db
type: datastore
data_classification: pii # turns on LINDDUN privacy threats
flows:
- name: login
from: user
to: web-api
encrypted: true
crosses_boundary: true
```
```
$ castellan analyze webapp.yml
System: Acme Web Application
Threats: 21 Unmitigated: 14 Risk score: 9.0/10 Frameworks: 7
Methodologies: STRIDE:21
ID RISK SEVERITY METH CATEGORY M TARGET
T017-I 9.3 critical STRIDE Information Disclosure - db-query
T020-E 8.0 critical STRIDE Elevation of Privilege - web-api
...
```
## 从你的 Infrastructure-as-Code 生成
无需绘制图表 —— 直接对你实际部署的内容进行建模:
```
castellan scan main.tf # Terraform (HCL or plan JSON)
castellan scan template.yaml # CloudFormation
castellan scan k8s/ # Kubernetes manifests
castellan scan docker-compose.yml # docker-compose
castellan scan ./infra --fail-on high # a whole repo, merged into one model
```
castellan 会将每个资源分类到其资产分类体系中,标记加密和公共暴露缺口,综合分析信任边界,并在生成的结果上运行完整的引擎。
## 在任何 AI 技术栈中使用
`castellan` 可与所有主流的 AI 使用方式实现互操作:
- **MCP server** —— `castellan mcp` 将 `analyze`、`scan`、`validate`、`import_iac`、`compliance`、`report_markdown` 和 `library_stats` 作为工具暴露出来(适用于 Claude Desktop、Cursor、Cognis.Studio、[uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet))。
- **JSON / SARIF** —— 通过管道将 `--format json` 或 `--format sarif` 传递给任何 agent、LLM 或代码扫描 UI。
- **LangChain · CrewAI · AutoGen · LlamaIndex** —— 只需一行代码即可将 CLI/JSON 封装为工具。
- **CI / 脚本** —— 为非 AI pipeline 提供 exit code + SARIF 支持。
## 对比分析
| | **castellan** | 典型的商业平台 |
|---|:---:|:---:|
| 完全离线 / 自托管运行 | ✅ | ❌ (云端 SaaS) |
| 无需账户,无按席位授权 | ✅ | ❌ |
| STRIDE + LINDDUN 隐私分析 | ✅ | 部分 |
| DREAD 风险 + 攻击树 | ✅ | 视情况而定 |
| 直接对你的 IaC 进行威胁建模 | ✅ Terraform/CFN/K8s/compose | 视情况而定 |
| 原生支持 AI agent 的 MCP | ✅ | 罕见 |
| 支持 CI 的 JSON + SARIF | ✅ | 视情况而定 |
| 映射的合规框架 | ✅ **625** | 视情况而定 |
| 开放、可审计的知识库 | ✅ | ❌ (闭源专有) |
| 价格 | **免费 / COCL** | 企业级 |
## 架构
```
flowchart LR
A[spec.yml] --> P
B[Terraform / CFN / K8s / compose] --> I[IaC importers] --> P
P[castellan engine
STRIDE · LINDDUN · DREAD · attack trees] --> K[(knowledge base
CWE · CAPEC · ATT&CK · 625 frameworks)]
P --> O[table · JSON · SARIF · Markdown · HTML · Mermaid]
```
## 安装 —— 各种方式,全平台支持
```
pip install cognis-castellan # PyPI
pipx install cognis-castellan # isolated CLI
uv tool install cognis-castellan # uv
pip install "git+https://github.com/cognis-digital/castellan.git" # from source
docker run --rm ghcr.io/cognis-digital/castellan:latest --help # Docker
curl -fsSL https://raw.githubusercontent.com/cognis-digital/castellan/main/install.sh | sh
```
可选附加项:`pip install "cognis-castellan[mcp]"`(MCP server),`[connect]`(通过 cognis-connect 转发发现结果),`[dev]`(测试)。
## 相关的 Cognis 工具
**探索完整套件 →** [🗂️ 所有工具](https://github.com/cognis-digital) · [🔗 cognis-connect](https://github.com/cognis-digital/cognis-connect) · [🤖 uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet) · [🧠 engram](https://github.com/cognis-digital/engram)
## 许可证
在 **Cognis Open Collaboration License (COCL) v1.0** 下提供源码可见授权 —— 可免费用于个人、内部评估、研究和教育用途;**商业 / 生产环境使用需获取许可证** (licensing@cognis.digital)。详情请参阅 [LICENSE](LICENSE)。
Cognis Digital · Cognis Neural Suite 的一部分 · Making Tomorrow Better Today