漏洞扫描器
- 作者仓库星标 0
- 作者更新于 2026年8月24日 23:09
- 作者仓库 skills
- 领域
- 通用
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @trailofbits · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 命令执行
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
第一阶段:发现(同步)
Entry:用户提供的目标代码库路径。代码库包含 Go 源代码(例如,`x/` 模块、`go.mod`)或带有 `cosmwasm_std` 的 Rust 合约。运行同步子代理(代理工具),并以 DISCOVERY.md 的完整内容作为提示。代理必须: 按照发现工作流程探索目标代码库 在其响应中返回完整的 CLAUDE.md 内容(技术清单和威胁模型)
第 2 阶段:并行漏洞扫描
在单个消息中生成扫描代理以实现最大并行度。使用下面的代理提示模板,填写每个代理的参考文件。子代理只需要读取访问权限(Grep、Glob、Read)——它们在响应中返回结果,主要技能写入文件。始终生成这 3 个代理:代理名称·参考文件·范围`core-scanner`·`VULNERABILITY_PATTERNS.md`·§1-9:非确定性、ABCI、签名者、验证、处理程序、安全性
第三阶段:写下调查结果
所有扫描代理返回后,将发现文件写入输出目录(默认`.bughunt_cosmos/`): 解析每个代理对`FINDING_FILE:`块的响应 对于每个发现,使用`FINDING_FILE:`中的文件名将内容写入`{OUTPUT_DIR}/{filename}`(如果不存在),首先创建输出目录
第 4 阶段:验证完整性
写入所有结果后,验证对每个模式进行了评估:收集每个代理返回的摘要行(§NUM 条目) 根据预期总数检查模式计数: `core-scanner`:8 种模式(§1-9,仅排除 §8 旧模式) `state-scanner`:13 种模式(§11-23)
# Cosmos Vulnerability Scanner
## Purpose
Scan Cosmos SDK modules and CosmWasm contracts for vulnerabilities that cause chain halts, consensus failures, or fund loss. Spawns parallel scanning agents — each specializing in a vulnerability category — that return findings to the main skill, which then writes them as individual markdown files to an output directory.
**Output directory**: defaults to `.bughunt_cosmos/`. If the user specifies a different directory in their prompt, use that instead.
## When to Use
- Auditing Cosmos SDK modules (custom `x/` modules)
- Reviewing CosmWasm smart contracts
- Pre-launch security assessment of Cosmos chains
- Investigating chain halt incidents
## When NOT to Use
- Pure Solidity/EVM audits without Cosmos SDK — use Solidity-specific tools
- CometBFT consensus engine internals — this covers SDK modules, not the consensus layer itself
- General Go code review with no blockchain context
- Cosmos SDK application logic that is not consensus-critical (e.g., CLI commands, REST endpoints)
- CosmWasm contract-only audits on chains without custom SDK modules — use the CosmWasm checklist items alone
## Essential Principles
1. **Consensus path is king** — A bug only matters for chain halt/fund loss if it's on the consensus-critical execution path (BeginBlock, EndBlock, FinalizeBlock, msg_server handlers, AnteHandler). Always verify a finding is reachable from consensus before reporting it.
2. **State divergence = chain halt** — Any non-determinism that causes validators to compute different state roots will halt the chain. This is the highest-severity class because it affects all validators simultaneously.
3. **Check the version** — Cosmos SDK has breaking changes across major versions (v0.47 removed GetSigners, v0.50 added ABCI 2.0, v0.53 deprecated ValidateBasic). Always check `go.mod` versions before applying patterns.
4. **False positives waste audit time** — A map iteration in a CLI command is not a consensus bug. A panic in a query handler does not halt the chain. Verify the execution context before flagging.
5. **Cross-module interactions are where bugs hide** — The most severe findings (IBC reentrancy, EVM/Cosmos state desync, authz escalation) involve interactions between modules, not bugs within a single module.
## Scanning Workflow
### Phase 1: Discovery (synchronous)
**Entry**: Target codebase path provided by user. Codebase contains Go source (e.g., `x/` modules, `go.mod`) or Rust contracts with `cosmwasm_std`.
Run a **synchronous subagent** (Agent tool) with the full contents of [DISCOVERY.md](resources/DISCOVERY.md) as its prompt. The agent must:
1. Follow the Discovery workflow to explore the target codebase
2. Return the full CLAUDE.md content (the technical inventory and threat model) in its response
3. Return a structured summary with exactly these fields:
```
PLATFORM: pure-cosmos | evm | wasm (pick one; if multiple, comma-separated)
IBC_ENABLED: true | false
SDK_VERSION: <version from go.mod>
IBC_GO_VERSION: <version from go.mod, or "n/a">
CUSTOM_MODULES: <comma-separated list of x/* modules>
```
After the subagent returns, **you** (the main skill) Write the CLAUDE.md to the target repo root. Save its path and the discovery values — these feed into Phase 2.
**Exit**: CLAUDE.md written by main skill. PLATFORM, IBC_ENABLED, SDK_VERSION, IBC_GO_VERSION, and CUSTOM_MODULES captured.
### Phase 2: Parallel Vulnerability Scan
Spawn scanning agents **in a single message** for maximum parallelism. Use the Agent Prompt Template below, filling in the reference file for each agent. Subagents only need read access (Grep, Glob, Read) — they return findings in their response and the main skill writes the files.
**Always spawn these 3 agents:**
| Agent Name | Reference File | Scope |
|------------|---------------|-------|
| `core-scanner` | `VULNERABILITY_PATTERNS.md` | §1-9: non-determinism, ABCI, signers, validation, handlers, ante security |
| `state-scanner` | `STATE_VULNERABILITY_PATTERNS.md` | §11-23: bookkeeping, bank, pagination, events, tx replay, governance, arithmetic, encoding, deprecated modules |
| `advanced-scanner` | `ADVANCED_VULNERABILITY_PATTERNS.md` | §24-27: storage keys, consensus validation, circuit breaker, crypto |
**Spawn conditionally (in the same parallel message):**
| Agent Name | Condition | Reference File |
|------------|-----------|---------------|
| `evm-scanner` | PLATFORM includes `evm` | `EVM_VULNERABILITY_PATTERNS.md` |
| `ibc-scanner` | IBC_ENABLED is `true` | `IBC_VULNERABILITY_PATTERNS.md` |
| `cosmwasm-scanner` | PLATFORM includes `wasm` | `COSMWASM_VULNERABILITY_PATTERNS.md` |
#### Agent Prompt Template
Construct each agent's prompt by replacing `{REFERENCE_FILE_PATH}` with the full path to the reference file (under `{baseDir}/resources/`) and `{CLAUDE_MD_PATH}` with the path to the CLAUDE.md written in Phase 1:
~~~
Perform a very thorough security scan of a Cosmos SDK codebase for specific vulnerability patterns.
CONTEXT:
Read {CLAUDE_MD_PATH} for codebase context (SDK version, modules, threat model, key files).
PATTERNS:
Read {REFERENCE_FILE_PATH} — it contains numbered vulnerability patterns. For EACH pattern:
1. Read the detection patterns and "What to Check" items
2. Use Grep and Glob to search the target codebase for each pattern
3. When a match is found, Read surrounding code to verify it's on a consensus-critical path (BeginBlock, EndBlock, FinalizeBlock, msg_server handlers, AnteHandler)
4. Classify severity per the guidelines below
RULES:
- Consensus path only: Only flag code reachable from consensus-critical execution. CLI/query/test code is NOT a finding.
- Check SDK version in go.mod before applying patterns (v0.47 removed GetSigners, v0.50 added ABCI 2.0, v0.53 deprecated ValidateBasic).
- Always use the Grep tool for searches, not bash grep. The reference file contains search patterns — use them directly with the Grep tool.
- Ignore cross-references to other resource files (e.g., links to IBC or COSMWASM patterns). Those patterns are covered by other scanning agents.
- Reject these rationalizations:
- "ValidateBasic catches this" — deprecated and facultative since SDK v0.53
- "Behind governance, so safe" — governance proposals can be malicious
- "IBC counterparty is trusted" — any chain can open a channel
- "Panic can't happen, input is validated" — trace the full call chain
- "Rounding error is only a few tokens" — compounds over time, can be looped
- "EVM precompile handles rollback" — many have incomplete rollback
SEVERITY:
- Critical (fund loss): signer mismatch, broken bookkeeping, AnteHandler bypass, bank keeper misuse, IBC token inflation, EVM/Cosmos desync, Merkle proof forgery, arithmetic overflow
- High (chain halt): non-determinism, ABCI panics, slow ABCI, non-deterministic IBC acks, consensus gaps, CacheContext event leak
- Medium (DoS): unbounded pagination, tx replay, missing validation, governance spam, rate limiting, circuit breaker bypass, storage key collisions
- Low (logic): rounding errors, stub handlers, event override, module ordering
OUTPUT — RETURN FORMAT:
Do NOT write any files. Return ALL findings and the summary in your response.
For each pattern, return one of:
§NUM PATTERN_NAME: Not applicable — [one-line reason]
§NUM PATTERN_NAME: FINDING (followed by the finding block below)
For each finding, include the full content using this template:
FINDING_FILE: {SEVERITY}-s{SECTION_NUM}-{kebab-description}.md
## [SEVERITY] Title
**Location**: `file:line`
**Description**: What the bug is and why it matters
**Vulnerable Code**: [snippet]
**Attack Scenario**: [numbered steps]
**Recommendation**: How to fix
**References**: [links to relevant advisories or building-secure-contracts]
You MUST report on ALL patterns in the reference file — do not skip any.
~~~
**Exit**: All scanning agents returned. Each reported on every pattern in their reference file.
### Phase 3: Write Findings
After all scanning agents return, write finding files to the output directory (default `.bughunt_cosmos/`):
1. Parse each agent's response for `FINDING_FILE:` blocks
2. For each finding, Write the content to `{OUTPUT_DIR}/{filename}` using the filename from `FINDING_FILE:`
3. Create the output directory first if it doesn't exist
### Phase 4: Verify Completeness
After writing all findings, verify every pattern was assessed:
1. Collect the summary lines (§NUM entries) returned by each agent
2. Check pattern counts against expected totals:
- `core-scanner`: 8 patterns (§1-9, excluding §8 legacy-only)
- `state-scanner`: 13 patterns (§11-23)
- `advanced-scanner`: 4 patterns (§24-27)
- `evm-scanner` (if spawned): 10 patterns (§1-10)
- `ibc-scanner` (if spawned): 16 patterns (§1-16)
- `cosmwasm-scanner` (if spawned): 3 patterns (§1-3)
3. If any pattern is missing from a summary, flag it and re-prompt that agent
4. List all finding files written to the output directory with a `Glob` for `*.md`
**Exit**: All patterns accounted for. Finding files listed for the user.
---
## Success Criteria
- [ ] Discovery CLAUDE.md written with complete technical inventory and threat model
- [ ] All scanning agents completed and reported on every pattern in their reference file
- [ ] Pattern counts verified against expected totals (no patterns skipped)
- [ ] All findings written to output directory as individual markdown files
- [ ] Each finding file includes: severity, location, vulnerable code, attack scenario, recommendation
---
## Resources
- **Discovery & CLAUDE.md**: [DISCOVERY.md](resources/DISCOVERY.md)
- **Core patterns (§1-9)**: [VULNERABILITY_PATTERNS.md](resources/VULNERABILITY_PATTERNS.md)
- **State & module patterns (§11-23)**: [STATE_VULNERABILITY_PATTERNS.md](resources/STATE_VULNERABILITY_PATTERNS.md)
- **Advanced patterns (§24-27)**: [ADVANCED_VULNERABILITY_PATTERNS.md](resources/ADVANCED_VULNERABILITY_PATTERNS.md)
- **IBC vulnerabilities**: [IBC_VULNERABILITY_PATTERNS.md](resources/IBC_VULNERABILITY_PATTERNS.md)
- **CosmWasm vulnerabilities**: [COSMWASM_VULNERABILITY_PATTERNS.md](resources/COSMWASM_VULNERABILITY_PATTERNS.md)
- **EVM vulnerabilities**: [EVM_VULNERABILITY_PATTERNS.md](resources/EVM_VULNERABILITY_PATTERNS.md)
- **Building Secure Contracts**: `building-secure-contracts/not-so-smart-contracts/cosmos/`
- **Cosmos SDK Docs**: https://docs.cosmos.network/
- **CodeQL for Cosmos SDK**: https://github.com/crypto-com/cosmos-sdk-codeql
章节与文件索引
按说明文件中的顺序排列。
目的
何时使用
何时不使用
基本原则
第一阶段:发现(同步)
文件/命令 -> .bughunt_cosmos/ · go.mod · cosmwasm_std · core-scanner · VULNERABILITY_PATTERNS.md · state-scanner · STATE_VULNERABILITY_PATTERNS.md · advanced-scanner
内容校验值 -> 1eafee433445
当前原文的自动摘译,尚未人工审校。
目的
扫描 Cosmos SDK 模块和 CosmWasm 合约,查找导致链停止、共识失败或资金损失的漏洞。生成并行扫描代理(每个代理专门针对一个漏洞类别),将发现结果返回给主要技能,然后将它们作为单独的降价文件写入输出目录。输出目录:默认为
.bughunt_cosmos/。如果用户在提示中指定不同的目录,请改用该目录。何时使用
审核 Cosmos SDK 模块(自定义
x/模块) 审查 CosmWasm 智能合约 Cosmos 链的启动前安全评估 调查链暂停事件何时不使用
无需 Cosmos SDK 的纯 Solidity/EVM 审计 — 使用 Solidity 特定工具 CometBFT 共识引擎内部结构 — 这涵盖了 SDK 模块,而不是共识层本身 没有区块链上下文的常规 Go 代码审查 Cosmos SDK 应用程序逻辑不是共识关键的(例如 CLI 命令、REST 端点) 没有自定义 SDK 模块的链上的 CosmWasm 仅合约审计 — 单独使用 CosmWasm 检查表项目
基本原则
共识路径为王——如果错误位于共识关键执行路径(BeginBlock、EndBlock、FinalizeBlock、msg_server handlers、AnteHandler)上,则仅对链停止/资金损失产生影响。在报告之前,请务必验证调查结果是否可以达成共识。状态分歧 = 链停止——任何导致验证器计算不同状态根的不确定性都会使链停止。这是最高严重性的类别,因为它同时影响所有验证器。