juanjoloq/Cyber_agent

GitHub: juanjoloq/Cyber_agent

一个基于 LLM 的多智能体网络安全系统,在隔离的 Docker 实验室中自动化执行侦察、渗透测试、加固及报告生成。

Stars: 3 | Forks: 0

# 🛡️ Cyber Agent ![Python](https://img.shields.io/badge/Python-3.11+-blue) ![Docker](https://img.shields.io/badge/Docker-Required%20for%20Lab-blue) ![Status](https://img.shields.io/badge/status-active-success) ![License](https://img.shields.io/badge/license-MIT-green) ## 📌 描述 **Cyber Agent** 是一个自主系统,它可以: * 分析目标(IP、域名或网络) * 执行侦察和渗透测试 pipeline * 利用 LLM 进行智能分析 * 生成 `.md` 和 `.html` 格式的技术报告 * 允许渐进式测试(无需工具 → 完整实验室) ## 🧠 总体架构 ``` ┌─────────────────────┐ │ CLI │ │ main.py │ └─────────┬───────────┘ │ ┌────────▼────────┐ │ AGENT CORE │ │ (Planner + LLM) │ └────────┬────────┘ │ ┌─────────────────┼─────────────────┐ │ │ │ ┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐ │ OSINT │ │ Pentesting │ │ Hardening │ │ dns/subdom │ │ nmap/vuln │ │ CVE/patch │ └─────────────┘ └─────────────┘ └─────────────┘ │ ┌────────▼────────┐ │ REPORTING │ │ MD + HTML │ └─────────────────┘ ``` # 🚀 安装(初始设置) ``` cd cyber_agent pip install -r requirements.txt cp .env.example .env ``` 使用你的凭据编辑 `.env`: ### 选项 A — Enterprise ``` DEFAULT_LLM_PROVIDER=enterprise ENTERPRISE_AI_URL=https://tu-servidor/api/chat/completions ENTERPRISE_AI_KEY=tu-key ENTERPRISE_AI_EMAIL=tu@email.com ENTERPRISE_MODEL=innti-dev ``` ### 选项 B — Anthropic ``` DEFAULT_LLM_PROVIDER=anthropic ANTHROPIC_API_KEY=sk-ant-... ``` # 🧪 如何测试该代理 系统具有 **3 个渐进式测试级别**: ## 🟢 级别 1 — 无需 Docker,无需工具(5 分钟) 验证: * 代理是否加载 * LLM 是否响应 * pipeline 是否正常运行 ### ▶️ Dry Run(全模拟) ``` python main.py --target 192.168.1.1 --mode recon --dry-run ``` 预期输出: ``` [→] Plan: 4 pasos — modo recon [DRY RUN] port_scan simulado [DRY RUN] dns_enum simulado ``` ### ▶️ 使用 LLM 进行侦察(不使用 nmap) ``` python main.py --target 192.168.1.1 --mode recon ``` * LLM 模拟侦察过程 * 生成报告于: ``` reports/output// ``` ### ▶️ 交互模式 ``` python main.py ``` ## 🟡 级别 2 — 使用 nmap(受控的真实环境) 验证: * 真实的 pipeline * 与工具的集成 ### 安装 nmap ``` # Windows https://nmap.org/download.html#windows # 1. Instala el nmap-version-setup.exe # 2. Reinicia tu terminal y Verifica # Linux sudo apt install nmap # macOS brew install nmap # 验证 nmap --version ``` ### ▶️ 基础扫描 ``` python main.py --target 192.168.1.1 --mode recon ``` ### ▶️ 完整 pipeline ``` python main.py --target 192.168.1.50 --mode full ``` 执行 pipeline: ``` 1. sandbox_setup 2. dns_enum 3. subdomain_finder 4. port_scan ← nmap real 5. vuln_analysis 6. exploit_research 7. hardening ``` ### ▶️ 查看报告 ``` ls reports/output/ cat reports/output//report_.md ``` 打开 HTML: ``` xdg-open reports/output//report_.html ``` ### ▶️ 恢复会话 ``` python main.py --session --mode report ``` ## 🔴 级别 3 — 使用 Docker 的完整实验室 验证: * 真实的脆弱性环境 * 代理的完整执行 ### 前置条件 ``` docker --version docker compose version ``` ### 构建镜像 ``` docker build -f infrastructure/Dockerfile.target -t cyberagent/target-lab . docker build -f infrastructure/Dockerfile.kali -t cyberagent/kali-tools . ``` ### 启动实验室 ``` docker compose -f infrastructure/docker-compose.yml up -d ``` 验证: ``` docker compose ps ``` ### 手动测试目标 ``` docker exec -it cyberagent_attacker bash nmap -sV 172.20.0.3 curl http://172.20.0.3/dvwa/ ``` ### 针对实验室运行代理 ``` python main.py --target 172.20.0.3 --mode full --scope 172.20.0.0/24 ``` ### 销毁实验室 ``` docker compose down -v ``` # 🧩 使用模式 ## 侦察 (Recon) ``` python main.py --target example.com --mode recon python main.py --target IP --mode full ``` ## 全量 (Full) ``` python main.py --target example.com --mode full python main.py --target IP --mode full ``` ## 代码扫描 (Code Scan) ``` # 运行代码分析的三种有效方式: # 使用 target "local" python main.py --target local --code-scan "D:\DESARROLLOS\ModuloDePreguntasCapacitaciónTI" --mode code # 不使用 target — 自动分配给 localhost python main.py --code-scan "D:\DESARROLLOS\ModuloDePreguntasCapacitaciónTI" --mode code # 显式使用 target localhost python main.py --target localhost --code-scan "D:\DESARROLLOS\ModuloDePreguntasCapacitaciónTI" --mode code ``` 检测: * SQL Injection * 硬编码密钥 * 不安全的 JWT * SSRF / XXE * 易受攻击的依赖项 ## 加固 (hardening) ``` # 针对你的网络进行完整模式 python main.py --target 192.168.1.1 --mode full # 仅 hardening(现有会话报告) python main.py --target 192.168.1.1 --mode report --session # 针对 Docker lab(将发现无 auth 的 Redis、无 pass 的 MySQL、root:toor 的 SSH) python main.py --target 172.20.0.3 --mode full ``` ## 清理 (Cleanup) — 销毁实验室 ``` # 销毁所有 containers 和 networks docker compose -f infrastructure/docker-compose.yml down -v # 验证没有留下孤立的 resources docker ps -a | grep cyberagent docker network ls | grep cyberagent # 如果留下了来自 agent 的孤立 resources(而非来自 compose): docker rm -f $(docker ps -aq --filter name=cyberagent) 2>/dev/null docker network rm $(docker network ls -q --filter name=cyberagent) 2>/dev/null ``` # ⚙️ 可用参数 ``` --target IP/DOMINIO --scope IP [IP ...] --mode recon|full|report|code --session ID --llm anthropic|enterprise --code-scan RUTA --dry-run ``` # 📁 输出结构 ``` reports/output// ├── report_.md ├── report_.html └── evidencias/ memory/ └── .json ``` # 🐞 调试 ``` DEBUG=true python main.py --target 192.168.1.1 --mode recon ``` 查看内存: ``` cat memory/.json | python -m json.tool ``` # ⚠️ 常见问题 | 错误 | 原因 | 解决方案 | | --------------------- | ------------------- | --------------------------------- | | `.env no configurado` | 缺少配置 | `cp .env.example .env` | | `nmap no instalado` | 缺少工具 | 安装 nmap | | `ModuleNotFoundError` | 依赖项问题 | `pip install -r requirements.txt` | | `Docker healthcheck` | 启动缓慢 | 等待 30 秒 | | `HIGH_FAILURE_RATE` | pipeline 失败 | 启用 DEBUG 模式 | # ⚠️ 法律声明 * 仅对自有或已获授权的系统执行操作 * 未经允许,请勿扫描第三方基础设施 * 仅供教育和受控环境下使用 # 代理主体结构 ``` cyber_agent/ │ ├── main.py # Entrypoint — CLI / FastAPI ├── .env # Configuración y API keys ├── .env.example ├── pyproject.toml │ ├── agent/ # Núcleo del orquestador principal │ ├── core.py # Orquestador — ejecuta el pipeline │ ├── router.py # Planner — decide qué activar │ ├── scope_guard.py # Valida acciones dentro del scope │ │ │ └── personalities/ # Personalidades del agente │ ├── __init__.py │ ├── base.py # Tono base compartido │ ├── orchestrator.py # "Coordina, no ejecutes" │ ├── analyst.py # Análisis técnico + CVSS │ └── reporter.py # Generación de reportes │ ├── skills/ # Capacidades del agente principal │ ├── recon/ │ │ ├── SKILL.md # Carga SKILL.md + llama al LLM │ │ └── recon.py # Cuándo activar + qué retornar │ │ │ ├── vuln_analysis/ │ │ ├── SKILL.md │ │ └── vuln_analysis.py │ │ │ ├── exploit_research/ │ │ ├── SKILL.md │ │ └── exploit_research.py │ │ │ └── remediation/ │ ├── SKILL.md │ └── remediation.py │ ├── subagents/ # Agentes especializados con pipeline propio │ │ ├── pentest/ # Subagente de pentesting activo │ │ ├── core.py │ │ ├── router.py │ │ ├── personalities/ │ │ │ └── __init__.py │ │ └── skills/ │ │ ├── port_scan/ │ │ │ ├── SKILL.md │ │ │ └── port_scan.py │ │ ├── vuln_scan/ │ │ │ ├── SKILL.md │ │ │ └── vuln_scan.py │ │ └── exploit/ │ │ ├── SKILL.md │ │ └── exploit.py │ │ ├── osint/ # Subagente de reconocimiento pasivo │ │ ├── core.py │ │ ├── router.py │ │ ├── personalities/ │ │ │ └── __init__.py │ │ └── skills/ │ │ ├── dns_enum/ │ │ │ ├── SKILL.md │ │ │ └── dns_enum.py │ │ ├── subdomain_finder/ │ │ │ ├── SKILL.md │ │ │ └── subdomain_finder.py │ │ └── metadata_extractor/ │ │ ├── SKILL.md │ │ └── metadata_extractor.py │ │ ├── hacking_tools/ # Subagente de herramientas especializadas │ │ ├── core.py │ │ ├── router.py │ │ ├── personalities/ │ │ │ └── __init__.py │ │ └── skills/ │ │ ├── web_attack/ │ │ │ ├── SKILL.md │ │ │ └── web_attack.py │ │ ├── brute_force/ │ │ │ ├── SKILL.md │ │ │ └── brute_force.py │ │ └── payload_gen/ │ │ ├── SKILL.md │ │ └── payload_gen.py │ │ ├── docker_env/ # Subagente de entornos y sandboxing │ │ ├── core.py │ │ ├── router.py │ │ ├── personalities/ │ │ │ └── __init__.py │ │ └── skills/ │ │ ├── sandbox_setup/ │ │ │ ├── SKILL.md │ │ │ └── sandbox_setup.py │ │ ├── network_isolation/ │ │ │ ├── SKILL.md │ │ │ └── network_isolation.py │ │ └── lab_manager/ │ │ ├── SKILL.md │ │ └── lab_manager.py │ │ ├── forensics/ # Subagente de análisis forense │ │ ├── core.py │ │ ├── router.py │ │ ├── personalities/ │ │ │ └── __init__.py │ │ └── skills/ │ │ ├── traffic_analysis/ │ │ │ ├── SKILL.md │ │ │ └── traffic_analysis.py │ │ ├── log_parser/ │ │ │ ├── SKILL.md │ │ │ └── log_parser.py │ │ └── artifact_extractor/ │ │ ├── SKILL.md │ │ └── artifact_extractor.py │ │ └── hardening/ # Subagente de remediación y hardening │ ├── core.py │ ├── router.py │ ├── personalities/ │ │ └── __init__.py │ └── skills/ │ ├── patch_advisor/ │ │ ├── SKILL.md │ │ └── patch_advisor.py │ ├── config_hardener/ │ │ ├── SKILL.md │ │ └── config_hardener.py │ └── cve_lookup/ │ ├── SKILL.md │ └── cve_lookup.py │ ├── audit/ # Pipeline interno — siempre corre tras cada sesión │ ├── scanner.py # Valida scope, detecta acciones fuera de límites │ └── reporter.py # Reporte final consolidado (1 llamada LLM) │ ├── tools/ # Código determinista (sin LLM) │ ├── nmap_runner.py # Ejecuta nmap, retorna JSON estructurado │ ├── docker_manager.py # Crea/destruye contenedores y redes │ ├── file_manager.py # Leer/escribir evidencias y outputs │ ├── diff_parser.py # Parsea diffs de configuraciones │ └── report_builder.py # Ensambla el reporte final en markdown/PDF │ ├── infrastructure/ # Dockerfiles e imágenes base │ ├── Dockerfile.kali # Imagen con todas las herramientas preinstaladas │ ├── Dockerfile.target # Target vulnerable para labs internos │ └── docker-compose.yml │ ├── services/ │ ├── llm/ │ │ └── factory.py # Cliente LLM │ ├── memory.py # Persistencia de sesiones │ └── context.py # Contexto para skills │ ├── config/ │ └── settings.py # Configuración global │ ├── memory/ # Sesiones guardadas │ └── session_example.json │ └── tests/ ├── unit/ ├── integration/ └── labs/ ├── dvwa_lab.py └── metasploitable_lab.py ```
标签:Docker, GitHub, PyRIT, 人工智能, 多智能体系统, 安全防御评估, 实时处理, 对称加密, 插件系统, 用户模式Hook绕过, 网络安全, 网页分析工具, 自动化审计, 请求拦截, 逆向工具, 隐私保护