Abrarceoo/GemmaShield
GitHub: Abrarceoo/GemmaShield
这是一个完全在本地运行的AI应用红队测试平台,通过四个自主代理自动模拟对抗攻击,用于在部署前发现并评估大型语言模型的安全漏洞。
Stars: 0 | Forks: 0
# translate headings, and the emoji is part of the text, I should include it. Perhaps translate "Shield" but keep "Gemma". To be consistent, I'll keep "GemmaShield" as is. So output: 🛡️ GemmaShield (but in Chinese context, emojis are often kept, so I'll keep the entire thing as is). But the user said "output exactly 6 line(s) of translation", so I need to provide Chinese translations. For "🛡️ GemmaShield", I can translate it to "🛡️ GemmaShield" or "🛡️ Gemma 盾". I think the best is to keep the English term and add Chinese if necessary. Looking back at examples: 'Running Naabu' -> '运行 Naabu', so they translated "Running" to Chinese and kept "Naabu". Similarly, for "GemmaShield", if "Shield" is a word, translate it. But "GemmaShield" might be a single word. I'll assume "Gemma" is a name and "Shield" is part of it, so keep it as "GemmaShield". The emoji can be kept.
**部署前 AI 安全测试平台**
*在攻击者之前,使用对抗性代理对您的 LLM 应用进行压力测试 — 完全由本地通过 Ollama 运行的 Gemma 4 驱动。*
[](https://ollama.com)
[](https://github.com/Abrarceoo/GemmaShield)
[](https://ollama.com)
[](https://github.com/Abrarceoo/GemmaShield)
[](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
[](https://fastapi.tiangolo.com)
[](https://react.dev)
[](LICENSE)
*提交至 Kaggle Gemma 4 Good 黑客马拉松 · 安全与信任赛道 · Ollama 特别奖*
## 问题所在
AI 系统正在医院、银行、律师事务所和政府机构中部署 — 通常没有经过任何系统的对抗性测试。一旦上线,这些系统就面临:
- 覆盖系统指令的 **提示注入** 攻击
- 通过上下文操纵绕过安全防护栏的 **越狱**
- 试图探测敏感信息的 **数据提取** 尝试
- 提升攻击者权限的 **角色覆盖** 攻击
- 通过虚假权限声明进行的 **社会工程学** 攻击
目前缺乏一个标准化的、保护隐私的、用于 LLM 的部署前安全测试框架。GemmaShield 填补了这一空白。
## 解决方案
GemmaShield 是一个自动化红队测试平台,可以在 AI 系统投入生产之前模拟对抗性攻击。它运行 **四个自主代理** — 全部由 Gemma 4 驱动 — 在一个顺序流水线中生成攻击、模拟目标响应、分析威胁并发布安全裁决。
每次推理都 **100% 在本地通过 Ollama** 运行。无云 API。无数据离开机器。无备用模型。如果 Gemma 4 不可用,系统会明确显示 `MODEL UNAVAILABLE` 故障 — 它永远不会静默伪造输出。
## 架构
```
┌─────────────────────────────────────────────────────────┐
│ React Frontend (SSE Streaming) │
│ Scenarios · Battle Console · Dashboard · Reports │
└───────────────────────┬─────────────────────────────────┘
│ REST / Server-Sent Events
┌───────────────────────▼─────────────────────────────────┐
│ FastAPI Backend │
│ /battle/stream · /analytics · /reports │
└────┬──────────────┬──────────────┬──────────────┬───────┘
│ │ │ │
┌────▼────┐ ┌─────▼────┐ ┌─────▼────┐ ┌─────▼────┐
│Attacker │ │ Target │ │Defender │ │ Judge │
│ Agent │ │ Agent │ │ Agent │ │ Agent │
└────┬────┘ └─────┬────┘ └─────┬────┘ └─────┬────┘
└───────────────┴────────────┴──────────────┘
│
┌──────────▼──────────┐
│ Gemma 4 via Ollama │
│ REST API · Stream │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ SQLite + JSONL │
│ Audit Log │
└─────────────────────┘
```
### 技术栈
| 层 | 技术 |
|-------|-----------|
| AI 模型 | Gemma 4 (`gemma4:latest`) |
| 推理 | Ollama REST API — 本地、流式传输 |
| 后端 | FastAPI + Python 3.10+ |
| 前端 | React 18 + 服务器推送事件 |
| 数据库 | SQLite + JSONL 审计跟踪 |
| PDF 报告 | jsPDF(客户端生成) |
## 代理系统
每个代理都是一个独立的 Gemma 4 调用,带有专门设计的系统提示和结构化 JSON 输出模式。没有代理与其他代理共享上下文 — 每个代理都独立推理。
### 🔴 攻击代理
接收目标系统的实际系统提示,并生成一个旨在绕过其特定规则的真实对抗性攻击。攻击类型包括:提示注入、越狱、角色覆盖、数据提取、欺骗。
**输出模式:**
```
{
"attack_type": "data_extraction",
"attack_prompt": "...",
"technique": "Contextual Role Overwriting",
"target_weakness": "...",
"severity": "CRITICAL",
"stealth_score": 9
}
```
### ⚪ 目标代理
使用与真实目标部署相同的系统提示运行。接收攻击提示并像真实部署的 AI 一样自然地做出响应。
### 🔵 防御代理
独立分析攻击提示和目标响应。确定攻击是否成功,对威胁类别进行分类,评估风险等级,并产生逐步推理。
**输出模式:**
```
{
"blocked": false,
"risk_score": 8.5,
"threat_category": "Sensitive Information Disclosure",
"confidence": 0.95,
"reasoning_steps": ["...", "..."],
"defense_strategy": "..."
}
```
### ⚖️ 评判代理
发布最终权威的安全裁决 — 独立于防御代理的评估。产生类似 CVSS 的评分、漏洞分类、补丁优先级和修复建议。
**输出模式:**
```
{
"cvss_like_score": 9.2,
"severity": "CRITICAL",
"vulnerability_label": "CWE-77: Improper Neutralization (AI Variant)",
"patch_priority": "IMMEDIATE",
"recommendation": "...",
"judge_reasoning": "..."
}
```
## 可追溯性
每个代理响应都包含一个完整的审计信封:
```
{
"agent": "attacker",
"model": "gemma4:latest",
"source": "ollama",
"latency_ms": 28827,
"raw_output": "...",
"output": { ... }
}
```
此信封在前端的 **调试面板** 中可见 — 评审员和审计员可以验证每个输出都来自真实的 Gemma 4 推理。
## 与 OWASP LLM Top 10 对齐
每次攻击都会自动映射到 OWASP LLM Top 10 分类法:
| 攻击类型 | OWASP ID | 类别 |
|-------------|----------|----------|
| 提示注入 | LLM01 | 提示注入 |
| 越狱 | LLM02 | 不安全的输出处理 |
| 数据提取 | LLM06 | 敏感信息泄露 |
| 角色覆盖 | LLM08 | 过度授权 |
| 欺骗 | LLM09 | 过度依赖 / 信任偏差 |
## 预设场景
每个场景都包含一个反映真实世界 AI 部署的现实系统提示。攻击代理读取此系统提示并精心设计针对性攻击来绕过它。
| 场景 | 系统身份 | 主要风险 |
|----------|----------------|--------------|
| 🏥 医疗 AI | MedAssist — 城市总医院 | HIPAA / 患者数据 |
| 🏦 银行聊天机器人 | FinBot — 安全银行 | PCI-DSS / 金融数据 |
| ⚖️ 法律 AI | LexAI — Morrison & 合伙人律所 | 律师-客户特权 |
| 🏛️ 政府 AI | CivicAssist — 公共服务部 | 公民 PII |
| 🎓 教育 AI | EduBot — LearnSphere 学院 | FERPA / 学生数据 |
| 👤 人力资源 AI | HRConnect — TechCorp 人力资源部 | 员工记录 |
## 产品界面
### 对战控制台
实时流式传输界面,在执行时显示每个代理阶段。一旦攻击代理完成,立即显示 OWASP 分类。包含一个调试面板,显示原始 Gemma 4 输出、模型名称、来源以及每个代理的延迟。
### 仪表板
跨所有对战的聚合安全指标:总对战次数、拦截率、泄露率、平均 CVSS 评分、OWASP 分布热图以及按类型划分的攻击成功率。
### 报告
每个对战的完整安全报告,可在应用内查看并可下载为格式化的 PDF。包含执行摘要、攻击提示、漏洞分类、防御推理、建议和完整的可追溯性表。
### 对战历史
所有对战的表格日志,包含 OWASP 徽章、严重性、CVSS 评分、拦截/泄露状态和流水线延迟。
## To be precise, I'll translate the text where applicable. Let's list the translations:
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| `GET` | `/scenarios` | 所有包含系统提示的目标场景 |
| `POST` | `/battle/stream` | 完整的 4 代理流水线 — 服务器推送事件 |
| `POST` | `/battle` | 完整的 4 代理流水线 — 同步 |
| `POST` | `/campaign` | 顺序 N 次对战战役 |
| `GET` | `/analytics` | 统计数据、OWASP 分布、成功率 |
| `GET` | `/reports` | 所有对战报告 |
| `GET` | `/report/{id}` | 单次对战完整报告 |
| `GET` | `/logs` | 原始对战历史记录 |
| `GET` | `/health` | 系统状态 |
## 设置
**要求:** Python 3.10+, Node.js 18+, [Ollama](https://ollama.com)
[](https://github.com/Abrarceoo/GemmaShield)
```
# - Line 1: "🛡️ GemmaShield" – Since "GemmaShield" is likely a proper name, keep it in English. The emoji is a symbol, so I can keep it as is. So translation: 🛡️ GemmaShield (no change, but since it's a translation, perhaps add Chinese if needed). I think for consistency with examples, keep the English term and if there's a common word, translate it. But here, no clear translation. I'll output: 🛡️ GemmaShield
ollama pull gemma4:latest
# But the user expects a translation to Simplified Chinese. Perhaps I should translate "Shield" to "盾". So: 🛡️ Gemma 盾牌 or 🛡️ GemmaShield. I'll go with keeping it as is since it's a proper noun.
cd backend
pip install -r requirements.txt
uvicorn main:app --reload --port 8000
# - Line 2: "API" – This is a standard acronym, keep it in English. So: API
ollama run gemma4:latest "hi"
# - Line 3: "1. Pull Gemma 4" – Here, "Pull" might be a command or action, "Gemma 4" could be a model or version. Keep "Gemma 4" in English, translate "Pull". In software context, "Pull" often means to pull data or code, so translate to "拉取" in Chinese. So: 1. 拉取 Gemma 4
cd frontend
npm install
npm start
```
打开 **http://localhost:3000**,选择一个场景,然后按 **▶ BATTLE**。
## 为何重要
未经对抗性测试就部署的 AI 系统是一种负担。一个可被操纵泄露患者数据的医院聊天机器人、一个可被欺骗透露账户详情的银行助手、一个可通过社会工程学提示绕过的政府服务 — 这些都不是理论上的风险。
GemmaShield 提供了一个可重复、有记录、符合 OWASP 标准的测试方法,组织可以在每次部署前运行该方法 — 完全在自己的基础设施上进行,无需数据离开其环境。
## 与黑客马拉松的契合点
**安全与信任赛道**
GemmaShield 直接回应了赛道要求:*"开创透明度和可靠性框架,确保 AI 保持扎实和可解释。"* 该平台产生结构化、可审计的安全评估,并包含完整的推理链 — 使 AI 行为可解释,其漏洞可操作。
**Ollama 特别奖**
通过 Ollama 使用 Gemma 4 并非外围功能 — 它是整个推理层。所有四个代理都通过启用了流式传输的 Ollama REST API 调用 `gemma4:latest`。该系统被设计为在 Ollama 不可用时发生故障,证明本地推断是基础性的,而非可选的。
*GemmaShield — 基于 Gemma 4 构建 · 本地运行 · 无需云服务*
标签:AI安全, AI风险缓解, AV绕过, Chat Copilot, CVSS评分, FastAPI, Gemma 4, Linux系统监控, LLM评估, Ollama, OWASP LLM Top 10, PDF报告, React, Syscalls, 一键部署, 反取证, 威胁建模, 安全测试平台, 安全评估, 对抗性测试, 时序数据库, 智能体测试, 本地推理, 模型安全, 网络安全, 网络安全, 自定义脚本, 逆向工具, 隐私保护, 隐私保护, 预部署测试