Engrossed-Riposte/cloud-malware-lab-v2
GitHub: Engrossed-Riposte/cloud-malware-lab-v2
基于 Azure 和 Terraform 构建的自动化恶意软件分析云沙箱,结合 Splunk 检测管线与 Gemini AI 日志分析,实现威胁告警的自动推送。
Stars: 0 | Forks: 0
# 云端恶意软件实验室
一个自动化的、基于 **Azure 的恶意软件分析沙箱**,通过 Terraform 进行配置。部署一台配备了 Sysmon 和 Splunk Universal Forwarder 的 Windows 受害机,同时部署一台运行 AI 驱动(Google Gemini)日志分析 agent 的 Linux 分析师 VM,该 agent 通过 webhook 将威胁评估结果发布到 Slack 或 Discord。所有 VM 均完全私有 —— 仅能通过 **Azure Bastion** 进行访问。
## 架构
```
┌───────────────────────────────────────────────────────────┐
│ Azure Resource Group │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌────────────────┐ │
│ │ Azure │ │ Windows VM │ │ Linux VM │ │
│ │ Bastion │ │ (Victim) │ │ (Analyst) │ │
│ │ (Public IP) │ │ │ │ │ │
│ │ │◄─│ • Win 2022 │ │ • Ubuntu 22.04│ │
│ └──────┬───────┘ │ • Sysmon │ │ • Splunk UF │ │
│ │ │ • Splunk UF│ │ • AI Agent │ │
│ │ └──────┬─────┘ └──────┬─────────┘ │
│ │ │ logs │ logs │
│ │ └──────┬────────┘ │
│ │ │ │
│ │ ┌────────▼─────────┐ │
│ │ │ Slack / Discord │ │
│ │ │ (Webhook Alerts) │ │
│ │ └──────────────────┘ │
│ │ │
│ Internet ──► (RDP / SSH / Splunk Web UI) │
└───────────────────────────────────────────────────────────┘
```
### 创建的资源
| 资源 | 名称 | 用途 |
|---|---|---|
| Resource Group | `rg-prod-ai-sandbox-01` | 所有实验室资源的容器 |
| Virtual Network | `vnet-sandbox` | 隔离的 `10.0.0.0/16` 网络 |
| Subnet | `subnet-sandbox` | `10.0.1.0/24` 工作负载子网(VM 是私有的 —— 无公共 IP) |
| Bastion Subnet | `AzureBastionSubnet` | `10.0.1.128/26` 专用 Bastion 子网 |
| NSG | `nsg-sandbox` | 仅将入站流量锁定在 Bastion 子网地址空间内 |
| Azure Bastion | `bastion-sandbox` | 安全的 RDP/SSH 网关(无直接 VM 访问) |
| Windows VM | `vm-malware-vic` | 恶意软件受害机(Windows Server 2022) |
| Linux VM | `vm-analyst` | 分析师工作站(Ubuntu 22.04) |
| Public IP | `pip-bastion` | 专用于 Azure Bastion 的单一静态 IP |
### NSG 规则
| 端口 | 方向 | 源 | 用途 |
|---|---|---|---|
| 22 | Inbound | 仅 Bastion 子网 | SSH 连接至分析师 VM |
| 3389 | Inbound | 仅 Bastion 子网 | RDP 连接至受害 VM |
| 8000 | Inbound | 仅 Bastion 子网 | Splunk Web UI |
| 9997 | Inbound | VNet 子网 | Splunk forwarder 流量 |
| All | Outbound | 任意 | 用于更新的 Internet 访问 |
## 前置条件
| 要求 | 版本 | 备注 |
|---|---|---|
| **Terraform** | >= 1.6.0 | [在此下载](https://developer.hashicorp.com/terraform/downloads) |
| **Azure CLI** | 最新版 | [安装指南](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) |
| **Azure Account** | 有效订阅 | 必须具有 Contributor 或 Owner 角色 |
| **Google Gemini API Key** | — | 在 [aistudio.google.com](https://aistudio.google.com/apikey) 获取 |
| **Slack 或 Discord Webhook** | — | 用于交付 AI 生成的告警 |
## 快速开始
### 1. 克隆仓库
```
git clone https://github.com//cloud-malware-lab-v2.git
cd cloud-malware-lab-v2
```
### 2. 认证至 Azure
```
az login
az account set --subscription ""
```
### 3. 配置变量
复制示例文件并填入您的值:
```
cp terraform.tfvars.example terraform.tfvars
```
然后编辑 `terraform.tfvars`:
```
admin_password = "YourStr0ngP@ssw0rd!" # Used for both VMs
gemini_api_key = "" # Google Gemini API key
webhook_url = "https://..." # Slack or Discord webhook URL
location = "centralus" # Azure region (optional)
vm_size = "Standard_D2_v3" # VM size (optional)
```
### 4. 初始化与部署
```
# 下载 Azure provider plugin
terraform init
# 查看将要创建的内容
terraform plan
# 应用配置
terraform apply
```
Terraform 将配置 VNet、NSG、Azure Bastion 以及两台 VM。Windows VM 将通过自定义脚本扩展自动安装 **Sysmon** 和 **Splunk Universal Forwarder**。Linux VM 将通过 cloud-init 安装 **Splunk**、**Python 依赖项**以及 **AI 分析 agent**。
### 5. 连接到您的 VM
部署完成后,获取 Bastion IP:
```
terraform output -raw bastion_ip
```
然后通过 **Azure Portal** 进行安全连接:
1. 导航到 **vm-malware-vic** 或 **vm-analyst** VM 边栏选项卡。
2. 点击 **Connect** → **Azure Bastion** → **bastion-sandbox**。
3. 对于 Windows VM,使用 **RDP** 连接,用户名为 `victimadmin`。
4. 对于 Linux VM,使用 **SSH** 连接,用户名为 `azureuser`。
### 6. 验证 AI Agent 是否正在运行
通过 Azure Bastion 连接到分析师 VM 并检查:
```
sudo tail -f /var/log/ai_agent.log
```
您应该会看到定期分析结果发布到您配置的 webhook 中。
## 文件结构
```
.
├── main.tf # Resource group, VNet, subnets
├── variables.tf # Input variable definitions
├── providers.tf # Azure provider configuration
├── versions.tf # Terraform and provider version constraints
├── bastion.tf # Azure Bastion host, Bastion subnet, NSG
├── windows.tf # Windows victim VM + Sysmon/Splunk auto-install
├── linux-vm.tf # Linux analyst VM + Splunk + AI agent cloud-init
├── terraform.tfvars # Your sensitive variables (gitignored)
└── README.md # This file
```
## 销毁
当不再需要该实验室时,销毁所有资源:
```
terraform destroy
```
这将删除资源组及其中的所有内容,并停止所有相关的 Azure 计费。
## 成本估算
默认配置(`Standard_D2_v3` VM,常开状态)的每月估算成本:
| 资源 | 估算成本/月 |
|---|---|
| Windows Server 2022 VM (D2_v3) | ~$40-50 |
| Ubuntu 22.04 VM (D2_v3) | ~$25-35 |
| Azure Bastion (Standard) | ~$10-15 |
| Public IP (Standard, 1x) | ~$1.80 |
| OS Disks (Standard_LRS) | ~$5 |
| **总计** | **~$85-105/月** |
## 故障排除
| 问题 | 解决方案 |
|---|---|
| `terraform plan` 因认证错误失败 | 运行 `az login` 并使用 `az account show` 验证您的订阅 |
| VM 无法启动 | 在 Azure portal 中检查 VM 错误状态;验证您的订阅是否支持 `Standard_D2_v3` |
| Bastion 连接失败 | 确保 Bastion 子网命名为 `AzureBastionSubnet` 并且 public IP 为 Standard SKU |
| AI agent 未发布告警 | 通过 Bastion 连接,检查 `/var/log/ai_agent.log`;验证 Gemini API key 和 webhook URL |
| Splunk Web UI 无法访问 | Splunk 监听 `8000` 端口;确保 NSG 规则允许来自 Bastion 子网的该端口;使用 `systemctl status splunkforwarder` 验证 Splunk 服务是否正在运行 |
## 许可证
本项目按“原样”提供,用于教育和研究目的。
标签:AI驱动分析, Azure, DAST, ECS, Sysmon, Terraform, 安全沙箱, 恶意软件分析, 逆向工具