AyeshaaRafaqat/Prompt-Injection-Detection-Engine
GitHub: AyeshaaRafaqat/Prompt-Injection-Detection-Engine
面向大语言模型的提示词注入攻击多层检测网关,通过规则匹配、语义相似度和启发式分析在恶意输入到达LLM前完成拦截与风险评估。
Stars: 0 | Forks: 0
# 提示词注入检测引擎 (PIDE)
一个针对大语言模型提示词注入攻击的多层检测系统。它提供快速的、基于规则的第一层检测(Layer 1)、embedding 相似度计算、启发式分析和风险评分。
## 快速开始(无需额外文件)
### 1. 克隆仓库
```
git clone https://github.com/AyeshaaRafaqt/Prompt-Injection-Detection-Engine.git
cd Prompt-Injection-Detection-Engine
```
### 2. 选择运行方式
#### a) **使用内置的 Makefile**(推荐初学者使用)
```
# 创建虚拟环境并安装依赖
make install
# 启动 API server (FastAPI) – 将在 http://localhost:8000 可访问
make run-api
# 在另一个终端中,启动 Gradio playground UI – http://localhost:7860
make run-ui
# 运行完整的测试套件
make test
```
#### b) **手动命令**(如果您更喜欢原始步骤)
```
# Windows PowerShell
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
python -m spacy download en_core_web_sm
python scripts/build_exemplars.py
# API
uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload
# Gradio UI
python -m demo.gradio_app
# 运行测试
pytest tests/ -v
```
#### c) **Docker**(适用于任何已安装 Docker 的平台的一行命令)
```
# 构建镜像(一次)
docker build -t pide .
# 运行容器 – 暴露 API 于 8000 和 UI 于 7860
docker run -p 8000:8000 -p 7860:7860 pide
```
## 项目结构(供参考)
```
.
├── api/ # FastAPI REST gateway
├── config/ # YAML patterns & scoring config
├── data/ # Exemplars & FAISS index
├── demo/ # Gradio UI & LLM client helper
├── evaluation/ # Ablation & benchmark scripts
├── layers/ # Detection layers (L1‑L4)
├── logs/ # Audit logs (privacy‑preserving)
├── scripts/ # Utility scripts (e.g., build_exemplars.py)
├── tests/ # Pytest suite (39 tests)
├── Dockerfile # Container build file
├── Makefile # Helper targets for common tasks
├── pipeline.py # Orchestrates layers & fail‑secure logic
├── requirements.txt
└── README.md # (this file)
```
## Dockerfile(已包含在仓库中)
仓库已经包含了一个最小的 `Dockerfile`,它:
1. 使用轻量级的 Python 3.11 基础镜像。
2. 创建虚拟环境,安装所有依赖项,并下载 spaCy 模型。
3. 暴露端口 **8000**(API)和 **7860**(Gradio UI)。
4. 默认启动 API 服务器。可以通过同一容器访问 UI,地址为 `http://localhost:7860`。
## Makefile(已包含在仓库中)
```
VENV=venv
PYTHON=$(VENV)/Scripts/python.exe
# 创建虚拟环境
venv:
python -m venv $(VENV)
# 安装依赖和 spaCy 模型
install: venv
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip install -r requirements.txt
$(PYTHON) -m spacy download en_core_web_sm
# 运行 API server (FastAPI)
run-api:
$(PYTHON) -m uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload
# 运行 Gradio Playground UI
run-ui:
$(PYTHON) -m demo.gradio_app
# 执行完整的测试套件
test:
$(PYTHON) -m pytest -q
```
使用 `make ` 运行任何目标(例如,`make run-ui`)。
## 许可证
MIT – 欢迎自由 fork、扩展并在您自己的项目中使用。
标签:AV绕过, DLL 劫持, Docker, FastAPI, Gradio, 人工智能安全, 合规性, 大语言模型, 安全网关, 安全防御评估, 提示词注入检测, 请求拦截, 逆向工具