ahirtonlopes/Mastering-LLM-Security
GitHub: ahirtonlopes/Mastering-LLM-Security
一门结合OWASP LLM Top 10与实战的大语言模型安全开放课件,涵盖guardrails防御、安全监控与红队测试。
Stars: 0 | Forks: 0
# 精通 LLM 安全
关于 LLM 安全与 AI 可靠性的开放课件 — OWASP LLM Top 10、guardrails、监控、红队测试与治理 · Gemini API · Python




## 你将学到什么
- 识别针对 LLM 的主要攻击向量(OWASP LLM Top 10)
- 实现多层 guardrails:regex、范围策略和 LLM-as-Judge
- 生成并解释 JSON 格式的结构化安全日志
- 执行自动化测试套件并计算指标(精确率、召回率、F1)
- 应用红队测试和规避技术来测试你自己的控制措施
- 将概念与现实世界联系起来:LGPD、EU AI Act、PL 2338/2023
## 前置条件
| 主题 | 级别 |
|---|---|
| Python | 中级 |
| REST API / JSON | 基础 |
| 机器学习概念 | 基础 |
| Google 账户 (AI Studio) | 必需(免费) |
## 目录
| # | Notebook | 主题 | OWASP 参考 |
|---|---|---|---|
| 01 | `Aula1_Security/llm_security_gemini_ptbr.ipynb` | 漏洞助手、prompt injection、PII 提取、多层 guardrails、结构化日志、安全指标 | LLM01, LLM06, LLM08 |
## Guardrails 架构
```
┌─────────────────────────────────────────────────────────────┐
│ APLICAÇÃO COM LLM │
│ │
│ INPUT GUARDRAILS OUTPUT │
│ ─────── ───────────────── ──────────── │
│ Usuário ──► Classificador ──► Gemini API ──► Resp. │
│ ──► Padrões banidos ──► (se seguro) │
│ ──► Política escopo ──► Bloqueio ──► Aviso │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────┐ ┌──────────┐ │
│ │ LOGS │ │ MÉTRICAS │ │
│ │ JSON │ │ │ │
│ └─────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
```
## OWASP LLM Top 10 (2025) 映射
| # | 漏洞 | 本课程涵盖 |
|---|---|---|
| LLM01 | Prompt Injection | ✅ 第 1 课 |
| LLM02 | Insecure Output Handling | ✅ 第 1 课 |
| LLM03 | Training Data Poisoning | ⚠️ 概念介绍 |
| LLM04 | Model Denial of Service | ⚠️ 概念介绍 |
| LLM05 | Supply Chain Vulnerabilities | 🔜 即将推出 |
| LLM06 | Sensitive Information Disclosure | ✅ 第 1 课 |
| LLM07 | Insecure Plugin Design | 🔜 即将推出 |
| LLM08 | Excessive Agency | ✅ 第 1 课 |
| LLM09 | Overreliance | ✅ 第 1 课 |
| LLM10 | Model Theft | ⚠️ 概念介绍 |
## 如何开始
**选项 1 — Google Colab(推荐)**
直接在 GitHub 上打开任意 notebook,然后点击文件顶部的 **Open in Colab**。
**选项 2 — 本地**
```
git clone https://github.com/ahirtonlopes/Mastering-LLM-Security.git
cd Mastering-LLM-Security
python -m venv .venv && source .venv/bin/activate
pip install google-genai jupyter
jupyter notebook
```
**API Key(免费):**
1. 访问 [aistudio.google.com](https://aistudio.google.com)
2. 点击 **Get API key → Create API key**
3. 在 Colab 中:将其添加为名为 `GEMINI_API_KEY` 的 secret
## 参考资料
- [OWASP Top 10 for LLM Applications 2025](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
- [Google AI Safety](https://ai.google/responsibility/safety/)
- [NIST AI Risk Management Framework](https://www.nist.gov/system/files/documents/2023/01/26/AI%20RMF%201.0.pdf)
- [PL 2338/2023 — 巴西 AI 监管框架](https://www.camara.leg.br/proposicoesWeb/fichadetramitacao?idProposicao=2384425)
## 作者
**Prof. Dr. Ahirton Lopes** · [LinkedIn](https://linkedin.com/in/ahirtonlopes) · [Google Scholar](https://scholar.google.com/citations?user=1SQDVrwAAAAJ)
人工智能 MBA — FIAP | 课程:AI 系统的安全与可靠性
欢迎贡献 — 请提交一个 issue 或发送 pull request。
## 许可证
[MIT](LICENSE)
标签:AI可靠性, NoSQL, OWASP LLM Top 10, Python, 大模型护栏, 开源课件, 无后门, 逆向工具