alexrepsec/incident-response-lab
GitHub: alexrepsec/incident-response-lab
一个基于 VMware 隔离网络构建的攻防模拟实验室,能够自动检测 SSH 暴力破解等真实攻击并执行证据收集、IP 封禁与报告生成的全流程事件响应。
Stars: 0 | Forks: 0
# 事件响应计划与执行实验室
一个功能齐全的家庭实验室,基于 VMware、Ubuntu Server 和 Kali Linux 构建,模拟真实世界的攻防场景。自动化检测引擎实时监控系统,一旦检测到攻击,便会触发多阶段响应:证据收集、IP 封禁和自动生成的事件报告——所有这些均无需人工干预。
## 实验室架构
```
┌─────────────────────────────────────┐ ┌──────────────────────────────────┐
│ VM1 — Defender │ │ VM2 — Attacker │
│ Ubuntu Server 22.04 │◄────│ Kali Linux │
│ 192.168.126.10 │ │ 192.168.126.129 │
│ │ │ │
│ ● auditd (kernel audit logging) │ │ ● nmap (reconnaissance) │
│ ● Fail2ban (adaptive IP banning) │ │ ● hydra (SSH brute force) │
│ ● UFW / iptables (host firewall) │ │ ● netcat (reverse shell sim) │
│ ● detect_incident.sh (engine) │ │ │
│ ● respond.sh (auto-response) │ │ │
│ ● Wazuh Agent (SIEM integration) │ │ │
└─────────────────────────────────────┘ └──────────────────────────────────┘
VMware VMnet1 — Host-Only Network (192.168.126.0/24)
```
## 工作原理
```
Attack (Kali) Detection (Ubuntu) Response (automated)
────────────── ────────────────── ────────────────────
hydra SSH BF ──► detect_incident.sh ──► Phase 1: Evidence
nmap scan ──► polls every 30s • network state
reverse shell ──► threshold reached • process list
alert written to • auth.log copy
alerts.json (JSON) • audit events
──► Phase 2: Containment
• iptables DROP
• UFW deny
• hosts.deny
──► Phase 3: Report
• Markdown report
• SHA256 hashes
```
## 涵盖场景
| # | 场景 | MITRE ATT&CK | 检测方法 | 自动化响应 |
|---|---|---|---|---|
| 1 | SSH 暴力破解 | T1110.001 | 失败认证阈值 ≥5 | 通过 iptables + UFW + hosts.deny 封禁 IP |
| 2 | 端口扫描 | T1046 | SYN flood 检测 | 速率限制 + 封禁源 IP |
| 3 | 反向 Shell | T1059.004 | 进程名模式匹配 | 终止进程 + 隔离二进制文件 |
| 4 | 权限提升 | T1548.001 | 新 SUID 二进制文件检测 | 终止会话 + 锁定文件 |
| 5 | 文件篡改 | T1565.001 | SHA256 哈希值更改 | chattr +i + 告警 |
## 实验室结果 — 捕获的真实攻击
### 攻击检测
检测引擎识别出来自 Kali (`192.168.126.129`) 的 SSH 暴力破解,并在一个轮询周期(30 秒)内触发了自动化响应流水线。

### IP 封禁 — iptables DROP 规则
来自攻击者 IP 的所有流量均通过 iptables 在内核级别丢弃,并通过 UFW 和 `/etc/hosts.deny` 应用了额外的封禁。

### 收集的证据
响应引擎在检测时刻捕获了完整的取证快照——网络状态、进程列表、认证日志、审计事件——全部经过 SHA256 哈希处理以保证证据保管链的完整性。

### 事件报告 — 自动生成
系统自动生成了结构化的 Markdown 事件报告,其中包含已采取的封禁措施、证据路径以及后续步骤建议。

