diegoDrp-Dev/hydra-lab

GitHub: diegoDrp-Dev/hydra-lab

一个为验证 Hydra SOC Engine 而设计的本地攻击模拟实验室,提供四个故意存在漏洞的 Web 服务以测试安全检测规则和事件管道。

Stars: 0 | Forks: 0

# hydra-lab ![Educational Use Only](https://img.shields.io/badge/Educational-Use%20Only-yellow) ![Local Environment](https://img.shields.io/badge/Environment-Local%20Only-blue) ![License MIT](https://img.shields.io/badge/License-MIT-green) ## 什么是 hydra-lab? **hydra-lab** 是一个攻击模拟实验室,旨在验证 [Hydra](https://github.com/diegoDrp-Dev/hydra) 的 SOC (Security Operations Center) engine。 该仓库提供了 **4 个故意设计为存在漏洞的 web 服务**,涵盖了 Hydra 的所有主要检测规则,可用于测试和演示: - ✅ **规则覆盖率** — 每个服务都会触发一组特定的漏洞 - ✅ **风险评分** — 验证生成的分数是否准确 - ✅ **事件生成** — 检查完整的事件 pipeline 是否正常工作 - ✅ **演示** — 现场向利益相关者展示 Hydra 的模式 ## ⚠️ 安全警告 **切勿将这些服务暴露在公共网络或生产环境中。** 这是一个**仅限本地测试**的环境。所有服务都具有以下特点: - 故意设计为存在漏洞 - 没有任何安全防护 - 包含硬编码的凭证 - 不启用 TLS/HTTPS 仅在受控且隔离的环境中使用。 ## 前置条件 - **Node.js 18+**(用于本地运行) - **Docker & Docker Compose**(可选,用于容器化) - **npm** 或 **yarn** - 访问在本地运行的 **Hydra** 实例(默认:`http://localhost:3000`) ## 🎤 面试模式 要在技术面试中演示该系统: ``` # 1. 重置先前的数据以从零开始 npm run demo:reset # 2. 启动易受攻击的 targets(在单独的终端中) npm run start:all # 3. 启动完整的面试流程(Scan -> Brute Force -> Demo Loop) npm run interview # 4. 结束所有流程并清理数据(面试结束后) npm run lab:clean ``` 系统将每 2-7 秒扫描一次目标,在终端和 Hydra 的 dashboard 中生成持续的视觉流。 **展示内容:** 1. 并行处理事件的终端。 2. 实时更新的 Hydra 事件 stream。 3. 不同目标之间的严重性差异(端口 4000 vs 4003)。 ## 🚀 如何启动 ### 选项 1:本地运行(推荐用于开发) ``` # Clone 仓库 git clone https://github.com/diegoDrp-Dev/hydra-lab.git cd hydra-lab # 安装依赖项 npm install # 复制 .env.example 文件到 .env 并配置其值 cp .env.example .env # 编辑 .env 并填入您的 HYDRA_TOKEN # 启动所有 4 个易受攻击的服务 npm run start:all ``` 你将在输出中看到: ``` 🚨 INSECURE-API listening on http://localhost:4000 🌐 VULNERABLE-WEB listening on http://localhost:4001 🔓 FAKE-LOGIN-ENDPOINT listening on http://localhost:4002 ⚠️ MIXED-HEADERS listening on http://localhost:4003 ``` ### 选项 2:在 Docker 中运行 ``` # 启动 containers npm run docker:up # 查看实时日志 npm run docker:logs # 停止 containers npm run docker:down ``` ## 🎬 现场演示模式 要以可视化且实时的方式展示 Hydra 检测漏洞: ``` # 运行连续的 demo 循环(每 3 分钟扫描一次) npm run demo ``` ### 预期行为: ``` ╔════════════════════════════════════════════════════════════════════════════════╗ ║ 🐉 HYDRA-LAB DEMO — LIVE SCANNING ║ ║ ║ ║ Targets: insecure-api | vulnerable-web | fake-login | mixed-headers ║ ║ Scan Interval: Every 3 minutes ║ ║ Press Ctrl+C to stop ║ ╚════════════════════════════════════════════════════════════════════════════════╝ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ⏰ Scan Cycle #1 — 2024-12-04T18:30:00.000Z ● insecure-api │ PORT 4000 │ Score: 92/100 │ 🔴 CRITICAL └─ Rules: missing_csp, missing_hsts, missing_x_frame_options +4 more ● vulnerable-web │ PORT 4001 │ Score: 68/100 │ 🟠 HIGH └─ Rules: missing_csp, exposed_admin_panel, missing_hsts ● fake-login │ PORT 4002 │ Score: 55/100 │ 🟠 HIGH └─ Rules: weak_authentication, http_only ● mixed-headers │ PORT 4003 │ Score: 28/100 │ 🟡 MEDIUM └─ Rules: missing_csp, missing_content_type_options ``` **按严重程度划分的颜色:** - 🟢 **GREEN** — LOW (20-35 score) - 🟡 **YELLOW** — MEDIUM (36-50 score) - 🟠 **ORANGE** — HIGH (51-75 score) - 🔴 **RED** — CRITICAL (76-100 score) ## 📋 可用目标 | 服务 | 端口 | 漏洞 | |-------------------|-------|-------------------------------------------------------------------------| | **insecure-api** | 4000 | missing_csp, missing_hsts, missing_x_frame_options, | | | | missing_content_type_options, http_only, slow_response | | **vulnerable-web**| 4001 | missing_csp, missing_hsts, exposed_admin_panel | | **fake-login** | 4002 | weak_authentication, http_only | | **mixed-headers** | 4003 | missing_csp, missing_content_type_options | ## 🎯 Risk Engine 覆盖范围 | 规则 | 触发位置 | 描述 | |------------------------------|----------------------------|------------------------------------------------------| | **missing_csp** | 4000, 4001, 4003 | 缺少 Content-Security-Policy header | | **missing_hsts** | 4000, 4001, 4002 | 缺少 Strict-Transport-Security header | | **missing_x_frame_options** | 4000, 4002 | 缺少 X-Frame-Options (clickjacking) | | **missing_content_type_options** | 4000, 4003 | 缺少 X-Content-Type-Options (MIME sniffing) | | **http_only** | 4000, 4002 | 缺少 HTTPS/TLS enforcement | | **slow_response** | 4000 | 故意设置 3-8 秒延迟的 endpoint | | **exposed_admin_panel** | 4001 | /admin 未经身份验证即返回敏感数据 | | **weak_authentication** | 4002 | 硬编码凭证:admin/password | ## 📡 运行扫描 ### 对所有目标进行单次扫描 ``` npm run scan ``` 预期输出: ``` ================================================================================ 🐉 HYDRA-LAB SCAN EXECUTION ================================================================================ ⏰ Started at: 2024-12-04T18:25:30.000Z 🔗 Hydra API: http://localhost:3000 🎯 Targets: 4 🔍 Scanning insecure-api (http://localhost:4000)... 🔍 Scanning vulnerable-web (http://localhost:4001)... 🔍 Scanning fake-login (http://localhost:4002)... 🔍 Scanning mixed-headers (http://localhost:4003)... ================================================================================ 📊 SCAN RESULTS ================================================================================ │ insecure-api │ 4000 │ 92 │ CRITICAL │ missing_csp, missing_hsts... │ │ vulnerable-web │ 4001 │ 68 │ HIGH │ missing_csp, exposed_admin... │ │ fake-login │ 4002 │ 55 │ HIGH │ weak_authentication, http... │ │ mixed-headers │ 4003 │ 28 │ MEDIUM │ missing_csp, missing_conte... │ ``` ### 模拟 Brute Force 攻击 ``` npm run brute ``` 预期输出: ``` ================================================================================ 🔓 BRUTE FORCE SIMULATION ================================================================================ ⏰ Started at: 2024-12-04T18:26:00.000Z 🎯 Target: http://localhost:4002/login 👤 Username: admin 🔑 Password list: 20 common passwords 🚀 Attempting passwords... [01/20] ✗ failed password="admin" (12ms) [02/20] ✗ failed password="123456" (11ms) [03/20] ✗ failed password="password" (10ms) ✓ SUCCESS ... ================================================================================ 📊 BRUTE FORCE RESULTS ================================================================================ 🎯 SUCCESSFUL PASSWORD CRACKED: "password" Time to compromise: 3 attempts 📈 ATTACK METRICS: Total attempts: 20 Avg response time: 11ms Max response time: 15ms Min response time: 9ms 🚨 VULNERABILITIES EXPOSED: ✗ No rate limiting — all 20 attempts succeeded instantly ✗ No account lockout — no protection after failed attempts ✗ Consistent response time — no timing variation ✗ No CAPTCHA — no challenge protection ✗ No 2FA — weak authentication ``` ## 🏗️ 技术细节 ### insecure-api (端口 4000) **Endpoints:** - `GET /api/public-data` — 返回暴露的凭证 - `POST /api/login` — 无 rate limiting 的登录 - `GET /api/slow` — 故意设置 3-8 秒延迟 - `GET /api/raw` — 不带 Content-Type header 的响应 **漏洞:** - 没有任何安全 header - 公共 endpoint 包含凭证 - 没有 brute force 防护 - 没有 HTTPS ### vulnerable-web (端口 4001) **Endpoints:** - `GET /` — 不带 CSP 的 HTML - `GET /admin` — 未受保护的 admin panel - `GET /debug` — 泄露 environment variables **漏洞:** - 因缺少 CSP 导致的 XSS - 信息泄露 - 未经身份验证即可访问敏感数据 ### fake-login-endpoint (端口 4002) **Endpoints:** - `POST /login` — username: "admin", password: "password" - `GET /status` — 服务状态 **漏洞:** - 硬编码凭证 - 针对暴力破解无 rate limiting - 无账户保护 - 所有响应均返回 HTTP 200 ### mixed-headers (端口 4003) **Endpoints:** - `GET /` — 带有部分 header 的 HTML - `GET /partial` — 演示部分实现 - `GET /status` — 服务状态 **已实现:** - ✓ HSTS header - ✓ X-Frame-Options header **缺失:** - ✗ CSP header - ✗ X-Content-Type-Options header ## 📊 预期结果 ### Risk Scores | 目标 | Score | 严重性 | 原因 | |-------------------|-------|------------|------------------------------------------------| | insecure-api | 85-95 | 🔴 CRITICAL | 包含所有漏洞 + slow_response | | vulnerable-web | 60-75 | 🟠 HIGH | 缺少多个 header + exposed_admin | | fake-login | 50-65 | 🟠 HIGH | weak_authentication + http_only | | mixed-headers | 20-35 | 🟡 MEDIUM | 安全配置为部分实现 | ## 🔧 .env 配置 复制 `.env.example` 来创建一个 `.env` 文件: ``` cp .env.example .env ``` 修改这些值: ``` # Hydra 的 API URL(您的本地 endpoint) HYDRA_API_URL=http://localhost:3000 # 从 Hydra 身份验证获取的 JWT Token HYDRA_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... # (可选)启用详细 logging DEBUG=false ``` 要获取你的 `HYDRA_TOKEN`,请在 Hydra 中进行身份验证: ``` curl -X POST http://localhost:3000/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"seu@email.com","password":"sua_senha"}' ``` ## 🐳 Docker 化 ### 单独构建 ``` # 构建特定 target 的镜像 docker build -f Dockerfile.insecure-api -t hydra-lab-insecure-api . # 运行 container docker run -p 4000:4000 hydra-lab-insecure-api ``` ### Docker Compose ``` # 启动所有 4 个服务 docker-compose up -d # 停止所有服务 docker-compose down # 查看日志 docker-compose logs -f # 清理 volumes docker-compose down -v ``` ## 📖 文件结构 ``` hydra-lab/ ├── targets/ │ ├── insecure-api.ts # Port 4000: Sem nenhuma proteção │ ├── vulnerable-web.ts # Port 4001: Admin exposed │ ├── fake-login-endpoint.ts # Port 4002: Brute force │ └── mixed-headers.ts # Port 4003: Parcial ├── scripts/ │ ├── run-all-scans.ts # Escaneia todos os alvos │ ├── brute-force-sim.ts # Simula brute force │ └── demo-loop.ts # Demo contínua a cada 3 min ├── docker-compose.yml # Orquestração de containers ├── Dockerfile.* # 4 Dockerfiles individuais ├── package.json # Dependências Node.js ├── tsconfig.json # Configuração TypeScript ├── .env.example # Modelo de variáveis de ambiente ├── .gitignore # Arquivos ignorados por Git └── README.md # Este arquivo ``` ## 🎓 用例:演示 此仓库非常适合用于: 1. **覆盖率验证** — 检查 Hydra 是否能检测到所有规则 2. **展示** — 现场演示 SOC engine 的运行情况 3. **培训** — 教授安全和扫描的概念 4. **原型设计** — 快速测试新的检测规则 5. **CI/CD** — Hydra 的自动化集成测试 ## 🚨 已记录的漏洞 每个服务都包含内联注释,解释了每个漏洞存在的**原因**以及它会触发 Hydra 的哪条规则。 示例: ``` /** * VULNERABILITY: No rate limiting — brute force attacks possible * Hydra Rule: weak_authentication * Impact: Attacker can guess passwords without consequence */ ``` ## 📈 支持的指标 Hydra 应当检测并记录以下内容: - ✅ Risk scores (0-100) - ✅ 严重性 (low/medium/high/critical) - ✅ 违反的规则 - ✅ 缺失的 Headers - ✅ 攻击模式 (brute force) - ✅ 暴露的 endpoints - ✅ 异常的响应时间 ## 🔗 相关项目 → **[Hydra SOC Engine](https://github.com/diegoDrp-Dev/hydra)** — 安全事件检测与响应平台 ## 📝 许可证 MIT — 详情请参阅 LICENSE ## 👤 作者 **Diego Rodrigues Pereira** Security Engineer | Backend Developer [![LinkedIn](https://img.shields.io/badge/LinkedIn-diego--rodrigues--pereira-0077b5?style=flat&logo=linkedin)](https://www.linkedin.com/in/diego-rodrigues-pereira-drp/) [![GitHub](https://img.shields.io/badge/GitHub-diegoDrp--Dev-181717?style=flat&logo=github)](https://github.com/diegoDrp-Dev) ## ⚖️ 免责声明 本项目按 **"原样" (AS IS)** 提供,仅供教育和测试目的使用。 - **请勿在生产环境中使用** - **请勿暴露在公共网络中** - **仅在受控环境中使用** - **请遵守当地的安全法律** ## 💬 支持 如有任何问题或建议,请在 GitHub 上提出 issue 或与我们联系。 **出于 ❤️ 为验证安全而生**
标签:Docker, GNU通用公共许可证, MITM代理, Node.js, 安全运营, 安全防御评估, 安全靶场, 扫描框架, 插件系统, 攻击模拟, 暗色界面, 漏洞环境, 版权保护, 自动化攻击, 请求拦截, 驱动签名利用