Sharmila-std/prompt_injection
GitHub: Sharmila-std/prompt_injection
SentinelAI 是一个通过实时分析 LLM Agent 行为遥测数据来检测并拦截提示注入攻击的企业级 AI 治理与防护平台。
Stars: 0 | Forks: 0
# SentinelAI
### 行为提示注入检测与 AI 治理平台
SentinelAI 是一个企业级的 AI 治理平台,旨在通过实时监控 AI Agent 的**行为**来检测提示注入攻击,而不是依赖于脆弱且容易被绕过的输入文本分析。
SentinelAI 将基于 LLM 驱动的 agent 视为不受信任的系统。通过流式传输 agent 的遥测数据(如工具调用、调用顺序、参数以及文件/数据库访问模式),该平台能够分析标准行为特征,运行异常检测模型,并作为防火墙在恶意 payload 执行前拦截被劫持的 agent。
## 🏗️ 整洁架构
该平台基于整洁架构和 SOLID 原则设计,将代码库划分为不同的模块:
- **`backend/`**:使用 Python、FastAPI、Uvicorn 和 Pydantic 编写的轻量级、高性能 API。专为高频遥测数据流摄取和执行风险评估而构建。
- **`frontend/`**:使用 Next.js、React、TypeScript 和 TailwindCSS 构建的交互式、响应式现代仪表盘,旨在提供统一的治理洞察和风险状态。
- **`docs/`**:详细的架构描述和 schema。
- **`datasets/`**:存储用于 ML 模型训练和基线画像分析的 agent 轨迹。
- **`models/`**:用于异常检测模型(例如 Isolation Forest)的序列化文件夹。
## 🗂️ 项目结构
```
SentinelAI/
├── backend/
│ ├── app/
│ │ ├── api/ # REST API routing and endpoints
│ │ ├── core/ # Core application logic & abstract bases
│ │ ├── config/ # Configuration management & environment loading
│ │ ├── agents/ # Mock agents & telemetry streaming specs
│ │ ├── tools/ # Tool execution metadata models
│ │ ├── logger/ # Structured enterprise logging setup
│ │ ├── monitoring/ # Telemetry listeners & session managers
│ │ ├── feature_engineering/ # Feature extraction from raw trace JSON
│ │ ├── anomaly_detection/ # ML models (e.g., isolation forests)
│ │ ├── risk_engine/ # Multi-layer threshold evaluations
│ │ ├── injection_simulator/ # Attack simulation drivers
│ │ ├── dashboard/ # Backend endpoint integrations for UI statistics
│ │ ├── database/ # Supabase PostgreSQL connections and config
│ │ ├── models/ # SQLAlchemy model definitions
│ │ ├── services/ # Database and ML computation services
│ │ ├── schemas/ # Pydantic data schemas
│ │ ├── utils/ # Shared auxiliary helper functions
│ │ ├── middleware/ # Security and rate limiting middlewares
│ │ └── main.py # API entry point & health check endpoints
│ │
│ ├── tests/ # Unit and integration test suites
│ ├── requirements.txt # Python packages manifest
│ ├── Dockerfile # Multi-stage production container setup
│ ├── .env.example # Configuration template
│ └── README.md # Backend readme
│
├── frontend/
│ ├── app/ # Next.js App Router (layout, page, global css)
│ ├── components/ # Shared UI components
│ ├── lib/ # Utility functions & axios clients
│ ├── hooks/ # Custom React hooks
│ ├── services/ # Api client services
│ ├── types/ # TypeScript declaration types
│ ├── public/ # Static assets (images, vectors)
│ ├── styles/ # Shared CSS variables
│ ├── package.json # Node package configuration
│ ├── tsconfig.json # TypeScript compiler config
│ └── README.md # Frontend readme
│
├── docs/ # High-level architecture and flow charts
├── docker/ # Extended environment compose configurations
├── datasets/ # AI trace training and simulation datasets
├── models/ # Serialized ML model binaries
├── logs/ # Output directory for application log files
├── scripts/ # Initialization and automation script hooks
├── .gitignore # Standard version control exclusion listing
├── docker-compose.yml # Service orchestration config
├── LICENSE # MIT License
└── README.md # Master Project Documentation
```
## 🛠️ 技术栈
| 层级 | 技术 | 用途 |
|---|---|---|
| **Backend** | Python 3.12, FastAPI, Uvicorn | 高性能、异步的 REST API 编排。 |
| **Data Validation** | Pydantic v2, Pydantic Settings | 对传入的轨迹遥测数据进行解析和 schema 验证。 |
| **ORM & DB Connection** | SQLAlchemy, Alembic, psycopg2-binary | 与 Supabase PostgreSQL 交互(阶段 1+)。 |
| **Agent / ML Libraries** | LangGraph, LangChain, scikit-learn, sentence-transformers | 遥测捕获和异常检测评分(阶段 1+)。 |
| **Frontend** | Next.js 16 (App Router), React 19, TypeScript | 高级动态 UI 仪表盘框架。 |
| **Styling** | TailwindCSS v4 | 现代响应式美学、毛玻璃效果和过渡动画。 |
| **Networking** | Axios, Plotly.js | 客户端 API 通信和 ML 图表绘制(阶段 1+)。 |
| **Infrastructure** | Docker, Compose, Vercel, Render | 无缝的容器编排以及本地/云端扩展。 |
## 🚀 设置与执行(本地开发)
### 前置条件
- **Python**: `3.12+`
- **Node.js**: `20.x+` (npm 10.x+)
- **Docker**: `24.x+` (包含 docker-compose)
### 运行后端
1. 导航至 `backend/` 目录:
cd backend
2. 创建并激活 Python 虚拟环境:
python -m venv venv
# 在 Windows (cmd) 上
venv\Scripts\activate
# 在 macOS/Linux 上
source venv/bin/activate
3. 安装后端依赖:
pip install -r requirements.txt
4. 创建本地环境配置:
copy .env.example .env
5. 通过 Uvicorn 启动 FastAPI 服务器:
python -m uvicorn app.main:app --reload --port 8000
*服务器将在 `http://localhost:8000` 启动。请在 `http://localhost:8000/health` 测试健康检查 endpoint。*
### 运行前端
1. 导航至 `frontend/` 目录:
cd frontend
2. 安装客户端依赖包:
npm install
3. 运行 Next.js 开发服务器:
npm run dev
*仪表盘将在 `http://localhost:3000` 启动。落地页会在挂载时自动探测后端的健康检查。*
## 🐳 Docker 部署
使用 Docker 构建并启动平台(阶段 0,仅限后端,符合规范):
1. **构建并运行后端服务**:
docker-compose up --build -d
2. **验证部署健康状态**:
使用 curl 或打开浏览器查询容器:
curl -f http://localhost:8000/health
可直接查看日志:
docker logs sentinelai-backend -f
## 🔮 未来执行阶段
- **阶段 1(核心 Agent 遥测与数据库)**:接入 Supabase schema 表,实现原始日志流水线,并结构化 agent 轨迹日志。
- **阶段 2(特征工程与异常检测)**:在实时 agent 工具调用字符串上实现 Isolation Forest 和序列嵌入向量指标。
- **阶段 3(风险缓解与治理 UI)**:创建实际的仪表盘图表,触发告警状态,并启用手动终止钩子。
标签:AI治理, AV绕过, DLL 劫持, FastAPI, 企业安全, 大语言模型, 异常检测, 提示词注入防御, 测试用例, 网络资产管理, 请求拦截, 逆向工具