zz-code-recon by sendaifun/skills
npx skills add https://github.com/sendaifun/skills --skill zz-code-recon通过超细粒度的代码分析构建全面的架构理解。专为安全审计员、代码审查员和需要在深入之前快速理解陌生代码库的开发者设计。
CodeRecon 是一种系统化的代码库侦察方法,它从高级架构到实现细节构建分层理解。灵感来源于 Trail of Bits 的审计上下文构建方法论。
在你发现漏洞之前,你需要理解:
本技能提供了一种高效构建该上下文的结构化方法。
┌─────────────┐
│ 细节层 │ ← 具体实现细节
─┼─────────────┼─
/ │ 函数层 │ ← 关键函数分析
/ ─┼─────────────┼─
/ │ 模块层 │ ← 组件关系
/ ─┼─────────────┼─
/ │ 架构层 │ ← 系统结构
/ ─┼─────────────┼─
/ │ 概览层 │ ← 高层次理解
─────────┴─────────────┴─────────
从宏观开始,系统性地深入。
收集基本项目信息:
# 检查文档
ls -la README* ARCHITECTURE* SECURITY* CHANGELOG* docs/
# 识别构建系统
ls package.json Cargo.toml go.mod pyproject.toml Makefile
# 检查测试
ls -la test* spec* *_test* __tests__/
# 识别 CI/CD
ls -la .github/workflows/ .gitlab-ci.yml Jenkinsfile .circleci/
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 语言分布
find . -type f -name "*.py" | wc -l
find . -type f -name "*.js" -o -name "*.ts" | wc -l
find . -type f -name "*.go" | wc -l
find . -type f -name "*.rs" | wc -l
find . -type f -name "*.sol" | wc -l
# 框架指示器
grep -r "from flask" --include="*.py" | head -1
grep -r "from django" --include="*.py" | head -1
grep -r "express\|fastify" --include="*.js" | head -1
grep -r "anchor_lang" --include="*.rs" | head -1
# Python 依赖
cat requirements.txt pyproject.toml setup.py 2>/dev/null | grep -E "^\s*[a-zA-Z]"
# Node.js 依赖
cat package.json | jq '.dependencies, .devDependencies'
# Rust 依赖
cat Cargo.toml | grep -A 100 "\[dependencies\]"
# Go 依赖
cat go.mod | grep -E "^\s+[a-z]"
## 技术图谱: [项目名称]
### 语言
| 语言 | 文件数 | 代码行数 | 主要用途 |
|----------|-------|-------|-------------|
| Python | 150 | 25K | 后端 API |
| TypeScript | 80 | 12K | 前端 |
| Solidity | 12 | 2K | 智能合约 |
### 关键依赖
| 包名 | 版本 | 用途 | 安全备注 |
|---------|---------|---------|----------------|
| fastapi | 0.100.0 | Web 框架 | 近期 CVE: 无 |
| web3.py | 6.0.0 | 区块链客户端 | 检查签名 |
| pyjwt | 2.8.0 | JWT 处理 | 验证算法检查 |
### 基础设施
- 数据库: PostgreSQL 15
- 缓存: Redis 7
- 消息队列: RabbitMQ
- 容器: Docker + K8s
# 顶层结构
tree -L 2 -d
# 识别入口点
find . -name "main.py" -o -name "app.py" -o -name "index.ts" -o -name "main.go"
# 识别配置
find . -name "config*" -o -name "settings*" -o -name ".env*"
寻找常见模式:
project/
├── api/ # HTTP 端点
├── auth/ # 认证
├── core/ # 业务逻辑
├── db/ # 数据库层
├── models/ # 数据模型
├── services/ # 外部服务
├── utils/ # 工具函数
├── workers/ # 后台任务
└── tests/ # 测试套件
┌─────────────────────────────────────────────────────────────┐
│ 客户端 │
│ (Web, 移动端, API 消费者) │
└─────────────────────────┬───────────────────────────────────┘
│ HTTPS
▼
┌─────────────────────────────────────────────────────────────┐
│ API 网关 │
│ (速率限制, 认证) │
└─────────────────────────┬───────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ 认证 │ │ 核心 │ │ 管理 │
│ 服务 │ │ API │ │ API │
└────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │
└──────────────┼──────────────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ 数据库 │ │ 缓存 │ │ 外部 │
│ (Postgres)│ │ (Redis) │ │ API │
└──────────┘ └──────────┘ └──────────┘
映射信任级别发生变化的位置:
## 信任边界
### 边界 1: 互联网 → API 网关
- **类型:** 网络边界
- **控制措施:** TLS, 速率限制, WAF
- **风险:** DDoS, 注入, 认证绕过
### 边界 2: API 网关 → 服务
- **类型:** 认证边界
- **控制措施:** JWT 验证, 角色检查
- **风险:** 令牌伪造, 权限提升
### 边界 3: 服务 → 数据库
- **类型:** 数据访问边界
- **控制措施:** 查询参数化, 连接池
- **风险:** SQL 注入, 数据泄露
### 边界 4: 服务 → 外部 API
- **类型:** 第三方集成
- **控制措施:** API 密钥, 请求签名
- **风险:** SSRF, 密钥暴露
针对每种入口点类型:
# HTTP 路由 - 映射所有端点
grep -rn "@app.route\|@router\|@api_view" --include="*.py"
grep -rn "app.(get|post|put|delete)\|router.(get|post)" --include="*.ts"
# CLI 命令
grep -rn "@click.command\|argparse\|clap" --include="*.py" --include="*.rs"
# 事件处理器
grep -rn "@consumer\|@handler\|on_message" --include="*.py"
## 入口点
### HTTP API
| 方法 | 路径 | 处理器 | 认证 | 输入 |
|--------|------|---------|------|-------|
| POST | /api/login | auth.login | 无 | JSON 请求体 |
| GET | /api/users | users.list | JWT | 查询参数 |
| POST | /api/transfer | tx.transfer | JWT + 2FA | JSON 请求体 |
| GET | /admin/logs | admin.logs | 管理员 JWT | 查询参数 |
### WebSocket
| 事件 | 处理器 | 认证 | 数据 |
|-------|---------|------|------|
| connect | ws.connect | JWT | 无 |
| message | ws.message | 会话 | JSON |
### 后台任务
| 队列 | 处理器 | 触发器 | 数据源 |
|-------|---------|---------|-------------|
| emails | email.send | API 调用 | 数据库 |
| reports | report.gen | Cron | 数据库 |
针对每个关键端点,追踪数据流:
POST /api/transfer
│
▼
┌──────────────────┐
│ 请求解析器 │ ← 验证 JSON 模式
│ (validation.py) │
└────────┬─────────┘
│ TransferRequest
▼
┌──────────────────┐
│ 认证中间件 │ ← 验证 JWT, 提取用户
│ (middleware.py) │
└────────┬─────────┘
│ 用户上下文
▼
┌──────────────────┐
│ 转账服务 │ ← 业务逻辑
│ (transfer.py) │
└────────┬─────────┘
│
┌────┴────┐
▼ ▼
┌────────┐ ┌────────┐
│ 数据库 │ │外部 API│
│ 写入 │ │ │
└────────┘ └────────┘
搜索安全敏感操作:
# 认证
grep -rn "def login\|def authenticate\|def verify_token" --include="*.py"
grep -rn "function login\|authenticate\|verifyToken" --include="*.ts"
# 授权
grep -rn "def is_authorized\|def check_permission\|@requires_role" --include="*.py"
# 密码学
grep -rn "encrypt\|decrypt\|hash\|sign\|verify" --include="*.py"
grep -rn "crypto\.\|bcrypt\|argon2" --include="*.py"
# 数据库
grep -rn "execute\|query\|cursor" --include="*.py"
grep -rn "\.query\|\.execute\|\.raw" --include="*.ts"
# 文件操作
grep -rn "open\(.*\)\|read\|write\|unlink" --include="*.py"
针对每个关键函数:
### 函数: `transfer_funds()`
**位置:** `services/transfer.py:45`
**目的:** 执行账户间资金转账
**参数:**
| 名称 | 类型 | 来源 | 验证 |
|------|------|--------|------------|
| from_account | str | JWT 声明 | UUID 格式 |
| to_account | str | 请求体 | UUID 格式, 存在性检查 |
| amount | Decimal | 请求体 | > 0, <= 余额 |
**返回:** TransferResult
**副作用:**
- 写入 `transactions` 表
- 调用外部支付 API
- 发出 `transfer_completed` 事件
**安全考虑:**
- 需要已认证用户
- 速率限制为 10次/分钟
- 金额根据余额验证
- 审计日志记录
**潜在风险:**
- 如果并发转账是否存在竞态条件?
- 如果外部 API 在转账中途失败会怎样?
transfer_funds()
├── validate_request()
│ └── check_uuid_format()
├── get_user_balance()
│ └── db.query()
├── check_rate_limit()
│ └── redis.get()
├── execute_transfer() ← 关键
│ ├── db.begin_transaction()
│ ├── update_balance() ← 状态变更
│ ├── external_api.send() ← 外部调用
│ └── db.commit()
└── emit_event()
# 查找所有配置加载
grep -rn "os.environ\|getenv\|config\." --include="*.py"
grep -rn "process.env\|config\." --include="*.ts"
# 检查硬编码的密钥
grep -rn "password\s*=\|secret\s*=\|api_key\s*=" --include="*.py"
grep -rn "-----BEGIN\|sk-\|pk_live_" .
# 查找异常处理
grep -rn "except.*:" --include="*.py" -A 2
grep -rn "catch\s*(" --include="*.ts" -A 2
# 查找错误响应
grep -rn "return.*error\|raise.*Error" --include="*.py"
# 查找日志语句
grep -rn "logger\.\|logging\.\|console\.log" --include="*.py" --include="*.ts"
# 检查记录的内容
grep -rn "log.*password\|log.*token\|log.*secret" --include="*.py"
# [项目名称] - 安全上下文文档
## 执行摘要
[2-3 句描述该系统功能]
## 技术栈
[来自第一阶段]
## 架构
[来自第二阶段的图表]
## 信任边界
[来自第 2.4 节]
## 入口点
[来自第 3.2 节的表格]
## 关键函数
[来自第四阶段的分析]
## 数据流
[来自第 3.3 节的图表]
## 安全控制
| 控制措施 | 实现 | 位置 | 备注 |
|---------|----------------|----------|-------|
| 认证 | JWT | middleware/auth.py | RS256 签名 |
| 授权 | RBAC | decorators/auth.py | 基于角色 |
| 输入验证 | Pydantic | schemas/*.py | 类型检查 |
| 加密 | AES-256-GCM | utils/crypto.py | 静态加密 |
## 需要重点关注的领域
1. [高风险领域 1]
2. [高风险领域 2]
3. [高风险领域 3]
## 待解决问题
- [ ] 当 Y 发生时,X 是如何处理的?
- [ ] 如果 Z 失败会发生什么?
# 完整侦察脚本
./scripts/recon.sh /path/to/project
# 生成入口点映射
./scripts/map-endpoints.sh /path/to/project
# 创建调用图
./scripts/callgraph.sh /path/to/project
code-recon/
├── SKILL.md # 本文件
├── resources/
│ ├── recon-checklist.md # 全面检查清单
│ └── question-bank.md # 待回答问题
├── examples/
│ ├── web-app-recon/ # Web 应用示例
│ └── smart-contract-recon/ # 智能合约示例
├── templates/
│ └── context-document.md # 输出模板
└── docs/
└── advanced-techniques.md # 深度技术
每周安装数
73
代码仓库
GitHub 星标数
68
首次出现
2026年1月24日
安全审计
安装于
opencode67
gemini-cli65
codex64
github-copilot62
amp60
kimi-cli60
Build comprehensive architectural understanding through ultra-granular code analysis. Designed for security auditors, code reviewers, and developers who need to rapidly understand unfamiliar codebases before diving deep.
CodeRecon is a systematic approach to codebase reconnaissance that builds layered understanding from high-level architecture down to implementation details. Inspired by Trail of Bits' audit-context-building methodology.
Before you can find vulnerabilities, you need to understand:
This skill provides a structured methodology for building that context efficiently.
┌─────────────┐
│ DETAILS │ ← Implementation specifics
─┼─────────────┼─
/ │ FUNCTIONS │ ← Key function analysis
/ ─┼─────────────┼─
/ │ MODULES │ ← Component relationships
/ ─┼─────────────┼─
/ │ ARCHITECTURE│ ← System structure
/ ─┼─────────────┼─
/ │ OVERVIEW │ ← High-level understanding
─────────┴─────────────┴─────────
Start broad, go deep systematically.
Gather basic project information:
# Check for documentation
ls -la README* ARCHITECTURE* SECURITY* CHANGELOG* docs/
# Identify build system
ls package.json Cargo.toml go.mod pyproject.toml Makefile
# Check for tests
ls -la test* spec* *_test* __tests__/
# Identify CI/CD
ls -la .github/workflows/ .gitlab-ci.yml Jenkinsfile .circleci/
# Language distribution
find . -type f -name "*.py" | wc -l
find . -type f -name "*.js" -o -name "*.ts" | wc -l
find . -type f -name "*.go" | wc -l
find . -type f -name "*.rs" | wc -l
find . -type f -name "*.sol" | wc -l
# Framework indicators
grep -r "from flask" --include="*.py" | head -1
grep -r "from django" --include="*.py" | head -1
grep -r "express\|fastify" --include="*.js" | head -1
grep -r "anchor_lang" --include="*.rs" | head -1
# Python dependencies
cat requirements.txt pyproject.toml setup.py 2>/dev/null | grep -E "^\s*[a-zA-Z]"
# Node.js dependencies
cat package.json | jq '.dependencies, .devDependencies'
# Rust dependencies
cat Cargo.toml | grep -A 100 "\[dependencies\]"
# Go dependencies
cat go.mod | grep -E "^\s+[a-z]"
## Technology Map: [PROJECT NAME]
### Languages
| Language | Files | Lines | Primary Use |
|----------|-------|-------|-------------|
| Python | 150 | 25K | Backend API |
| TypeScript | 80 | 12K | Frontend |
| Solidity | 12 | 2K | Smart Contracts |
### Key Dependencies
| Package | Version | Purpose | Security Notes |
|---------|---------|---------|----------------|
| fastapi | 0.100.0 | Web framework | Recent CVEs: None |
| web3.py | 6.0.0 | Blockchain client | Check signing |
| pyjwt | 2.8.0 | JWT handling | Verify alg checks |
### Infrastructure
- Database: PostgreSQL 15
- Cache: Redis 7
- Message Queue: RabbitMQ
- Container: Docker + K8s
# Top-level structure
tree -L 2 -d
# Identify entry points
find . -name "main.py" -o -name "app.py" -o -name "index.ts" -o -name "main.go"
# Identify config
find . -name "config*" -o -name "settings*" -o -name ".env*"
Look for common patterns:
project/
├── api/ # HTTP endpoints
├── auth/ # Authentication
├── core/ # Business logic
├── db/ # Database layer
├── models/ # Data models
├── services/ # External services
├── utils/ # Utilities
├── workers/ # Background jobs
└── tests/ # Test suite
┌─────────────────────────────────────────────────────────────┐
│ CLIENTS │
│ (Web, Mobile, API Consumers) │
└─────────────────────────┬───────────────────────────────────┘
│ HTTPS
▼
┌─────────────────────────────────────────────────────────────┐
│ API GATEWAY │
│ (Rate Limiting, Auth) │
└─────────────────────────┬───────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Auth │ │ Core │ │ Admin │
│ Service │ │ API │ │ API │
└────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │
└──────────────┼──────────────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Database │ │ Cache │ │ External │
│ (Postgres)│ │ (Redis) │ │ APIs │
└──────────┘ └──────────┘ └──────────┘
Map where trust levels change:
## Trust Boundaries
### Boundary 1: Internet → API Gateway
- **Type:** Network boundary
- **Controls:** TLS, Rate limiting, WAF
- **Risks:** DDoS, Injection, Auth bypass
### Boundary 2: API Gateway → Services
- **Type:** Authentication boundary
- **Controls:** JWT validation, Role checks
- **Risks:** Token forgery, Privilege escalation
### Boundary 3: Services → Database
- **Type:** Data access boundary
- **Controls:** Query parameterization, Connection pooling
- **Risks:** SQL injection, Data leakage
### Boundary 4: Services → External APIs
- **Type:** Third-party integration
- **Controls:** API keys, Request signing
- **Risks:** SSRF, Secret exposure
For each entry point type:
# HTTP Routes - map all endpoints
grep -rn "@app.route\|@router\|@api_view" --include="*.py"
grep -rn "app.(get|post|put|delete)\|router.(get|post)" --include="*.ts"
# CLI Commands
grep -rn "@click.command\|argparse\|clap" --include="*.py" --include="*.rs"
# Event Handlers
grep -rn "@consumer\|@handler\|on_message" --include="*.py"
## Entry Points
### HTTP API
| Method | Path | Handler | Auth | Input |
|--------|------|---------|------|-------|
| POST | /api/login | auth.login | None | JSON body |
| GET | /api/users | users.list | JWT | Query params |
| POST | /api/transfer | tx.transfer | JWT + 2FA | JSON body |
| GET | /admin/logs | admin.logs | Admin JWT | Query params |
### WebSocket
| Event | Handler | Auth | Data |
|-------|---------|------|------|
| connect | ws.connect | JWT | None |
| message | ws.message | Session | JSON |
### Background Jobs
| Queue | Handler | Trigger | Data Source |
|-------|---------|---------|-------------|
| emails | email.send | API call | Database |
| reports | report.gen | Cron | Database |
For each critical endpoint, trace data flow:
POST /api/transfer
│
▼
┌──────────────────┐
│ Request Parser │ ← Validate JSON schema
│ (validation.py) │
└────────┬─────────┘
│ TransferRequest
▼
┌──────────────────┐
│ Auth Middleware │ ← Verify JWT, extract user
│ (middleware.py) │
└────────┬─────────┘
│ User context
▼
┌──────────────────┐
│ Transfer Service │ ← Business logic
│ (transfer.py) │
└────────┬─────────┘
│
┌────┴────┐
▼ ▼
┌────────┐ ┌────────┐
│ DB │ │External│
│ Write │ │ API │
└────────┘ └────────┘
Search for security-sensitive operations:
# Authentication
grep -rn "def login\|def authenticate\|def verify_token" --include="*.py"
grep -rn "function login\|authenticate\|verifyToken" --include="*.ts"
# Authorization
grep -rn "def is_authorized\|def check_permission\|@requires_role" --include="*.py"
# Cryptography
grep -rn "encrypt\|decrypt\|hash\|sign\|verify" --include="*.py"
grep -rn "crypto\.\|bcrypt\|argon2" --include="*.py"
# Database
grep -rn "execute\|query\|cursor" --include="*.py"
grep -rn "\.query\|\.execute\|\.raw" --include="*.ts"
# File Operations
grep -rn "open\(.*\)\|read\|write\|unlink" --include="*.py"
For each critical function:
### Function: `transfer_funds()`
**Location:** `services/transfer.py:45`
**Purpose:** Execute fund transfer between accounts
**Parameters:**
| Name | Type | Source | Validation |
|------|------|--------|------------|
| from_account | str | JWT claim | UUID format |
| to_account | str | Request body | UUID format, exists check |
| amount | Decimal | Request body | > 0, <= balance |
**Returns:** TransferResult
**Side Effects:**
- Writes to `transactions` table
- Calls external payment API
- Emits `transfer_completed` event
**Security Considerations:**
- Requires authenticated user
- Rate limited to 10/minute
- Amount validated against balance
- Audit logged
**Potential Risks:**
- Race condition if concurrent transfers?
- What if external API fails mid-transfer?
transfer_funds()
├── validate_request()
│ └── check_uuid_format()
├── get_user_balance()
│ └── db.query()
├── check_rate_limit()
│ └── redis.get()
├── execute_transfer() ← CRITICAL
│ ├── db.begin_transaction()
│ ├── update_balance() ← State change
│ ├── external_api.send() ← External call
│ └── db.commit()
└── emit_event()
# Find all config loading
grep -rn "os.environ\|getenv\|config\." --include="*.py"
grep -rn "process.env\|config\." --include="*.ts"
# Check for hardcoded secrets
grep -rn "password\s*=\|secret\s*=\|api_key\s*=" --include="*.py"
grep -rn "-----BEGIN\|sk-\|pk_live_" .
# Find exception handling
grep -rn "except.*:" --include="*.py" -A 2
grep -rn "catch\s*(" --include="*.ts" -A 2
# Find error responses
grep -rn "return.*error\|raise.*Error" --include="*.py"
# Find logging statements
grep -rn "logger\.\|logging\.\|console\.log" --include="*.py" --include="*.ts"
# Check what's being logged
grep -rn "log.*password\|log.*token\|log.*secret" --include="*.py"
# [PROJECT NAME] - Security Context Document
## Executive Summary
[2-3 sentences on what this system does]
## Technology Stack
[From Phase 1]
## Architecture
[Diagram from Phase 2]
## Trust Boundaries
[From Phase 2.4]
## Entry Points
[Table from Phase 3.2]
## Critical Functions
[Analysis from Phase 4]
## Data Flows
[Diagrams from Phase 3.3]
## Security Controls
| Control | Implementation | Location | Notes |
|---------|----------------|----------|-------|
| Authentication | JWT | middleware/auth.py | RS256 signing |
| Authorization | RBAC | decorators/auth.py | Role-based |
| Input Validation | Pydantic | schemas/*.py | Type checking |
| Encryption | AES-256-GCM | utils/crypto.py | At-rest |
## Areas Requiring Focus
1. [High-risk area 1]
2. [High-risk area 2]
3. [High-risk area 3]
## Open Questions
- [ ] How is X handled when Y?
- [ ] What happens if Z fails?
# Full recon script
./scripts/recon.sh /path/to/project
# Generate entry point map
./scripts/map-endpoints.sh /path/to/project
# Create call graph
./scripts/callgraph.sh /path/to/project
code-recon/
├── SKILL.md # This file
├── resources/
│ ├── recon-checklist.md # Comprehensive checklist
│ └── question-bank.md # Questions to answer
├── examples/
│ ├── web-app-recon/ # Web application example
│ └── smart-contract-recon/ # Smart contract example
├── templates/
│ └── context-document.md # Output template
└── docs/
└── advanced-techniques.md # Deep dive techniques
Weekly Installs
73
Repository
GitHub Stars
68
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode67
gemini-cli65
codex64
github-copilot62
amp60
kimi-cli60
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
42,100 周安装
LLM错误分析指南:如何系统化诊断和分类AI流水线故障
194 周安装
Nansen 持币者分析工具:评估代币持有者质量,识别聪明钱与散户信号
195 周安装
Symfony端到端测试工具:Panther与Playwright集成,实现自动化E2E测试与TDD开发
198 周安装
Microsoft Agent Framework:开源AI智能体与工作流平台,支持Python/C#跨平台开发
195 周安装
Flask Python Web开发专家指南:最佳实践、性能优化与API设计
202 周安装
LLM评估审计工具:诊断AI评估流程问题,生成优先级修复清单
197 周安装