Dev9269/malware-sandbox
GitHub: Dev9269/malware-sandbox
一个自动化的教育性恶意软件分析流水线,在KVM隔离沙箱中对可疑二进制文件进行静态与动态分析,并生成含风险评分的结构化报告。
Stars: 0 | Forks: 0
# 恶意软件沙箱
**一个自动化的教育性恶意软件分析流水线** — 提交一个可疑的
二进制文件,您将收到一份结构化的报告,其中包含静态分析(哈希、PE 解析、
YARA、熵值)、在隔离的 KVM 虚拟机中进行引爆(detonation)、syscall 级别的
行为追踪、网络捕获以及启发式风险评分。
# → {"status": "detonating", ...}
curl http://localhost:8000/report/
# → {"static_analysis": {...}, "dynamic_analysis": {...}, ...}
```
## 项目结构
```
malware-sandbox/
├── orchestrator/ # FastAPI, Celery tasks, VM manager, job models
├── static_analysis/ # PE parser, YARA scanner, hash/entropy analysis
├── dynamic_analysis/ # Auditd log parser, tcpdump wrapper, audit rules
├── reporting/ # Jinja2 HTML report + risk scorer
│ └── templates/ # Dark-theme HTML template
├── frontend/ # React SPA (Vite + Tailwind)
│ └── src/
│ ├── api.ts # API client (submit, status, report)
│ ├── components/ # Stepper, Icons
│ └── pages/ # Upload, Status, Report pages
├── infra/ # INetSim config, libvirt XML, containment script
├── tests/ # Pytest suites (mocked, no VM required)
├── samples-benign/ # EICAR test stubs + sample reports
├── docs/ # Architecture deep-dive
├── scripts/ # Utility scripts (e.g., regenerate sample reports)
├── .github/workflows/ # CI pipeline
├── docker-compose.yml # Redis + API + frontend stack
├── pyproject.toml
└── requirements.txt
```
## 报告与风险评分
分析完成后,流水线会生成一份 HTML 报告和一份 JSON 报告:
```
from reporting.report_generator import ReportGenerator
gen = ReportGenerator()
gen.write_html(merged_report, "report.html") # standalone dark-theme page
gen.write_json(merged_report, "report.json") # machine-readable
```
HTML 报告具有可折叠的部分和可筛选的行为时间线 —
无需 JavaScript 框架。 风险评分(0–100)是根据
六个加权类别计算得出的:
| 类别 | 最高得分 | 信号 |
|---|---|---|
| YARA 匹配 | 30 | 每命中一条规则得 5 分(最高 6 分) |
| 熵值异常 | 20 | 每个熵值 > 7.0 的区段得 5 分 |
| 可疑导入 | 10 | 每个可疑的 PE 特征得 2 分 |
| 敏感 syscall | 15 | 每次 setuid / setgid / capset 得 3 分 |
| 持久化指标 | 15 | 每次写入启动项、cron、systemd 得 3 分 |
| 网络窃取 / 违规 | 10 | 每个非 INetSim 目标得 3 分 |
供检查的示例报告:[`samples-benign/reports/`](samples-benign/reports/)。
## 运行测试
```
# 安装所有内容
pip install -r requirements.txt
# 运行所有测试(static、dynamic、reporting —— 全部为模拟,无需 VM)
pytest tests/ -v
# 运行特定模块
pytest tests/test_static_analyzer.py -v
pytest tests/test_dynamic_analysis.py -v
# 如果缺少 libvirt-python,VM 测试将自动跳过
# 要运行它们:安装 libvirt-dev + libvirt-python,然后:
# pytest tests/test_vm_manager.py -v
```
CI 会在每次推送时通过 GitHub Actions 自动运行(参见
[`.github/workflows/ci.yml`](.github/workflows/ci.yml))。
## 伦理使用
此工具**专为防御性网络安全教育**而设计。
- ✅ 仅在**隔离的、一次性的 VM** 中分析样本
- ✅ 测试仅使用 **EICAR 测试文件**和**自行编写的良性 PoC**
- ✅ 本仓库中的所有样本报告均为**合成数据**,并非真实的恶意软件输出
- ❌ 本仓库**不包含任何活体恶意软件**
- ❌ **切勿**在生产系统、个人计算机或连接网络的宿主机上运行此工具
- ❌ **未经明确授权,请勿**使用此工具分析样本
如果您打算分析真实的恶意软件,您必须:
1. 获得系统所有者的**书面授权**
2. 在**气隙隔离实验室**中操作,且不得与生产环境进行网络桥接
3. 遵守您所在司法管辖区的所有适用法律法规
## 许可证
MIT — 参见 [LICENSE](./LICENSE)。由 [@jainam-h-maru](https://github.com/jainam-h-maru) 构建。
标签:DAST, Python, React, Syscalls, 云安全监控, 恶意软件分析, 搜索引擎查询, 无后门, 沙箱, 自动化分析, 请求拦截, 跨站脚本, 逆向工具, 静态分析