RedKnight-aj/ai-security-framework

GitHub: RedKnight-aj/ai-security-framework

一个生产级 Python 框架,可对 LLM 应用进行 OWASP LLM Top 10 安全扫描、红队测试和 NIST AI RMF 合规审计。

Stars: 0 | Forks: 0

# AI 安全框架 🛡️

最全面的 AI 安全测试框架。一个命令。完整的 OWASP LLM Top 10 + NIST AI RMF 合规审计。

License Python Tests OWASP LLM Top 10 Promptfoo Stars

安装说明快速开始功能使用示例CLIPython API合规性对比贡献指南

## 这是什么? AI Security Framework 是一个**生产级 Python 包**,可针对完整的 **OWASP LLM Top 10** 扫描任何 LLM 驱动的应用程序,生成专业安全报告(JSON/HTML/Markdown),并为 **OWASP LLM Top 10** 和 **NIST AI RMF** 生成合规审计报告——所有功能都来自一个命令行工具。 基于 [Promptfoo](https://github.com/promptfoo/promptfoo) 构建,包含 71 个 Python 文件、2700+ 行生产代码、68 个通过的测试,以及真实的漏洞/攻击模式数据库。 ## 快速开始 ⚡ 30 秒内获取结果: ``` # 安装 pip install ai-security-framework npm install -g promptfoo # required scan engine # 扫描任意 LLM 端点 ai-sec-scan scan \ --target https://api.example.com/v1/chat \ --quick-start basic-scan # 获取您的报告 ai-sec-scan report --input security-results/report.json --format html ``` 就这样。你刚刚完成了针对 OWASP LLM Top 10 的 LLM 扫描。 ## 功能 | 功能 | 详情 | |---------|---------| | **OWASP LLM Top 10** | 10 个完整的 Promptfoo 配置文件 — LLM01 到 LLM10 | | **快速启动预设** | `basic-scan`、`chatbot-scan`、`rag-app-scan` — 选了就用 | | **4 命令 CLI** | `scan`、`redteam`、`report`、`compliance` | | **红队引擎** | 注入、越狱、毒性、PII 负载,多种策略 | | **3 种报告格式** | JSON(机器可读)、HTML(高管)、Markdown(GitHub 就绪) | | **合规审计** | OWASP LLM Top 10 2025 + NIST AI RMF 1.0,含评分 | | **漏洞数据库** | 捆绑 `vulnerabilities.json`,包含 50+ 已知模式 | | **攻击模式库** | `attack-patterns.yml`,含 MITRE ATLAS 映射 | | **Python API** | `SecurityScanner`、`RedTeam`、`ReportGenerator`、`ComplianceAuditor` | | **68 个测试通过** | 完整测试套件,CI 就绪 | | **MIT 许可** | 免费用于商业和学术用途 | ## 架构 ``` ┌─────────────────────────────────────────────────────────────┐ │ ai-sec-scan CLI │ │ scan │ redteam │ report │ compliance │ └──────────────────────────┬──────────────────────────────────┘ │ ┌────────────┴────────────┐ │ │ ┌────────▼────────┐ ┌────────▼────────┐ │ SecurityScanner │ │ RedTeam │ │ │ │ │ │ • Load configs │ │ • Attack plugins│ │ • Run promptfoo │ │ • Strategies │ │ • Parse results │ │ • Built-in │ │ • ReturnFinding │ │ payloads │ └────────┬────────┘ └────────┬────────┘ │ │ └────────────┬───────────┘ │ ┌────────────▼────────────┐ │ OWASP LLM Top 10 │ │ Promptfoo Configs │ │ (10 YAML files) │ └────────────┬────────────┘ │ ┌────────────▼────────────┐ │ Promptfoo CLI │ │ (promptfoo eval) │ │ (promptfoo redteam) │ └────────────┬────────────┘ │ ┌────────────▼────────────┐ │ Your LLM / API │ │ (OpenAI, Ollama, etc.)│ └─────────────────────────┘ ┌─────────────────────────┐ │ ReportGenerator ◄─────┤ │ JSON │ HTML │ MD │ └─────────────────────────┘ ┌─────────────────────────┐ │ ComplianceAuditor ◄───┤ │ OWASP │ NIST AI RMF │ └─────────────────────────┘ ``` ## 安装说明 ### 从 PyPI 安装(推荐) ``` pip install ai-security-framework ``` ### 从源码安装 ``` git clone https://github.com/RedKnight-aj/ai-security-framework.git cd ai-security-framework pip install -e ".[dev]" ``` ### 前置条件 | 依赖项 | 版本 | 用途 | |------------|---------|---------| | Python | ≥ 3.9 | 运行时 | | Node.js + npm | ≥ 18 | Promptfoo 需要 Node | Promptfoo 是扫描引擎。安装一次即可: ``` npm install -g promptfoo ``` ### 环境变量(可选) ``` export SECURITY_TARGET="https://api.yourapp.com/v1/chat" export SECURITY_PROVIDER="openai:chat:gpt-4o" export SECURITY_TIMEOUT=600 export SECURITY_REPORT_DIR="./security-results" ``` ## 使用示例 ### 扫描 LLM 端点 ``` # 完整 OWASP 扫描(快速启动预设) ai-sec-scan scan \ --target https://api.example.com/v1/chat \ --quick-start basic-scan # 扫描特定 OWASP 类别 ai-sec-scan scan \ --target https://api.example.com/v1/chat \ --category LLM01 LLM06 LLM08 # 使用自定义配置文件扫描 ai-sec-scan scan \ --target https://api.example.com/v1/chat \ --config configs/owasp/LLM01-injection.yml ``` ### 红队攻击演练 ``` # 完整红队测试(所有插件) ai-sec-scan redteam \ --target https://api.example.com/v1/chat \ --plugins default \ --output redteam-results.json # 特定攻击插件和策略 ai-sec-scan redteam \ --target https://api.example.com/v1/chat \ --plugins injection,jailbreak \ --strategy direct,multi_turn \ --output injection-results.json ``` ### 生成报告 ``` # HTML 报告 ai-sec-scan report \ --input security-results/report.json \ --format html \ --output report.html # Markdown(用于 GitHub issues) ai-sec-scan report \ --input security-results/report.json \ --format markdown \ --output SECURITY.md ``` ### 合规审计 ``` # OWASP LLM Top 10 合规 ai-sec-scan compliance \ --target https://api.example.com/v1/chat \ --framework owasp # NIST AI RMF 合规 ai-sec-scan compliance \ --target https://api.example.com/v1/chat \ --framework nist_ai_rmf \ --output nist-report.json # 审计现有结果文件 ai-sec-scan compliance \ --input security-results/report.json \ --framework owasp ``` ### Python API ``` from ai_security import SecurityScanner, RedTeam, ReportGenerator, ComplianceAuditor # --- 扫描 --- scanner = SecurityScanner(target="https://api.example.com/v1/chat") findings = scanner.run_scan(categories=["LLM01", "LLM06"]) for f in findings: print(f"{f.vulnerability.severity}: {f.vulnerability.name} → {'VULNERABLE' if f.is_vulnerable else 'PASS'}") # --- 报告 --- reporter = ReportGenerator() reporter.to_html(findings, "security-report.html") reporter.to_markdown(findings, "SECURITY.md") # --- 合规 --- auditor = ComplianceAuditor() report = auditor.audit(findings, framework="owasp") print(f"OWASP Score: {report.score}/100 — {report.overall_status}") # --- 红队 --- rt = RedTeam(target="https://api.example.com/v1/chat") rt_findings = rt.run(plugins=["injection", "jailbreak"], strategies=["direct", "multi_turn"]) report = rt.generate_report(rt_findings) print(f"Attacks: {report['summary']['total_tests']} · Vulnerable: {report['summary']['vulnerabilities_found']}") ``` ## CLI 命令 | 命令 | 用途 | |---------|---------| | `ai-sec-scan scan` | 针对 OWASP LLM Top 10 的安全扫描 | | `ai-sec-scan redteam` | 红队攻击模拟 | | `ai-sec-scan report` | 生成 JSON/HTML/Markdown 报告 | | `ai-sec-scan compliance` | OWASP / NIST AI RMF 合规审计 | ``` ai-sec-scan --help ai-sec-scan scan --help ai-sec-scan redteam --help ai-sec-scan report --help ai-sec-scan compliance --help ``` 完整参考及所有选项请参阅 [docs/CLI.md]( --config configs/owasp/your-config.yml` 进行验证 ## 引用 在学术论文中使用: ``` @software{ai_security_framework_2026, author = {RedKnight AI}, title = {AI Security Framework: Production-Grade LLM Security Testing}, year = {2026}, url = {https://github.com/RedKnight-aj/ai-security-framework}, version = {2.0.0}, license = {MIT} } ``` ## 相关项目 - **[ai-security-scanner](https://github.com/RedKnight-aj/ai-security-scanner)** — 我们采用不同扫描方法的姐妹项目 - **[Promptfoo](https://github.com/promptfoo/promptfoo)** — 为我们的扫描器提供支持的 LLM 评估引擎 ## 许可 [MIT 许可](LICENSE) © 2026 RedKnight AI 免费用于商业、学术和个人用途。

RedKnight AI 构建 · 一次一个提示,保卫 AI 的未来。 🛡️

标签:AI安全, AMSI绕过, Chat Copilot, Homebrew安装, MITM代理, NIST AI RMF, OWASP LLM Top 10, Promptfoo, Prompt注入, 人工智能安全, 动态调试, 合规性, 多语言支持, 大语言模型安全, 威胁检测, 安全报告生成, 安全测试框架, 对抗性测试, 机密管理, 逆向工具