ShravanTheegala/AgentSec-AI

GitHub: ShravanTheegala/AgentSec-AI

一个 AI 驱动的安全运营中心平台,结合本地机器学习模型与 LLM 实现实时威胁检测、事件分诊和攻击模拟。

Stars: 0 | Forks: 0

# AgentSec AI - AI 驱动的云安全运营中心 (SOC) AgentSec AI 是一个先进的生产级安全运营中心 (SOC) 平台,旨在接收系统遥测数据,使用本地机器学习模型对网络威胁向量进行分类,并利用 Google Gemini LLM Copilot 模型生成专业的安全事件分诊与缓解摘要。 本项目扩展了云网络安全事件响应研究论文: ## 架构概述 ``` +------------------------+ | Student Portal | (Victim Application) | (React, Port 3000) | +-----------+------------+ | | Client-Side Telemetry v +-----------+------------+ | AgentSec Backend | (FastAPI, Port 8000) | - Random Forest | | - Isolation Forest | | - Static Malware Scan | +-----------+---+--------+ | | Read/Write Logs | | AI Copilot Prompts +------------------------+ +-------------------+ v v +--------+-------+ +--------+-------+ | MongoDB Atlas | | Google Gemini | | (Port 27017) | | (AI Studio) | +----------------+ +----------------+ | | Structured JSON Report v +--------+-------+ | SOC Dashboard | | (React, Port 4000) +----------------+ ``` ## 文件夹结构 ``` AgentSecAI/ │ ├── backend/ │ ├── app/ │ │ ├── core/ # Logging & Configs │ │ ├── dependencies/ # Route access overrides │ │ ├── routers/ # API Routers (Auth, Simulation, Ingest) │ │ ├── schemas/ # Pydantic validation definitions │ │ ├── services/ # Core ML classifiers and Malware checks │ │ ├── main.py # App entry and startup Lifespan Seeding │ │ └── database.py # MongoDB connection hooks │ ├── tests/ # Pytest Unit Test suite │ ├── requirements.txt # Python packages │ └── Dockerfile # Backend container spec │ ├── frontend/ │ ├── student-portal/ # Protected Victim client web app │ │ ├── src/services/ # Telemetry Interceptor Services │ │ └── Dockerfile # Portal container spec │ │ │ └── dashboard/ # SOC Security Dashboard analyst portal │ ├── src/pages/ # Alerts console, Simulation Lab, Live Monitor │ └── Docker/ # Dashboard Nginx container spec │ ├── memory/ # Architectural logs & status trackers ├── start.bat # Windows bootstrapper script ├── start.sh # Linux bootstrapper script └── docker-compose.yml # Root multi-container composer orchestrator ``` ## 安装与设置 ### 前置条件 - [Node.js (v20+)](https://nodejs.org/) - [Python (v3.10+)](https://www.python.org/) - [Docker Desktop](https://www.docker.com/products/docker-desktop/) (推荐用于容器运行) - 本地运行的 MongoDB 或 MongoDB Atlas URI ### 配置说明 1. 复制环境变量模板: cp .env.example .env 2. 打开 `.env` 并配置您的凭证。将您的 Google AI Studio API key 粘贴到 `GEMINI_API_KEY` 中以启用 Gemini Copilot。如果留空,应用将自动默认提供稳健的静态解释。 ## 本地运行(开发模式) ### 1. 启动后端 ``` cd backend python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate pip install -r requirements.txt python -m uvicorn app.main:app --reload --port 8000 ``` *模型会在生命周期启动期间基于合成数据集自动进行训练。* ### 2. 启动学生门户 ``` cd frontend/student-portal npm install npm run dev ``` *学生门户运行在 `http://localhost:3000/`。* ### 3. 启动 SOC 仪表板 ``` cd frontend/dashboard npm install npm run dev ``` *SOC 仪表板运行在 `http://localhost:5173/`。* ## 使用 Docker 运行(生产就绪) 要在统一的 Docker 容器中构建并运行所有服务: - **Windows**: start.bat - **Linux/macOS**: chmod +x start.sh ./start.sh 正在运行的容器: - **受保护的学生门户**:`http://localhost:3000` - **SOC 安全仪表板**:`http://localhost:4000` - **后端 API Swagger 文档**:`http://localhost:8000/docs` ## 核心工作流 ### 1. AI 威胁检测流程 ``` Client Request -> Features Extracted -> Estimator Models -> Database Logging -> SOC Stream ``` HTTP 请求参数会被转换为 10 维特征向量。**Random Forest** 分类器会预测其类别(SQL Injection、XSS、Traversal、Brute Force、Normal)。如果被标记,该事件将被写入 MongoDB 并实时流式传输到 Live Monitor。 ### 2. 模拟流程 ``` Analyst Action -> Simulation Endpoint -> Ingest Trigger -> AI Predict -> Alert Event ``` SOC 分析师在模拟实验室(Simulation Lab)中点击 **Fire Payload**。这会通过 API 安全地执行模拟 payload 参数,触发 Random Forest/Isolation Forest 推理,创建真实的数据库事件,并动态将该事件推送到 Live Monitor。 ## API 端点 ### 身份验证 - `POST /api/v1/auth/register` - 创建新的 SOC 账户。 - `POST /api/v1/auth/login` - 进行身份验证并获取 JWT bearer token。 ### 遥测数据接入 - `POST /api/v1/telemetry` - 客户端遥测 pipeline 钩子。 ### 检测器模型 - `POST /api/v1/predict` - 使用 Random Forest 对 HTTP 请求进行分类。 - `POST /api/v1/anomaly` - 使用 Isolation Forest 检查速率行为异常。 - `POST /api/v1/malware-scan` - 扫描上传的元数据签名。 ### 安全事件 - `GET /api/v1/incidents` - 查询开启/已解决的事件队列。 - `POST /api/v1/incidents/{id}/explain` - 查询 Gemini LLM 以对事件进行分诊。 ### 威胁模拟器 - `POST /api/v1/simulation/sqli` - 安全触发模拟 SQL Injection。 - `POST /api/v1/simulation/xss` - 安全触发模拟跨站脚本攻击(Cross Site Scripting)。 - `POST /api/v1/simulation/ddos` - 安全触发模拟 DDoS 流量激增。 ## 故障排除 - **Windows Defender 拦截**:如果 Windows Defender 隔离了测试代码、构建文件夹或脚本,请确保 payload 字符串已拆分或混淆(例如,使用字符串拼接)。 - **Windows 上的 Vite Rolldown 错误**:在 Windows 上构建前端之前,请确保 `@rolldown/binding-win32-x64-msvc` 存在于 devDependencies 中。 ## 未来展望 - 将 SHAP 可解释性图表直接集成到事件详情视图中。 - LangGraph 自主安全调查 agent 执行主动遥测分诊。 - 多区域 Kubernetes 部署。
标签:AMSI绕过, Apex, AV绕过, Docker, FastAPI, LLM大模型, React, Syscalls, 威胁检测, 安全运营中心, 安全防御评估, 机器学习, 网络映射, 自动化攻击, 请求拦截, 逆向工具