haseeb-shah-12/ai-cybersecurity-soc-agent

GitHub: haseeb-shah-12/ai-cybersecurity-soc-agent

一个由 LangGraph 和 LLM 驱动的多智能体安全运营中心系统,用于自动化威胁检测、日志分析、事件响应和安全情报检索。

Stars: 0 | Forks: 0

# 🔒 AI 网络安全 SOC Agent 一个由 LangGraph、LLM 和机器学习驱动的高级安全运营中心 (SOC) **多智能体 AI 系统**。该系统通过智能体 AI 工作流实现威胁检测、事件响应和异常检测的自动化,并提供智能化的安全洞察。 ## 🎯 核心功能 ### 智能体 AI 与多智能体系统 - **基于 LangGraph 的编排** - 有状态的、基于图的智能体工作流 - **多智能体架构** - 针对不同安全领域的专用智能体 - **威胁检测智能体** - 识别可疑模式和异常 - **事件响应智能体** - 协调自动化响应操作 - **日志分析智能体** - 解析并提取安全事件 - **威胁情报智能体** - 检索和关联威胁数据 - **异常检测智能体** - 使用机器学习进行行为分析 - **分类智能体** - 对事件进行标记和优先级排序 ### 威胁检测与响应 - 🚨 **实时日志分析** - 处理来自多个来源的安全日志 - 🔍 **异常检测** - 基于统计和机器学习的异常检测 - 📊 **模式匹配** - 识别已知的攻击签名 - 🎯 **威胁分类** - 基于机器学习的威胁严重性和类型分类 - ⚡ **自动化响应剧本** - 根据威胁类型执行响应操作 - 📈 **事件关联** - 链接相关的安全事件 ### 情报与上下文 - 🧠 **RAG (检索增强生成)** - 查询安全知识库 - 📚 **安全知识检索** - 自定义威胁情报集成 - 🔗 **基于 LLM 的分析** - 使用 GPT-4/Claude 进行上下文威胁分析 - 🎓 **Few-shot Learning** - 从历史事件中学习 ### 部署与运营 - 🐳 **Docker 容器化** - 面向生产环境的容器化 - ⚙️ **FastAPI 端点** - 用于智能体交互的 RESTful API - 📊 **MLOps Pipeline** - 模型训练、评估和部署 - 📈 **监控与可观测性** - Prometheus 指标和结构化日志 - 🔄 **支持 CI/CD** - GitHub Actions 工作流 ## 📋 技术栈 | 层级 | 技术 | |-------|---------------| | **智能体编排** | LangGraph, LangChain, Pydantic | | **LLM** | OpenAI GPT-4, Claude, 本地 LLM | | **机器学习/异常检测** | scikit-learn, PyOD, XGBoost | | **数据处理** | Pandas, NumPy, Elasticsearch | | **API 框架** | FastAPI, Uvicorn | | **部署** | Docker, Docker Compose | | **知识检索** | FAISS/Chroma (RAG), Pinecone | | **监控** | Prometheus, 结构化日志 | | **测试** | Pytest, Mock | ## 🏗️ 架构 ``` ┌─────────────────────────────────────────────────────────┐ │ Data Sources (Logs, Events, Streams) │ │ ┌──────────────────────────────────────────────────┐ │ │ │ Elasticsearch | Splunk | AWS | GCP | Syslog │ │ │ └──────────────────────────────────────────────────┘ │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ Log Ingestion & Pre-processing Layer │ │ ┌──────────────────────────────────────────────────┐ │ │ │ Parsing | Normalization | Enrichment │ │ │ └──────────────────────────────────────────────────┘ │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ LangGraph Multi-Agent Orchestration Layer │ │ ┌──────────────────────────────────────────────────┐ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ │ │ Threat Detection Agent │ │ │ │ │ │ ├─ Pattern Matching │ │ │ │ │ │ ├─ Anomaly Detection (ML) │ │ │ │ │ │ └─ Threat Scoring │ │ │ │ │ └─────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ │ │ Log Analysis Agent │ │ │ │ │ │ ├─ Parse & Normalize │ │ │ │ │ │ ├─ Extract IoCs │ │ │ │ │ │ └─ Correlate Events │ │ │ │ │ └─────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ │ │ Threat Intelligence Agent (RAG) │ │ │ │ │ │ ├─ Query Knowledge Base │ │ │ │ │ │ ├─ Retrieve Context │ │ │ │ │ │ └─ Enrich Findings │ │ │ │ │ └─────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ │ │ Incident Response Agent │ │ │ │ │ │ ├─ Execute Playbooks │ │ │ │ │ │ ├─ Notify Teams │ │ │ │ │ │ └─ Track Response │ │ │ │ │ └─────────────────────────────────────────┘ │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ │ │ Classification Agent (ML) │ │ │ │ │ │ ├─ Severity Classification │ │ │ │ │ │ ├─ Threat Type Detection │ │ │ │ │ │ └─ False Positive Filtering │ │ │ │ │ └──��──────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────┘ │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ LLM-Enhanced Analysis & Decision Making │ │ ┌──────────────────────────────────────────────────┐ │ │ │ GPT-4 / Claude / Local LLM │ │ │ │ ├─ Contextual Threat Analysis │ │ │ │ ├─ Recommendation Generation │ │ │ │ └─ Report Writing │ │ │ └──────────────────────────────────────────────────┘ │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ Alert & Response Generation │ │ ┌──────────────────────────────────────────────────┐ │ │ │ Slack | Jira | PagerDuty | Email | Webhooks │ │ │ └──────────────────────────────────────────────────┘ │ └────────────────────┬────────────────────────────────────┘ │ ┌────────────────────▼────────────────────────────────────┐ │ FastAPI Dashboard & Monitoring │ │ ┌──────────────────────────────────────────────────┐ │ │ │ REST API | WebSocket | Prometheus | Logs │ │ │ └──────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────┘ ``` ## 🚀 快速开始 ### 前置条件 - Python 3.9+ - Docker & Docker Compose - OpenAI API key (或替代的 LLM) - Elasticsearch (可选,用作日志源) ### 安装 ``` # Clone repository git clone https://github.com/haseeb-shah-12/ai-cybersecurity-soc-agent.git cd ai-cybersecurity-soc-agent # 创建虚拟环境 python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate # 安装依赖 pip install -r requirements.txt # 设置环境 cp .env.example .env # 使用你的配置编辑 .env ``` ### 本地运行 ``` # 启动 FastAPI 服务器 python -m uvicorn src.api.server:app --reload # 在另一个终端中,运行 agent python main.py ``` ### 使用 Docker 运行 ``` # 构建并启动服务 docker-compose up --build # 查看日志 docker-compose logs -f soc-agent ``` ## 📁 项目结构 ``` ai-cybersecurity-soc-agent/ ├── src/ │ ├── agents/ # Multi-agent system (LangGraph) │ │ ├── __init__.py │ │ ├── base_agent.py # Base agent class │ │ ├── threat_detection.py # Threat detection agent │ │ ├── log_analysis.py # Log analysis agent │ │ ├── threat_intelligence.py # RAG-based threat intel agent │ │ ├── incident_response.py # Incident response agent │ │ ├── classification.py # ML classification agent │ │ ├── orchestrator.py # LangGraph orchestration │ │ └── workflows/ │ │ ├── threat_detection_workflow.py │ │ └── incident_response_workflow.py │ │ │ ├── detectors/ # Threat detection modules │ │ ├── __init__.py │ │ ├── anomaly_detector.py # Statistical & ML anomalies │ │ ├── pattern_matcher.py # Signature-based detection │ │ ├── ioc_extractor.py # IoC extraction │ │ └── models/ │ │ ├── isolation_forest.pkl │ │ └── threat_classifier.pkl │ │ │ ├── ml/ # Machine learning pipelines │ │ ├── __init__.py │ │ ├── anomaly_detection.py # PyOD models │ │ ├── classification.py # Threat classification │ │ ├── feature_engineering.py # Feature extraction │ │ └── training.py # Model training pipeline │ │ │ ├── rag/ # RAG system for threat intelligence │ │ ├── __init__.py │ │ ├── knowledge_base.py # Knowledge base setup │ │ ├── retriever.py # RAG retriever │ │ ├── documents/ │ │ │ ├── mitre_attack.md │ │ │ ├── cve_database.md │ │ │ └── threat_intelligence.md │ │ └── embeddings.py # Embedding models │ │ │ ├── integrations/ # External integrations │ │ ├── __init__.py │ │ ├── elasticsearch_client.py # Elasticsearch connector │ │ ├── siem_connector.py # SIEM integrations │ │ ├── log_sources/ │ │ │ ├── cloudtrail.py │ │ │ ├── windows_events.py │ │ │ └── firewall_logs.py │ │ ├── alerting.py # Alert channels (Slack, Jira, etc.) │ │ └── playbooks.py # Incident response playbooks │ │ │ ├── llm/ # LLM integration │ │ ├── __init__.py │ │ ├── models.py # LLM model wrappers │ │ ├── prompts.py # Prompt templates │ │ └── callbacks.py # LLM callbacks & monitoring │ │ │ ├── api/ # FastAPI server │ │ ├── __init__.py │ │ ├── server.py # Main FastAPI app │ │ ├── routes/ │ │ │ ├── agents.py # Agent endpoints │ │ │ ├── logs.py # Log ingestion endpoints │ │ │ ├── incidents.py # Incident management endpoints │ │ │ ├── threats.py # Threat analysis endpoints │ │ │ └── health.py # Health check │ │ ├── schemas.py # Pydantic schemas │ │ └── middleware.py # Auth, logging, monitoring │ │ │ ├── utils/ # Utilities │ │ ├── __init__.py │ │ ├── logger.py # Structured logging │ │ ├── config.py # Configuration management │ │ ├── cache.py # Caching utilities │ │ └── validators.py # Input validation │ │ │ ├── models/ # Data models │ │ ├── __init__.py │ │ ├── schemas.py # Pydantic models │ │ ├── threat.py # Threat data models │ │ └── incident.py # Incident data models │ │ │ └── monitoring/ # Observability │ ├── __init__.py │ ├── metrics.py # Prometheus metrics │ └── tracing.py # Distributed tracing │ ├── config/ │ ├── config.yaml # Main configuration │ ├── agents.yaml # Agent configurations │ ├── models.yaml # ML model configurations │ ├── threats.yaml # Threat definitions │ └── playbooks.yaml # Response playbooks │ ├── data/ │ ├── logs/ # Sample logs │ ├── models/ # Trained ML models │ └── knowledge_base/ # RAG knowledge base │ ├── tests/ │ ├── __init__.py │ ├── unit/ │ │ ├── test_agents.py │ │ ├── test_detectors.py │ │ ├── test_ml.py │ │ └── test_rag.py │ ├── integration/ │ │ ├── test_workflows.py │ │ └── test_api.py │ └── fixtures/ │ └── sample_logs.json │ ├── docs/ │ ├── ARCHITECTURE.md │ ├── SETUP.md │ ├── API.md │ ├── AGENTS.md │ ├── ML_PIPELINE.md │ └── RAG_SYSTEM.md │ ├── scripts/ │ ├── train_models.py # Train ML models │ ├── build_knowledge_base.py # Build RAG KB │ ├── generate_sample_logs.py # Generate test data │ └── deploy.sh # Deployment script │ ├── Dockerfile ├── docker-compose.yml ├── requirements.txt ├── requirements-dev.txt ├── .env.example ├── .gitignore ├── pytest.ini ├── main.py # Entry point └── README.md ``` ## 🔄 智能体工作流 ### 威胁检测工作流 ``` Log Input → Log Analysis Agent → Anomaly Detection → Pattern Matching → Classification Agent → Threat Intelligence Agent (RAG) → LLM Analysis → Alert Generation ``` ### 事件响应工作流 ``` High-Severity Threat → Incident Response Agent → Execute Playbook → Notify Teams → Track Response → Report Results ``` ## 🤖 多智能体系统 | 智能体 | 职责 | |-------|-----------------| | **日志分析智能体** | 解析、规范化和丰富安全日志 | | **威胁检测智能体** | 识别可疑模式和异常 | | **分类智能体** | 按严重性和类型对威胁进行分类 (基于机器学习) | | **威胁情报智能体** | 查询 RAG 知识库以获取上下文 | | **事件响应智能体** | 执行自动化响应剧本 | | **编排智能体** | 协调多智能体工作流 (LangGraph) | ## 📊 机器学习组件 - **异常检测**: Isolation Forest, LOF, Autoencoder - **分类**: XGBoost, Random Forest 威胁严重性/类型 - **特征工程**: 日志模式提取、统计特征 - **MLOps**: 模型版本控制、A/B 测试、监控 ## 🧠 RAG 系统 - **知识源**: MITRE ATT&CK、CVE 数据库、威胁情报 - **Embedding 模型**: OpenAI embedding 或 sentence-transformer - **向量数据库**: FAISS、Chroma 或 Pinecone - **检索**: 针对威胁上下文的语义搜索 ## 🐳 Docker 部署 ``` # 构建 images docker-compose build # 启动服务 docker-compose up -d # 查看日志 docker-compose logs -f soc-agent # 停止服务 docker-compose down ``` ## 📡 API 端点 - `POST /api/v1/agents/analyze` - 分析安全事件 - `POST /api/v1/logs/ingest` - 摄取安全日志 - `GET /api/v1/incidents` - 列出事件 - `POST /api/v1/incidents/{id}/respond` - 执行事件响应 - `GET /api/v1/threats` - 获取威胁分析 - `GET /api/v1/health` - 健康检查 - `GET /metrics` - Prometheus 指标 ## 🧪 测试 ``` # 运行所有测试 pytest # 运行 coverage pytest --cov=src # 运行特定测试 pytest tests/unit/test_agents.py ``` ## 📚 文档 - [架构](docs/ARCHITECTURE.md) - 系统设计和数据流 - [设置指南](docs/SETUP.md) - 安装和配置 - [API 参考](docs/API.md) - REST API 端点 - [智能体指南](docs/AGENTS.md) - 智能体行为和工作流 - [机器学习流水线](docs/ML_PIPELINE.md) - 模型训练和评估 - [RAG 系统](docs/RAG_SYSTEM.md) - 知识检索设置 ## 🛠️ 开发 ``` # 安装 dev 依赖 pip install -r requirements-dev.txt # 格式化代码 black src tests # Lint flake8 src tests # Type checking mypy src ``` ## 🔐 安全最佳实践 - 将 API key 存储在环境变量中 - 使用密钥管理工具 (HashiCorp Vault, AWS Secrets Manager) - 验证所有输入 - 实施速率限制 - 启用审计日志 - 为 API 使用 HTTPS - 定期进行安全测试 ## 📈 监控与可观测性 - 所有智能体的 Prometheus 指标 - JSON 格式的结构化日志 - 分布式追踪 (OpenTelemetry) - 告警阈值和 SLO - 性能仪表盘 (Grafana) ## 📝 许可证 MIT 许可证 - 请参阅 LICENSE 文件 ## 📞 支持与联系 如有任何问题、疑问或建议: - 提交一个 [GitHub Issue](https://github.com/haseeb-shah-12/ai-cybersecurity-soc-agent/issues) - 联系维护者 ## 🌟 路线图 - [ ] 支持 WebSocket 实时告警 - [ ] 高级可视化仪表盘 - [ ] Kubernetes 部署清单 - [ ] 多 LLM 支持 (Claude, Llama) - [ ] 高级威胁建模 - [ ] 自动化剧本生成 - [ ] 集成更多 SIEM 平台 - [ ] 自定义模型 fine-tuning **为网络安全团队倾注 ❤️ 打造**
标签:AI智能体, AMSI绕过, Apex, DLL 劫持, 大语言模型, 威胁检测, 安全运营中心, 机器学习, 网络映射, 自动化响应, 自定义请求头, 请求拦截, 逆向工具, 速率限制