mcpField
V
vulnhunter

vulnhunter

github.com/sendaifun安全130271 次安装13 周前更新
代码仓库

关于 vulnhunter

VulnHunter 是面向开发者和审计人员的安全审查技能,结合危险 API 与默认配置检查,以及基于模式的代码库漏洞变体搜索。

主要功能

  1. 01检测危险 API 与默认配置
  2. 02检查特定语言的易错模式
  3. 03搜索漏洞变体
  4. 04采用 grep 和 AST 搜索方法
  5. 05整理发现并编写修复报告

适用场景

  1. 01检查代码中的安全隐患
  2. 02搜索已知漏洞的变体
  3. 03审计前评估陌生代码库
  4. 04整理安全报告中的发现

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sendaifun/skills --skill vulnhunter

安装后在 Claude Code 中输入/vulnhunter确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

docs/
methodology.md
examples/smart-contracts/
reentrancy-hunt.md
examples/web-apps/
sql-injection-hunt.md
resources/
sharp-edges-catalog.md
variant-patterns.md
templates/
variant-report.md

详细介绍

VulnHunter - 安全漏洞检测与分析

一套全面的安全审计技能,用于识别危险 API、易踩坑的模式、容易出错的配置,并在代码库中搜寻漏洞变体。灵感来自 Trail of Bits 的尖锐边缘和变体分析方法。

概述

VulnHunter 结合了两种强大的安全分析技术:

  1. 尖锐边缘检测 - 识别容易出错的 API、危险的默认设置和易踩坑的设计
  2. 变体分析 - 使用基于模式的分析,在代码库中查找类似漏洞
何时使用 VulnHunter

在以下情况下启用此技能:

  • 进行安全代码审查或审计
  • 审查第三方依赖项中的危险模式
  • 搜寻已知漏洞的变体
  • 评估 API 设计中容易引发安全问题的缺陷
  • 对不熟悉的代码库进行审计前侦察

尖锐边缘检测

尖锐边缘的类别
1. 危险的默认配置

查找默认情况下不安全的配置:

- CORS: Access-Control-Allow-Origin: *
- Debug modes enabled in production
- Default credentials or API keys
- Permissive file permissions (777, 666)
- SSL/TLS verification disabled
- Insecure deserialization settings
2. 容易出错的 API

内存安全:

// Dangerous: No bounds checking
strcpy(), strcat(), sprintf(), gets()
memcpy() without size validation

// Safer alternatives
strncpy(), strncat(), snprintf(), fgets()
memcpy_s() with explicit size

密码学陷阱:

- ECB mode encryption
- MD5/SHA1 for security purposes
- Hardcoded IVs or salts
- Custom crypto implementations
- Random without CSPRNG (Math.random for tokens)

并发问题:

- Race conditions in file operations
- Time-of-check to time-of-use (TOCTOU)
- Double-checked locking anti-patterns
- Non-atomic increment/decrement operations
3. 特定语言的易踩坑之处

JavaScript/TypeScript:

// Dangerous patterns
eval(), new Function(), setTimeout(string)
innerHTML, outerHTML, document.write()
Object.assign() for deep clone (shallow only!)
== instead of === (type coercion)

Python:

# Dangerous patterns
pickle.loads(untrusted)  # RCE vector
yaml.load(untrusted)     # Use safe_load
exec(), eval()
os.system(), subprocess with shell=True

Rust:

// Patterns requiring extra scrutiny
unsafe { }
.unwrap() in production code
mem::transmute()
raw pointer dereference

Solidity/智能合约:

// High-risk patterns
tx.origin for authentication  // Phishing vulnerable
delegatecall to untrusted     // Storage collision
selfdestruct                  // Permanent destruction
block.timestamp for randomness // Miner manipulable
尖锐边缘检查清单

审查代码时,系统地检查以下内容:

  • 身份验证绕过 - 缺少身份验证检查、默认凭据
  • 授权缺陷 - 权限提升、IDOR 模式
  • 注入向量 - SQL、命令、模板、XSS
  • 密码学弱点 - 弱算法、密钥处理不当
  • 资源耗尽 - 无界循环、内存分配
  • 竞态条件 - TOCTOU、并发状态修改
  • 信息泄露 - 过于详细的错误信息、调试端点
  • 反序列化 - 对不可信数据进行解组
  • 路径遍历 - 用户控制的文件路径
  • SSRF 向量 - 用户控制的 URL、重定向

变体分析

漏洞变体搜寻流程
  1. 识别根本原因 - 理解漏洞存在的原因
  2. 提取模式 - 哪种代码结构使其成为可能?
  3. 泛化模式 - 创建正则表达式/AST 模式
  4. 搜索代码库 - 搜寻类似结构
  5. 验证发现 - 确认每个变体都可被利用