## 告警格式 (JSON)
每次检测事件都会作为结构化 JSON 写入 `/opt/ir-lab/logs/alerts.json`,随时可导入 SIEM 或 TheHive:
```
{
"id": "ALERT-1783568272-14498",
"timestamp": "2026-07-09T03:37:52Z",
"severity": "HIGH",
"type": "SSH_BRUTEFORCE",
"message": "Brute force: 8 intentos desde 192.168.126.129",
"src_ip": "192.168.126.129",
"hostname": "ubuntu"
}
```
## 项目结构
```
incident-response-lab/
├── README.md
├── scripts/
│ ├── setup_environment.sh # Installs all tools on VM1 (one command)
│ ├── deploy_ir_scripts.sh # Deploys engine as systemd service
│ ├── ir_dashboard.sh # Live terminal dashboard
│ ├── detection/
│ │ └── detect_incident.sh # Detection engine (6 modules, 30s polling)
│ ├── response/
│ │ └── respond.sh # Evidence + containment + report
│ └── simulation/
│ └── attack_simulation.sh # 3-phase attack from VM2
├── playbooks/
│ ├── playbook-ssh-bruteforce.md # Runbook T1110.001
│ └── playbook-port-scan.md # Runbook T1046
└── configs/
└── wazuh_custom_rules.xml # 8 custom Wazuh detection rules
```
## 环境配置
### 前置条件
| 组件 | 规格 |
|---|---|
| 宿主机 OS | Windows 10/11 |
| Hypervisor | VMware Workstation 17+ |
| VM1 | Ubuntu Server 22.04 LTS — 2 vCPU, 2 GB 内存, 20 GB 磁盘 |
| VM2 | Kali Linux — 2 vCPU, 2 GB 内存, 20 GB 磁盘 |
| 网络 | 用于实验室隔离的 VMnet1 Host-Only (192.168.126.0/24) |
### VM1 — 防御者配置
```
# 克隆 repo
git clone https://github.com/alexrepsec/incident-response-lab.git
cd incident-response-lab
# 安装所有工具 (auditd, fail2ban, ufw, wazuh-agent, net-tools, tcpdump, jq)
sudo bash scripts/setup_environment.sh
# 将检测引擎部署为 systemd service
sudo bash scripts/deploy_ir_scripts.sh
# 验证 service 正在运行
sudo systemctl status ir-detection
# 实时监控
journalctl -u ir-detection -f
```
### VM2 — 攻击者配置
```
# Kali 已预装所有工具
# 验证与 VM1 的连接性
ping -c 3 192.168.126.10
# 发起 SSH 暴力破解攻击
hydra -l root -P /usr/share/wordlists/rockyou.txt 192.168.126.10 ssh -t 4 -V
```
## 证据结构
检测到事件后,工件会自动进行整理:
```
/opt/ir-lab/
├── evidence//
│ ├── network/
│ │ ├── listening_ports.txt # Open ports at incident time
│ │ ├── established_connections.txt # Active connections
│ │ ├── iptables_rules.txt # Firewall state
│ │ └── routing_table.txt
│ ├── processes/
│ │ ├── process_list.txt # Full ps auxef output
│ │ └── top_snapshot.txt
│ ├── system/
│ │ ├── auth.log # Authentication log copy
│ │ ├── audit_today.txt # auditd events
│ │ ├── last_logins.txt
│ │ └── current_users.txt
│ └── EVIDENCE_HASHES.txt # SHA256 of all artifacts
├── reports/
│ └── incident-report-.md # Auto-generated report
├── logs/
│ ├── alerts.json # Structured JSON alert feed
│ ├── detection.log # Human-readable detection log
│ ├── blocked_ips.txt # Audit trail of all IP blocks
│ └── response.log # Response action log
└── quarantine/ # Captured malicious binaries
```
## 工具与技术
| 工具 | 用途 |
|---|---|
| `auditd` | 内核级 syscall 监控和审计日志记录 |
| `Fail2ban` | 基于日志模式匹配的自适应 IP 封禁 |
| `UFW / iptables` | 基于主机的防火墙和实时 IP 封堵 |
| `Wazuh Agent` | 具有自定义检测规则的 SIEM 集成 |
| `Bash` | 检测引擎、响应自动化、证据收集 |
| `JSON` | 用于 SIEM 摄入的结构化告警格式 |
| `Python` (通过 auditd) | 日志解析和审计事件处理 |
| `tcpdump` | 证据收集期间的抓包 |
| `hydra` | SSH 暴力破解模拟(攻击者 VM) |
| `nmap` | 网络侦察模拟(攻击者 VM) |
| `tmux` | Ubuntu Server 上的多终端会话管理 |
| `sha256sum` | 证据完整性和证据保管链 |
## NIST 事件响应框架对齐
| 阶段 | 实现 |
|---|---|
| **准备阶段** | auditd 规则、Fail2ban 配置、UFW 基线、作为 systemd 服务的检测引擎 |
| **检测与分析** | `detect_incident.sh` — 基于阈值的检测、JSON 告警、30 秒轮询周期 |
| **封禁** | `respond.sh` — iptables DROP、UFW deny、hosts.deny、进程终止 |
| **根除** | 包含手动根除步骤和验证命令的 Playbook |
| **恢复** | 每个 Playbook 中的恢复检查清单 |
| **事后活动** | 自动生成的 Markdown 报告,包含时间线、证据和建议 |
## Playbook
| 文件 | 场景 | MITRE |
|---|---|---|
| `playbooks/playbook-ssh-bruteforce.md` | SSH 暴力破解 — 检测、封禁、恢复 | T1110.001 |
| `playbooks/playbook-port-scan.md` | 网络侦察 — 检测、封禁 | T1046 |
*我的网络安全作品集的一部分 — [alexrepsec](https://github.com/alexrepsec)*
标签:Homebrew安装, 安全实验环境, 库, 应急响应, 应用安全, 攻击模拟, 混合加密, 自动化响应, 蓝队防御, 驱动签名利用