M3tan01/OpenElia

GitHub: M3tan01/OpenElia

下一代AI驱动的紫色团队平台,以MCP编排红蓝协作,实现攻击的自动化模拟与防御的实时闭环。

Stars: 3 | Forks: 1

# 🛡️ OpenElia Core **自主人工智能驱动的紫色团队编排平台** OpenElia 是一个下一代网络安全操作库,旨在处理多代理进攻和防御操作。由大型语言模型(LLM)和模型上下文协议(MCP)提供支持,它为模拟真实攻击和自动化实时防御提供了一个安全、高性能的生态系统。 ## **重要提示:** **请查看 COMMANDS.txt 以获取完整的命令参考和模型配置指南!** ## 🚀 五层安全架构 1. **身份与配置**:API 密钥存储在操作系统原生密钥库中(macOS 钥匙串,Linux Secret Service)。静态凭证使用 **Fernet AES-256 加密**(`state/vault.bin`)。加密密钥从不接触磁盘——仅存储在操作系统密钥环中。 2. **双重防火墙**:每次工具调用都经过 **数学防火墙**(范围/IP 验证,无 `roe.json` 时失败关闭)和 **语义防火墙**(有效载荷净化)的验证。SIEM Webhook 使用严格的 **主机名允许列表**(`SIEM_WEBHOOK_ALLOWLIST`),而非黑名单。 3. **无菌执行**:进攻模块在 **临时、无特权的 Docker 容器**(`cap_drop=ALL`)中运行。Metasploit 命令写入签名的临时资源文件——从不作为 CLI 字符串注入。Nmap 目标与参数在执行前通过 `ipaddress` 和元字符剥离进行验证。 4. **不可变审计**:每个审计事件都携带对上一条记录的 **HMAC-SHA256 链式链接**。篡改任何记录都会破坏链条。所有敏感文件以 `chmod 0o600` 写入。 5. **供应链完整性**:哈希锁定依赖项、自动化 SAST/密钥扫描,以及软件物料清单(`python main.py sbom`)。 ## 🛠️ 关键特性 * 🔴 **红队(渗透测试)**:使用 **Atomic Red Team** 库进行自主侦察、漏洞评估与利用。 * 🔵 **蓝队(防御者)**:实时日志分析、SIEM 风格遥测与主动修复(通过 iptables 阻断 IP,通过 SIGKILL 终止进程)。默认为模拟模式;通过 `BLUE_REMEDIATE_LIVE=1` 启用实时修复,并需 RBAC 令牌验证。 * 🟣 **紫队(模拟)**:协作式、迭代的攻击/防御循环(**持续混沌**),用于快速安全演练。 * 📺 **战情室仪表盘**:实时的 TUI 界面,提供 MITRE 热度图、发现结果、红/蓝队日志和活动跳转会话面板。 * 🧠 **自主自愈**:代理自动检测工具错误、反思原因并发出修正命令。 * 🕵️ **隐身模式(OPSEC)**:使用随机抖动和清单技术以规避检测。 * 🐝 **子网蜂群**:并行启动多个代理线程,同时扫描并评估整个 CIDR 范围。 * ⚖️ **风险/成功率引擎**:实时概率建模,评估利用成功率与检测风险。 * 🚨 **影子 Shell**:用于实时会话控制的人机战术交接。 * 🔐 **基于角色的访问控制(RBAC)**:硬件级身份验证与操作系统级权限强制执行。 * 🛑 **全局熔断开关**:允许操作员即时暂停或终止所有活跃代理的安全机制。 * 📡 **战略消息总线**:实现代理间实时通信与协调。 * ⚡ **精英效率**:内置 **语义缓存**(ChromaDB)与 **大规模输出自动压缩**,以降低 API 成本与延迟。 ## 📁 项目结构 ``` OpenElia/ ├── main.py # Main entry point for Python engine ├── orchestrator.py # Core orchestration logic ├── agents/ # AI agent implementations │ ├── base_agent.py # Base agent class │ ├── reporter_agent.py # Executive reporting, MITRE heatmap, chain of custody │ ├── blue/ # Defensive agents │ │ ├── defender_ana.py # Tier 2 LLM-based triage │ │ ├── defender_hunt.py # Proactive threat hunting │ │ ├── defender_mon.py # Tier 1 Sigma/regex monitoring │ │ ├── defender_os.py # Blue team orchestrator │ │ └── defender_res.py # Tier 4 containment & response │ └── red/ # Offensive agents │ ├── pentester_os.py # Red team phase orchestrator │ ├── pentester_recon.py# Reconnaissance phase │ ├── pentester_vuln.py # Vulnerability assessment │ ├── pentester_exploit.py # Exploitation phase │ ├── pentester_lat.py # Lateral movement phase │ └── pentester_ex.py # Exfiltration phase ├── adversaries/ # Adversary emulation profiles │ ├── apt29.json # APT29 TTPs │ └── fin7.json # FIN7 TTPs ├── artifacts/ # Generated artifacts and evidence ├── lab/ # Testing environment │ └── docker-compose.yml # Lab setup ├── mcp_servers/ # Model Context Protocol servers │ ├── atomic/ # Atomic Red Team integration │ ├── blue_remediate/ # Automated remediation │ ├── blue_telemetry/ # Telemetry collection │ ├── graph/ # Attack surface graph │ ├── memory/ # Long-term memory │ ├── pivot/ # Pivoting tools │ ├── red_recon/ # Reconnaissance │ ├── siem/ # SIEM integration │ ├── threat_intel/ # Threat intelligence │ └── vault/ # Secure credential storage ├── skills/ # Domain-specific skill modules ├── src/ # TypeScript CLI (project root) │ ├── src/ # TypeScript source files │ │ ├── cli.ts # CLI implementation │ │ └── index.ts # Entry point │ ├── dist/ # Compiled JavaScript output │ ├── package.json # Node.js dependencies │ └── tsconfig.json # TypeScript config ├── state/ # Persistent state and databases ├── requirements.txt # Python dependencies ├── pyproject.toml # Python project config ├── roe.json # Rules of Engagement ├── setup.sh & setup.ps1 # Installation scripts └── scrub.py # Data sanitization tool ``` ## 🏁 快速开始 ### 先决条件 - Docker(用于无菌执行) - Ollama(本地运行 `llama3.1:8b` 或类似模型) - Python 3.11+ - Node.js 18+(用于 TypeScript CLI) ### 安装 **Python 引擎(必需):** ``` # Clone the Repository git clone https://github.com/M3tan01/OpenElia.git cd OpenElia # Create and activate a virtual environment (required on Debian/Ubuntu) python3 -m venv .venv source .venv/bin/activate # Linux/macOS # .venv\Scripts\activate # Windows # Install Python dependencies pip install -r requirements.txt # Or install as editable package pip install -e . # Or use setup scripts (also handles venv creation) chmod +x setup.sh && ./setup.sh # Unix/macOS # .\setup.ps1 # Windows # Verify environment readiness python3 main.py check ``` **TypeScript CLI(可选但推荐):** ``` # Install TypeScript CLI cd src npm install npm run build npm link # Make globally available as 'openelia-cli' ``` **全局命令(可选):** ``` pip install . # Now you can use 'openelia' instead of 'python main.py' ``` ### 实验场(可选) 启动一个标准化的易受攻击实验环境以立即测试: ``` cd lab docker-compose up -d ``` ### 净化与合规 在推送前确保数据已清除,或生成取证工件: ``` # Purge all local state and artifacts python3 scrub.py # Package the entire engagement into a secure, hashed Case File python3 main.py archive # Note: On first run, a GUI prompt will ask you to set a password for the # OS keyring ("Choose password for new keyring"). Enter and confirm a password, # then click Continue. This keyring protects your API keys and vault encryption key. # Leave the password blank only if you are in a headless/server environment. # Generate Software Bill of Materials python3 main.py sbom ``` ### 用法 #### Python CLI(直接调用) ``` # Verify environment readiness python3 main.py check # Launch the interactive War Room TUI python3 main.py dashboard # Run a red team engagement (Single Target) python3 main.py red --target 10.10.10.50 --stealth # Run a parallel subnet swarm (CIDR Range) emulating APT29 python3 main.py red --target 10.10.10.0/29 --apt apt29 # Run a collaborative purple team loop (2 iterations) python3 main.py purple --target 10.10.10.50 --iterations 2 # Generate executive report with MITRE heatmap and chain of custody python3 main.py report python3 main.py report --brain-tier expensive # Execute an approved response action by its logged ID python3 main.py execute-remediation --action-id 42 ``` #### TypeScript CLI(增强用户体验) ``` # Interactive mode (recommended) openelia-cli # Direct commands openelia-cli red --target 10.10.10.50 --stealth openelia-cli blue --logs /var/log/auth.log openelia-cli purple --target 10.10.10.50 --iterations 3 openelia-cli nmap --target 10.10.10.50 openelia-cli msf --target 10.10.10.50 openelia-cli report openelia-cli report --task "Board-level summary" --brain-tier expensive openelia-cli execute-remediation --action-id 42 openelia-cli check openelia-cli status openelia-cli dashboard openelia-cli lock openelia-cli unlock openelia-cli archive openelia-cli sbom openelia-cli doctor # Switch agents in interactive mode openelia-cli interactive > agent Pentester > red --target 10.10.10.50 ``` #### 代理命令 ``` # Switch to Pentester agent /agent Pentester # Generate a final report with MITRE ATT&CK coverage /agent Reporter ``` ## 📜 交战规则 所有操作均受 `roe.json` 约束。范围验证器 **失败关闭**——如果 `roe.json` 缺失或 `authorized_subnets` 为空,所有目标将被阻止。 ``` { "authorized_subnets": ["10.10.10.0/24"], "blacklisted_ips": ["10.10.10.1", "10.10.10.254"] } ``` 所有传出流量将通过 **隐私卫士** 自动脱敏 PII。所有工具结果在重新进入模型上下文前均经过提示注入净化。 ## ⚙️ 必需配置 | 变量 / 文件 | 用途 | 缺失时的影响 | |-------------|------|--------------| | `roe.json` 含 `authorized_subnets` | 定义合法目标范围 | 所有操作被阻止 | | `SIEM_WEBHOOK_ALLOWLIST` | 逗号分隔的允许 SIEM 主机名 | 所有 Webhook 转发被阻止 | | `THEHIVE_URL` | TheHive 实例基础 URL | TheHive 案件调度被静默跳过 | | `THEHIVE_API_KEY` | TheHive API 密钥 | TheHive 案件调度被静默跳过 | | OS 密钥环凭据 | API 密钥、vault 加密密钥 | 首次运行时交互式提示 | | `BLUE_REMEDIATE_LIVE` | 设为 `1` 以启用实时 iptables/kill 执行 | 以安全模拟模式运行 | | `BLUE_REMEDIATE_RBAC_TOKEN` | RBAC 令牌环境变量(必须与密钥环值匹配) | 实时修复操作被拒绝 | ### SIEM Webhook 允许列表 在运行 SIEM MCP 服务器前设置: ``` export SIEM_WEBHOOK_ALLOWLIST="splunk.corp.com,siem.internal" ``` ### Vault 加密 通过 `store_credential` 存储的凭据将**自动使用 Fernet AES-256 加密**。密钥在首次使用时生成并存储在操作系统密钥环中,名称为 `VAULT_ENCRYPTION_KEY`。如果存在旧版明文 `state/vault.json`,将在首次加载时迁移并删除。 *免责声明:本工具仅用于授权的安全测试与研究目的。*
标签:5层安全架构, AES-256, AI安全, AI风险缓解, Chat Copilot, Docker沙箱, Fernet AES-256加密, FTP漏洞扫描, HMAC链式审计, HTTP/HTTPS抓包, IP验证, MCP, nmap验证, OS密钥链, payload净化, SAST, SBOM, SIEM集成, TGT, Web截图, 不可变审计, 主机名白名单, 内存密钥保护, 协议分析, 原子红队, 双防火墙, 安全开发生命周期, 安全编排, 实时威胁检测, 容器安全, 态势感知, 攻击模拟, 攻防演练, 敏感扫描, 数学防火墙, 数据展示, 无根容器, 权限提升, 漏洞评估, 盲注攻击, 硬件无关, 紫色团队, 红队, 网络防火墙, 自主AI, 自动化渗透, 语义防火墙, 请求拦截, 逆向工具, 防篡改日志, 零信任架构, 驱动签名利用