# LLM-Sec **Repository Path**: sangjiacun_admin/LLM-Sec ## Basic Information - **Project Name**: LLM-Sec - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-09 - **Last Updated**: 2026-01-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 多模态大语言模型安全评估系统 一个基于 [OmniSafeBench-MM](https://github.com/jiaxiaojunQAQ/OmniSafeBench-MM) 构建的全栈安全评估平台,提供可视化的多模态大语言模型(MLLM)越狱攻击与防御评估能力。 ## 项目背景 本项目是一次 AI 辅助软件开发的实践探索。在尽可能减少人为干预的前提下,通过多个大语言模型协作完成了从需求分析到系统实现的全流程开发。 ### 开发历程(V1.0) | 阶段 | 执行者 | 任务内容 | |------|--------|----------| | 需求分析 | 豆包 | 阅读 OmniSafeBench-MM 源码,输出前端功能需求文档 | | 代码开发 | Claude Code | 根据需求文档,完成前端代码的从零实现 | | 调试优化 | Qode | 修复系统缺陷,优化功能体验 | ## 功能特性 - **统一评估框架**:支持从测试用例生成、模型响应生成到结果评估的完整流水线 - **丰富的攻击方法**:集成 FigStep、HADES、BAP、UMK 等 13 种主流多模态越狱攻击方法 - **多样的防御策略**:支持 JailGuard、MLLM-Protector、AdaShield、Llama-Guard 等 15 种防御方法 - **三维评估协议**:从有害性、意图对齐度、响应细节三个维度进行精细化评估 - **Web 管理界面**:提供可视化的实验管理、测试用例管理、评估结果分析界面 - **灵活的配置系统**:支持 YAML 配置文件和命令行参数的灵活组合 - **可扩展架构**:支持自定义攻击方法、防御策略、模型和评估器 ## OmniSafeBench-MM 架构 ![img](./OmniSafeBench-MM/docs/img/多模态大模型测评架构图.png) ## 系统架构 ``` ┌─────────────────────────────────────────────────────────────┐ │ 用户浏览器 │ │ (http://localhost:5173) │ └─────────────────────┬───────────────────────────────────────┘ │ HTTP/HTTPS ┌─────────────────────▼───────────────────────────────────────┐ │ 前端 (Vue 3) │ │ • Vue Router + Pinia 状态管理 │ │ • Element Plus UI 组件库 │ │ • ECharts 数据可视化 │ └─────────────────────┬───────────────────────────────────────┘ │ REST API + JWT ┌─────────────────────▼───────────────────────────────────────┐ │ 后端 API (FastAPI) │ │ • JWT 认证 + RBAC 权限控制 │ │ • 43 个 RESTful API 端点 │ │ • Pydantic 数据验证 │ └─────────────────────┬───────────────────────────────────────┘ │ SQLAlchemy ORM ┌─────────────────────▼───────────────────────────────────────┐ │ 数据库层 (MySQL/PostgreSQL) │ │ • 10 个核心数据表 │ │ • Alembic 数据库迁移 │ └─────────────────────────────────────────────────────────────┘ ``` ## 项目结构 ``` LLM-Sec/ ├── OmniSafeBench-MM/ # 核心评估框架 │ ├── api/ # FastAPI 后端 API │ │ ├── routes/ # API 路由模块 │ │ ├── auth.py # 认证逻辑 │ │ ├── config.py # API 配置 │ │ └── schemas.py # Pydantic 数据模型 │ ├── attacks/ # 攻击方法实现 │ ├── defenses/ # 防御策略实现 │ ├── models/ # 大语言模型接口 │ ├── evaluators/ # 评估器实现 │ ├── pipeline/ # 流水线核心模块 │ ├── database/ # 数据库模型和仓库 │ ├── config/ # 配置文件 │ │ ├── attacks/ # 攻击方法配置 │ │ ├── defenses/ # 防御策略配置 │ │ ├── general_config.yaml │ │ ├── model_config.yaml │ │ └── plugins.yaml │ ├── main.py # 后端入口文件 │ └── run_pipeline.py # 命令行流水线入口 ├── frontend/ # Vue3 前端应用 │ ├── src/ │ │ ├── api/ # API 接口定义 │ │ ├── components/ # 公共组件 │ │ ├── views/ # 页面组件 │ │ ├── stores/ # Pinia 状态管理 │ │ ├── router/ # 路由配置 │ │ └── types/ # TypeScript 类型定义 │ └── package.json └── README.md ``` ## 环境要求 - Python 3.10+ - Node.js 20+ - MySQL 8.0+ 或 PostgreSQL 13+ - CUDA 11.8+(GPU 推理需要) ## 快速开始 ### 1. 后端部署 ```bash # 进入后端目录 cd OmniSafeBench-MM # 安装依赖(推荐使用 uv) uv sync # 或使用 pip pip install -r requirements.txt # 配置环境变量 # 创建 .env 文件并配置以下内容 DATABASE_URL=mysql+pymysql://root:password@localhost:3306/omnisafebench_dev?charset=utf8mb4 SECRET_KEY=your-secret-key-must-be-at-least-32-characters-long # 初始化数据库 alembic upgrade head python database/init_db.py # 启动后端服务 python main.py ``` 后端服务将在 http://localhost:8000 启动,API 文档可访问 http://localhost:8000/api/docs ### 2. 前端部署 ```bash # 进入前端目录 cd frontend # 安装依赖 npm install # 启动开发服务器 npm run dev ``` 前端应用将在 http://localhost:5173 启动 ### 3. 默认账户 | 角色 | 用户名 | 密码 | |------|--------|------| | 管理员 | admin | admin123 | | 操作员 | operator | operator123 | ## 命令行使用 ### 运行完整流水线 ```bash python run_pipeline.py --config config/general_config.yaml --full ``` ### 分阶段运行 ```bash ## 第1阶段: 生成两张测试用例图片 D:\LLM-Sec\OmniSafeBench-MM\.venv\Scripts\python.exe D:\LLM-Sec\OmniSafeBench-MM\run_pipeline.py --config D:\LLM-Sec\OmniSafeBench-MM\output\test45\task_30_20260111_112140\config\task_30_config.yaml --stage test_case_generation --output-dir D:\LLM-Sec\OmniSafeBench-MM\output\test45\task_30_20260111_112140 ## 第2阶段:文生图大模型返回图片 D:\LLM-Sec\OmniSafeBench-MM\.venv\Scripts\python.exe D:\LLM-Sec\OmniSafeBench-MM\run_pipeline.py --config D:\LLM-Sec\OmniSafeBench-MM\output\test45\task_30_20260111_112140\config\task_30_config.yaml --stage response_generation --output-dir D:\LLM-Sec\OmniSafeBench-MM\output\test45\task_30_20260111_112140 ## 第3阶段:评估图片 D:\公司项目\202504-01-大模型安全测评系统\open_source\LLM-Sec\OmniSafeBench-MM\test\.run_evaluation_with_oss_force.ps1 ``` ## 配置说明 ### 通用配置 (config/general_config.yaml) - `test_case_generation.attacks`:选择攻击方法列表 - `response_generation.models`:选择目标模型列表 - `response_generation.defenses`:选择防御方法列表(可设为 "None" 跳过防御) - `evaluation.evaluators`:选择评估器 - `system.output_dir`:输出目录 ### 模型配置 (config/model_config.yaml) 按提供商分组配置模型参数,支持 OpenAI、Qwen、Google、Anthropic、vLLM 等多种后端。 ## 集成的攻击方法 | 方法 | 论文 | 会议 | |------|------|------| | FigStep | FigStep: Jailbreaking Large Vision-Language Models via Typographic Visual Prompts | AAAI 2025 | | QR-Attack | MM-SafetyBench: A Benchmark for Safety Evaluation of Multimodal Large Language Models | ECCV 2024 | | MML | Jailbreak Large Vision-Language Models Through Multi-Modal Linkage | ACL 2025 | | HADES | Images are Achilles' Heel of Alignment: Exploiting Visual Vulnerabilities for Jailbreaking MLLMs | ECCV 2024 | | BAP | Jailbreak Vision Language Models via Bi-Modal Adversarial Prompt | TIFS 2025 | | UMK | White-box Multimodal Jailbreaks Against Large Vision-Language Models | ACMMM 2024 | | JOOD | Playing the Fool: Jailbreaking LLMs and Multimodal LLMs with Out-of-Distribution Strategy | CVPR 2025 | | 更多... | 详见 OmniSafeBench-MM/README.md | - | ## 集成的防御方法 | 方法 | 论文 | 会议 | |------|------|------| | JailGuard | A Universal Detection Framework for Prompt-based Attacks on LLM Systems | TOSEM 2025 | | MLLM-Protector | Ensuring MLLM's Safety without Hurting Performance | EMNLP 2024 | | AdaShield | Safeguarding MLLMs from Structure-based Attack via Adaptive Shield Prompting | ECCV 2024 | | ShieldLM | Empowering LLMs as Aligned, Customizable and Explainable Safety Detectors | EMNLP 2024 | | Llama-Guard-4 | Llama Guard 4 | Meta | | 更多... | 详见 OmniSafeBench-MM/README.md | - | ## Web 界面功能 - **仪表盘**:展示系统统计数据和可视化图表 - **实验管理**:创建、运行、停止和管理安全评估实验 - **测试用例管理**:查看和管理越狱攻击测试用例 - **评估结果**:查看和分析模型安全评估结果 - **配置管理**:管理攻击方法、防御方法和模型配置 - **用户管理**:管理系统用户和权限 ## 输出格式 ### 测试用例输出 ```json { "test_case_id": "4", "prompt": "jailbreak_prompt_generated_by_attack", "image_path": "/path/to/jailbreak_image.jpg", "metadata": { "attack_method": "figstep", "original_prompt": "original harmful prompt" } } ``` ### 评估结果输出 ```json { "test_case_id": "case_001", "model_response": "model response text", "judge_score": 2, "judge_reason": "evaluation explanation", "success": false, "metadata": { "harmfulness_score": 1, "alignment_score": 2, "detail_score": 3 } } ``` ## 扩展开发 ### 添加新攻击方法 1. 在 `attacks/` 目录创建实现类,继承 `core.base_classes.BaseAttack` 2. 在 `config/plugins.yaml` 中注册组件 3. 创建 `config/attacks/.yaml` 配置文件 4. 在 `general_config.yaml` 中启用该攻击方法 ### 添加新防御方法 1. 在 `defenses/` 目录创建实现类,继承 `core.base_classes.BaseDefense` 2. 在 `config/plugins.yaml` 中注册组件 3. 创建 `config/defenses/.yaml` 配置文件 4. 在 `general_config.yaml` 中启用该防御方法 ## 技术栈 ### 后端 - FastAPI - 高性能异步 Web 框架 - SQLAlchemy 2.0 - ORM 框架 - Alembic - 数据库迁移 - Pydantic - 数据验证 - JWT - 认证机制 ### 前端 - Vue 3 - 渐进式 JavaScript 框架 - TypeScript - 类型安全 - Element Plus - UI 组件库 - Pinia - 状态管理 - ECharts - 数据可视化 - Vite - 构建工具 ## 相关文档 - [OmniSafeBench-MM 详细文档](./OmniSafeBench-MM/README.md) - [前端项目文档](./frontend/README.md) - [后端部署指南](./BACKEND_SETUP.md) - [数据库设计文档](./OmniSafeBench-MM/docs/DATABASE_DESIGN.md) - [API 快速入门](./OmniSafeBench-MM/docs/API_QUICK_START.md)