sunehrisahel/prompt-injection-detector
GitHub: sunehrisahel/prompt-injection-detector
基于机器学习的提示词注入攻击检测中间件,通过意图感知 pipeline 在用户输入到达 LLM 之前进行实时安全分析和拦截。
Stars: 0 | Forks: 0
# AI 提示词注入检测器
基于 ML 的安全中间件,可在用户提交的文本到达 LLM 之前分析其中的 AI 威胁。使用**意图感知的 5 阶段 pipeline**:normalization → 意图分类 → 分类 regex 检测 → 综合风险评分 → 响应策略。
## 功能
- FastAPI 接口:`/analyze`、`/health`、`/logs`、`/analytics`、`/red-team/*`
- 具备意图感知评分的 12 类威胁检测
- TF-IDF + 逻辑回归 ML 分类器
- Red-team LLM 代理端点(Anthropic key 保留在服务端)
- `chatbot/` 中的可选 **SecureChat** UI(FastAPI + 静态前端)
## 快速开始(本地)
```
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000
```
```
curl http://localhost:8000/health
curl -X POST http://localhost:8000/analyze \
-H "Content-Type: application/json" \
-d '{"text": "hello", "source": "test"}'
```
## 在 Render 上部署
1. [在 Render 上连接此仓库](https://render.com/deploy)
2. Render 读取 `render.yaml` 并创建 **prompt-injection-detector**
3. 在 Environment 中设置 **ANTHROPIC_API_KEY** 和 **RED_TEAM_API_KEY**
4. 复制 red-team 仓库的 `DETECTOR_URL` 的线上 URL
## 可选:SecureChat UI
```
cd chatbot
cp .env.example .env # set ANTHROPIC_API_KEY, DETECTOR_URL
pip install -r requirements.txt
python web_server.py # http://localhost:3000
```
将 `chatbot/` 单独部署在 Vercel 上(参见 `chatbot/README.md`)。
## 测试
```
python -m pytest tests/ -v
```
## 相关仓库
- [prompt-injection-red-team](https://github.com/sunehrisahel/prompt-injection-red-team) — Streamlit 对抗性评估控制台
## License
MIT
标签:AMSI绕过, AV绕过, DLL 劫持, FastAPI, Python, 人工智能, 大语言模型, 威胁检测, 提示词注入攻击, 无后门, 用户模式Hook绕过, 逆向工具