siddhantbhattarai/anvil

GitHub: siddhantbhattarai/anvil

ANVIL 是一款基于 Rust 的高性能 Web 应用安全扫描器,通过证据驱动的方式检测 11 类主动漏洞和 5 项被动审计,支持 CI 流水线集成与 AI agent 调用。

Stars: 3 | Forks: 3

# ANVIL 🔨 **企业级对抗性安全测试框架** [![许可证](https://img.shields.io/badge/License-PolyForm%20Noncommercial%201.0.0-blue.svg)](LICENSE) [![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org/) [![版本](https://img.shields.io/badge/version-0.6.0-green.svg)](https://github.com/siddhantbhattarai/anvil) ANVIL 是一款使用 Rust 编写的高性能、证据驱动的 Web 应用安全扫描器。它能检测并安全地**证明** **11 类主动漏洞**以及**5 项被动审计** —— 涵盖了 **OWASP Top 10 中的 8 项** —— 具有极低的误报率,并输出适用于分类和 CI 拦截的机器可读报告(文本、JSON、CSV)。 它专为自动化和 AI agent 而构建:支持一键 `--owasp` 扫描、确定性的 `--fail-on` 退出代码,以及内置的 **MCP server** (`--mcp`),以便像 Claude Code 这样的 agent 可以将其作为原生工具进行调用。 ## 🎯 OWASP Top 10 覆盖范围 | OWASP 2021 | ANVIL 检测项 | |------------|--------------| | **A01** 失效的访问控制 | 路径遍历、开放重定向、CORS | | **A02** 加密机制失效 | 密钥 / 敏感数据暴露 | | **A03** 注入 | SQLi、NoSQLi、XSS、命令注入、SSTI、CRLF | | **A05** 安全配置错误 | CORS、安全标头及 cookie 审计 | | **A06** 易受攻击和过时的组件 | 过时的 JS 库检测 | | **A07** 身份识别和认证失败 | JWT 漏洞 | | **A08** 软件和数据完整性失败 | 子资源完整性 (SRI) | | **A10** 服务器端请求伪造 | SSRF | *A04(不安全的设计)和 A09(安全日志记录失败)无法通过黑盒扫描检测。* ## 🚀 功能 ### 主动检测类别 | 标志 | 类别 | CWE | |------|-------|-----| | `--sqli` | SQL 注入 | CWE-89 | | `--nosqli` | NoSQL (MongoDB 操作符) 注入 | CWE-943 | | `--xss` | 跨站脚本攻击 | CWE-79 | | `--ssrf` | 服务器端请求伪造 | CWE-918 | | `--cmdi` | 操作系统命令注入 | CWE-78 | | `--path-traversal` | 路径遍历 / LFI | CWE-22 | | `--ssti` | 服务器端模板注入 | CWE-1336 | | `--xxe` | XML 外部实体注入 | CWE-611 | | `--open-redirect` | 开放重定向 | CWE-601 | | `--cors` | CORS 配置错误 | CWE-942 | | `--crlf` | CRLF / HTTP 标头注入 | CWE-113 | ### 被动分析器 | 标志 | 审计 | OWASP | |------|-------|-------| | `--security-headers` | 缺失/脆弱的安全标头及 cookie 标志 | A05 | | `--jwt` | JWT 漏洞 (alg:none、弱密钥、无过期时间) | A07 | | `--secrets` | 暴露的密钥 / 敏感数据 | A02 | | `--components` | 带有已知 CVE 的过时前端库 | A06 | | `--sri` | 跨域资源缺失子资源完整性 | A08 | ### 自动化与 agent - **`--all` / `--owasp`** — 通过一条命令运行所有可靠的检测类别 + 被动审计。 - **`--fail-on `** — 用于 CI 拦截的确定性退出代码(`0` 表示干净,`2` 表示发现的问题 ≥ 阈值,`1` 表示错误)。 - **`--mcp`** — 作为 Model Context Protocol server (stdio JSON-RPC) 运行,为 AI agent 暴露 `anvil_scan` 工具。 - **输出格式** — 文本、JSON、CSV;为下游工具提供稳定的 JSON schema。 ### SQL 注入 (SQLi) — 深度能力 - **检测技术** - 基于 UNION 的注入 - 基于布尔的盲注 - 基于时间的盲注 - 基于错误的注入 - DNS 数据外带 (Out-of-Band) - 二阶注入 - 堆叠查询 - **数据库枚举** - 数据库列出 (`--dbs`) - 表枚举 (`--tables`) - 列枚举 (`--columns`) - 数据转储 (`--dump`, `--dump-all`) - Schema 提取 (`--schema`) - 行计数 (`--count`) - **数据库信息** - 标语/版本 (`--banner`) - 当前用户 (`--current-user`) - 当前数据库 (`--current-db`) - 主机名 (`--hostname`) - DBA 检查 (`--is-dba`) - **用户枚举** - 列出用户 (`--users`) - 密码哈希 (`--passwords`) - 权限 (`--privileges`) - 角色 (`--roles`) - **高级功能** - 18 个用于绕过 WAF 的篡改脚本 - 交互式 SQL shell - 从服务器读取/写入文件 - 操作系统命令执行 - 基于字典的哈希破解 - **支持的数据库** - MySQL / MariaDB - PostgreSQL - Microsoft SQL Server - Oracle - SQLite - Microsoft Access ### 跨站脚本攻击 (XSS) - 反射型 XSS 检测 - 存储型/持久型 XSS 检测 - 基于 DOM 的 XSS 检测 - 带有回调的盲打 XSS - 上下文感知 payload (HTML、属性、JS、URL) - Polyglot payload ### 服务器端请求伪造 (SSRF) - 内网扫描 (RFC1918) - 云元数据 endpoint 测试 (AWS、GCP、Azure) - 协议方案测试 (file、gopher、dict) - 带有回调的盲 SSRF ### 额外功能 - **爬取**:自动参数发现 - **指纹识别**:服务器、操作系统和框架检测 - **身份验证**:支持 Cookie 和标头 - **速率限制**:可配置的请求限流 - **输出格式**:文本、JSON、CSV ## 📦 安装 ### Linux / macOS ``` # Clone 仓库 git clone https://github.com/siddhantbhattarai/anvil.git cd anvil # 运行 setup 脚本 chmod +x setup.sh ./setup.sh # 或手动安装 cargo install --path . ``` ### Windows #### 选项 1:使用 PowerShell 脚本 ``` # 以管理员身份运行 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser # Clone 并安装 git clone https://github.com/siddhantbhattarai/anvil.git cd anvil .\setup.ps1 ``` #### 选项 2:手动安装 1. 安装 [Rust](https://rustup.rs/) - 下载并运行 `rustup-init.exe` 2. 打开命令提示符或 PowerShell: ``` git clone https://github.com/siddhantbhattarai/anvil.git cd anvil cargo install --path . ``` 3. 如果尚未添加,请将 Cargo 的 bin 目录添加到 PATH 中: - 打开系统属性 → 环境变量 - 将 `%USERPROFILE%\.cargo\bin` 添加到 PATH 中 ## 🔧 用法 ### 完整的 OWASP 扫描(推荐) ``` # 一条命令运行所有检测类 + passive audit anvil -t "http://target.com" --owasp --crawl -o report.json --format json # CI / agent gating:如果发现 High 或更严重的问题,则 exit code 为 2 anvil -t "http://target.com" --owasp --fail-on high --format json ``` ### 针对性的单一类别检测 ``` anvil -t "http://host/page?id=1" -p id --sqli anvil -t "http://host/find?q=cat" -p q --nosqli anvil -t "http://host/search?q=t" -p q --xss --xss-all anvil -t "http://host/fetch?url=x" -p url --ssrf anvil -t "http://host/ping?host=x" -p host --cmdi anvil -t "http://host/view?file=a" -p file --path-traversal anvil -t "http://host/tpl?name=x" -p name --ssti anvil -t "http://host/api/xml" --xxe anvil -t "http://host/go?next=/" -p next --open-redirect anvil -t "http://host/api/me" --cors anvil -t "http://host/set?lang=en" -p lang --crlf ``` ### 被动审计 ``` anvil -t "https://host/" --security-headers anvil -t "https://host/api" --cookie 'session=eyJ...' --jwt anvil -t "https://host/config.js" --secrets anvil -t "https://host/" --components anvil -t "https://host/" --sri ``` ### MCP server(面向 AI agent) ``` # 通过 stdio 将 ANVIL 作为 MCP server 启动 anvil --mcp ``` 在支持 MCP 的 agent(例如 Claude Code)中注册它: ``` { "mcpServers": { "anvil": { "command": "anvil", "args": ["--mcp"] } } } ``` 该 server 暴露了一个 `anvil_scan` 工具,接收 `target`、`profile`(`owasp` 或单个类别)、可选的 `param` 以及可选的 `fail_on` 参数。 ### 基础 SQL 注入扫描 ``` # 检测 SQLi vulnerability anvil -t "http://target.com/page.php?id=1" -p id --sqli # Enumerate 数据库 anvil -t "http://target.com/page.php?id=1" -p id --sqli --dbs # Enumerate 数据库中的表 anvil -t "http://target.com/page.php?id=1" -p id --sqli -D database_name --tables # Enumerate 表中的列 anvil -t "http://target.com/page.php?id=1" -p id --sqli -D database_name -T table_name --columns # Dump 表数据 anvil -t "http://target.com/page.php?id=1" -p id --sqli -D database_name -T table_name --dump # Dump 特定列 anvil -t "http://target.com/page.php?id=1" -p id --sqli -D database_name -T table_name -C "user,pass" --dump ``` ### XSS 扫描 ``` # 基础 XSS 扫描 anvil -t "http://target.com/search?q=test" -p q --xss # 所有 XSS 类型 anvil -t "http://target.com/search?q=test" -p q --xss-all # 带 callback 的 Blind XSS anvil -t "http://target.com/contact" --xss-blind --callback "attacker.com" ``` ### SSRF 扫描 ``` # 基础 SSRF 扫描 anvil -t "http://target.com/fetch?url=http://example.com" -p url --ssrf # Cloud metadata 测试 anvil -t "http://target.com/fetch?url=test" -p url --ssrf-metadata # 所有 SSRF 测试 anvil -t "http://target.com/fetch?url=test" -p url --ssrf-all ``` ### 高级选项 ``` # 带认证 anvil -t "http://target.com/admin?id=1" -p id --sqli --cookie "session=abc123" # Custom headers anvil -t "http://target.com/api?id=1" -p id --sqli -H "Authorization: Bearer token" # POST request anvil -t "http://target.com/login" --data "user=admin&pass=test" -p user --sqli # 调整 risk/level anvil -t "http://target.com/page?id=1" -p id --sqli --level 3 --risk 2 # 输出到文件 anvil -t "http://target.com/page?id=1" -p id --sqli --dbs -o results.json --format json ``` ## 📁 项目结构 ``` anvil/ ├── src/ │ ├── main.rs # Entry point │ ├── cli/ # Command-line interface │ ├── core/ # Core engine and context │ ├── http/ # HTTP client and requests │ ├── sqli/ # SQL Injection module │ │ ├── core/ # Settings, enums, queries │ │ ├── request/ # HTTP and comparison │ │ ├── techniques/ # Detection techniques │ │ │ ├── union/ # UNION-based │ │ │ ├── blind/ # Boolean/Time-based │ │ │ ├── error/ # Error-based │ │ │ └── dns/ # DNS exfiltration │ │ ├── tamper/ # WAF bypass scripts │ │ ├── shell.rs # SQL shell │ │ ├── file_access.rs # File read/write │ │ └── os_shell.rs # OS commands │ ├── xss/ # XSS detection module │ ├── ssrf/ # SSRF detection module │ ├── cmdi/ # OS command injection (CWE-78) │ ├── nosqli/ # NoSQL injection (CWE-943) │ ├── pathtrav/ # Path traversal / LFI (CWE-22) │ ├── ssti/ # Server-side template injection (CWE-1336) │ ├── xxe/ # XML external entity (CWE-611) │ ├── openredirect/ # Open redirect (CWE-601) │ ├── cors/ # CORS misconfiguration (CWE-942) │ ├── crlf/ # CRLF / header injection (CWE-113) │ ├── secheaders/ # Passive security-header audit (A05) │ ├── jwt/ # JWT weakness analysis (CWE-347) │ ├── secrets/ # Secret / sensitive-data exposure (A02) │ ├── components/ # Outdated component detection (A06) │ ├── sri/ # Subresource Integrity audit (A08) │ ├── mcp/ # MCP server (stdio JSON-RPC) for AI agents │ ├── scanner/ # Crawling and fingerprinting │ ├── validation/ # Input validation │ └── reporting/ # Output and reports ├── docs/ │ └── anvil.1 # man page ├── Cargo.toml # Dependencies ├── setup.sh # Linux/macOS installer ├── setup.ps1 # Windows installer ├── LICENSE # PolyForm Noncommercial 1.0.0 └── README.md # This file ``` ## 🔒 法律免责声明 本工具仅供**授权的安全测试**使用。在测试任何你不拥有的系统之前,请务必获得适当的授权。未经授权访问计算机系统是违法行为。 对于因使用本工具而造成的任何误用或损害,作者不承担任何责任。 ## 📄 许可证 ANVIL 采用 **[PolyForm Noncommercial License 1.0.0](LICENSE)** 授权 —— 这是一个源代码可见的许可证。 - ✅ **可免费用于非商业用途** —— 个人项目、研究、教育及非商业组织。 - ❌ **未经单独的商业许可,不得被他人用于商业用途、转售或托管**。 - 🔒 **仅限授权测试** —— 该许可证包含可接受的使用条件(仅限测试你拥有或获得书面许可测试的系统)。 所有商业权利均由作者保留。如需商业许可,请联系作者(见下文)。 ## 👤 作者 **Siddhant Bhattarai** - GitHub: [@siddhantbhattarai](https://github.com/siddhantbhattarai) ## ⭐ 致谢 - 灵感来源于 [sqlmap](https://sqlmap.org/) 及其他安全工具 - 使用 [Rust](https://www.rust-lang.org/) 构建,以确保性能与安全
标签:CISA项目, Rust, Web安全, 加密, 可视化界面, 漏洞扫描器, 网络流量审计, 蓝队分析, 通知系统