模式提取模板
模板 1:缺少验证模式
Original bug: User input flows to SQL query without sanitization
Pattern: [user_input] -> [sink_function] without [validation_function]

Search for:
- Direct database calls with string concatenation
- ORM raw query methods with user parameters
- Similar data flows in adjacent modules
模板 2:身份验证绕过
Original bug: Endpoint missing auth middleware
Pattern: Route definition without auth decorator/middleware

Search for:
- Routes defined after the vulnerable one
- Similar API patterns in other modules
- Admin/internal endpoints
模板 3:竞态条件
Original bug: Check-then-act without atomicity
Pattern: if (check_condition()) { act_on_condition() }

Search for:
- File existence checks followed by file operations
- Permission checks followed by privileged actions
- Balance checks followed by transfers
搜索策略
基于 Grep 的搜索
# Find potential SQL injection
grep -rn "execute.*%s" --include="*.py"
grep -rn "query.*\+" --include="*.js"

# Find dangerous deserialize
grep -rn "pickle.loads\|yaml.load\|eval(" --include="*.py"

# Find command injection vectors
grep -rn "os.system\|subprocess.*shell=True" --include="*.py"
语义搜索(基于 AST)

如需更精确的匹配,请使用基于 AST 的工具:

  • Semgrep - 跨语言语义 grep
  • CodeQL - GitHub 的语义分析工具
  • tree-sitter - 通用解析器
变体分析报告模板
## Variant Analysis Report

### Original Finding
- **ID**: FINDING-001
- **Severity**: High
- **Root Cause**: [Description]
- **Affected File**: path/to/file.ext:line

### Pattern Extracted
[Code pattern or regex]

### Variants Discovered

| # | Location | Severity | Status | Notes |
|---|----------|----------|--------|-------|
| 1 | file.ext:42 | High | Confirmed | Same root cause |
| 2 | other.ext:100 | Medium | Suspected | Needs validation |

### Recommendations
[Systematic fix approach]

工作流

阶段 1:侦察
  1. 识别技术栈和编程语言
  2. 梳理入口点(API、CLI、文件输入)
  3. 定位身份验证/授权逻辑
  4. 查找密码学操作
  5. 识别外部集成
阶段 2:尖锐边缘扫描
  1. 逐项检查尖锐边缘清单
  2. 聚焦安全关键路径
  3. 记录所有可疑模式
  4. 与已知 CVE 交叉比对
阶段 3:漏洞变体搜寻
  1. 针对每项发现提取模式
  2. 系统地搜索变体
  3. 验证每个潜在变体
  4. 评估总体风险
阶段 4:报告
  1. 按类别汇总发现
  2. 评定严重程度
  3. 提供修复建议
  4. 指出系统性问题

与静态分析集成

常见模式的 Semgrep 规则
# Example: Detect SQL injection in Python
rules:
  - id: sql-injection-format
    patterns:
      - pattern: $CURSOR.execute($QUERY % ...)
    message: "Potential SQL injection via string formatting"
    severity: ERROR
    languages: [python]
CodeQL 查询
// Find tainted data flowing to dangerous sinks
import python
import semmle.python.dataflow.TaintTracking

from DataFlow::PathNode source, DataFlow::PathNode sink
where TaintTracking::localTaint(source.getNode(), sink.getNode())
  and sink.getNode().asExpr().(Call).getTarget().getName() = "execute"
select sink, source, sink, "Tainted input reaches SQL execution"

示例

有关以下内容,请参见 /examples 文件夹:

  • 按语言分类的真实尖锐边缘示例
  • 变体分析案例研究
  • 模式提取演练

资源

  • resources/sharp-edges-catalog.md - 危险模式的综合目录
  • resources/variant-patterns.md - 常见漏洞模式模板
  • templates/variant-report.md - 变体分析报告模板

指南

  1. 务必验证 - 不要将理论问题报告为已确认的漏洞
  2. 结合上下文判断 - 某种模式在一个上下文中可能是安全的,在另一个上下文中则可能是危险的
  3. 优先考虑可利用性 - 关注会造成实际影响的模式
  4. 记录假设 - 说明威胁模型的任何假设
  5. 优先解决系统性问题,而非单点修复 - 如果模式反复出现,建议进行架构改进

技能文件

vulnhunter/
├── SKILL.md                          # This file
├── resources/
│   ├── sharp-edges-catalog.md        # Categorized dangerous patterns
│   └── variant-patterns.md           # Vulnerability pattern templates
├── examples/
│   ├── smart-contracts/              # Solidity/blockchain examples
│   ├── web-apps/                     # Web application examples
│   └── native-code/                  # C/C++/Rust examples
├── templates/
│   └── variant-report.md             # Analysis report template
└── docs/
    └── methodology.md                # Detailed methodology guide

评论

支持 Markdown