PantelisTsagkas/modal-detonation-sandbox
GitHub: PantelisTsagkas/modal-detonation-sandbox
基于 Modal 无服务器平台的恶意样本隔离引爆沙箱,在临时云端 micro-VM 中执行可疑代码并自动生成行为与网络遥测分析报告。
Stars: 1 | Forks: 0
# Modal Detonation 沙箱
[](https://www.python.org/)
[](LICENSE)
[](https://modal.com/docs/guide/sandbox)
[](https://docs.astral.sh/uv/)
**在临时的云端沙箱中运行可疑代码 —— 绝不在您的本机上运行。**
上传样本 → 在隔离的 Modal micro-VM 中触发(detonate) → 捕获行为、网络活动和 artifacts → 销毁环境。专为**安全研究、教育和威胁分析原型设计**而构建。
## 功能
| | |
|---|---|
| 🛡️ **隔离执行** | Payload 在远程、临时的 micro-VM 中运行 —— 而非您的主机上 |
| 📡 **网络遥测** | `strace` 捕获出站 `connect` / `sendto` 系统调用 |
| 📂 **Artifact 收集** | 从 `/tmp` 和 `/root` 中提取下载文件和释放的文件 |
| 📋 **JSON 报告** | SHA-256、退出代码、计时、沙箱 ID —— 支持 SIEM |
| 🧩 **多格式支持** | 自动检测 Python、shell 和原生二进制文件 |
| 💸 **缩容至零** | 无需常驻 VM。每次运行后沙箱均会终止 |
### 三个可观测性层级
```
Behavioral Network Forensic
─────────── ─────── ────────
stdout/stderr → strace connect → dropped files
exit code socket snapshot network.strace
```
## 工作原理
```
flowchart LR
A["🖥️ Your machine
## 项目结构
| 文件 | 用途 |
|------|---------|
| `sandbox.py` | 协调器 —— 遥测、artifacts、JSON 报告 |
| `fake_malware.py` | Python 样本(侦察 + EICAR 下载) |
| `fake_malware.sh` | Shell 样本(相同行为) |
| `results/` | 生成的报告和 artifacts *(已 gitignore)* |
## 路线图
- [ ] 网络出站允许/阻止列表
- [ ] 触发前的静态分析
- [ ] 使用 `tcpdump` 捕获 PCAP
- [ ] Next.js 分诊门户
- [ ] 上传报告至 SIEM / 对象存储
## 安全提示
- 仅分析您在法律上被允许处理的样本
- 在被证明无害之前,将所有未知代码视为恶意代码
- 在云端运行不受信任的 payload 之前,请查阅 Modal 的安全模型以及您所在组织的安全策略
## 许可证
[MIT](LICENSE) © 2026 Pantelis Tsagkas
sandbox.py"] -->|stream sample| B["☁️ Modal Sandbox"]
B --> C["strace + exec"]
C --> D["📋 report.json"]
C --> E["📂 artifacts/"]
B --> F["💥 VM destroyed"]
style B fill:#1a1a2e,stroke:#62DE84,color:#fff
style F fill:#2d1b1b,stroke:#ff6b6b,color:#fff
```
1. **启动** — 在 Modal 的云环境中配置一个隔离的沙箱
2. **接入** — 将样本流式传输到 `/tmp/analysis_target.*`
3. **监控** — 使用 `strace` 包装执行以监控网络系统调用
4. **触发** — 以 Python、shell 或二进制文件运行
5. **收集** — stdout、stderr、网络事件、artifacts
6. **销毁** — 终止沙箱,在本地写入 JSON 报告
## 快速开始
**前置条件:** Python 3.12+,[Modal 账户](https://modal.com/),`uv` 或 `pip`
```
git clone https://github.com/PantelisTsagkas/modal-detonation-sandbox.git
cd modal-detonation-sandbox
uv sync
modal setup # first time only
```
**运行一次触发:**
```
uv run modal run sandbox.py --filename fake_malware.py
uv run modal run sandbox.py --filename fake_malware.sh
```
CLI 选项与 payload 检测
``` uv run modal run sandbox.py \ --filename path/to/sample.bin \ --output-dir results \ --execution-timeout 120 \ --payload-type auto ``` | 标志 | 默认值 | 描述 | |------|---------|-------------| | `--filename` | *(必填)* | 您机器上的样本路径 | | `--output-dir` | `results` | 存放 JSON 报告和 artifacts 的目录 | | `--execution-timeout` | `60` | payload 执行的最大秒数 | | `--payload-type` | `auto` | `auto`、`python`、`shell` 或 `binary` | | 输入 | 检测到的类型 | 执行方式 | |-------|---------------|-----------| | `.py` / `.pyw` | `python` | `python3 /tmp/analysis_target.py` | | `.sh` / `.bash` | `shell` | `bash /tmp/analysis_target.sh` | | Shebang `#!/usr/bin/python` | `python` | `python3 ...` | | Shebang `#!/bin/bash` | `shell` | `bash ...` | | 其他所有类型 | `binary` | 在执行 `chmod +x` 后直接运行 |输出示例
``` 📁 Locating local file: fake_malware.py 🧪 Detected payload type: python 🚀 Booting isolated cloud sandbox... 🔒 Streaming fake_malware.py into the secure boundary... 📡 Enabling network telemetry (strace)... 💥 Executing payload inside the isolated sandbox... === PIPELINE TELEMETRY === [!] Malicious Payload Activated... [+] Gathering system info... Target User: root [+] Contacting Command & Control (C2) server... [!] Execution complete. System compromised. === DETONATION REPORT === Status: success Exit code: 0 Payload type: python SHA-256: cd0498fe50fe1720c27b2560161b0d07bafba64331c8cb538f631a8412816305 Sandbox ID: sb-b8RppvSSiD5yxgiPCt2TjQ Duration: 15.05s === NETWORK ACTIVITY === - connect -> 172.21.0.1:53 ← sandbox DNS resolver - connect -> 89.238.73.97:443 ← secure.eicar.org (HTTPS) === ARTIFACTS COLLECTED === - eicar.com.txt (68 bytes) - network.strace (8883 bytes) 🔒 Sandbox session ended. Micro-VM permanently destroyed. ``` 每次运行都会写入一个带有时间戳的文件夹: ``` results/ └── 20260615T150923Z_fake_malware/ ├── report.json └── artifacts/ ├── eicar.com.txt └── network.strace ```标签:DAST, DNS 反向解析, Python, Serverless, 威胁情报, 开发者工具, 恶意软件分析, 无后门, 沙箱, 网络信息收集, 逆向工具