Dev9269/malware-sandbox

GitHub: Dev9269/malware-sandbox

一个自动化的教育性恶意软件分析流水线,在KVM隔离沙箱中对可疑二进制文件进行静态与动态分析,并生成含风险评分的结构化报告。

Stars: 0 | Forks: 0

# 恶意软件沙箱 **一个自动化的教育性恶意软件分析流水线** — 提交一个可疑的 二进制文件,您将收到一份结构化的报告,其中包含静态分析(哈希、PE 解析、 YARA、熵值)、在隔离的 KVM 虚拟机中进行引爆(detonation)、syscall 级别的 行为追踪、网络捕获以及启发式风险评分。

Python React License

## 演示 |POST /submit| API Frontend -->|GET /status/:id| API Frontend -->|GET /report/:id| API API -->|enqueue job| Redis Celery -->|consume| Redis Celery --> Static Celery -->|pre-flight: verify_containment.sh| VM Celery -->|guest agent: copy + exec| VM Celery -->|collect audit.log + pcap| VM Celery -->|snapshot revert| VM Celery --> Reporter Reporter -->|HTML + JSON| API style VM fill:#1a1a2e,stroke:#e94560,stroke-width:2px style Host fill:#16213e,stroke:#0f3460,stroke-width:2px ``` ### 为什么在 VM 隔离环境中进行引爆? 容器共享宿主机内核 — 如果恶意样本利用了 容器逃逸或内核漏洞,它可能会突破限制并危及 宿主机。 VM 提供了由 KVM 强制执行的硬件级隔离: - 样本与宿主机之间**没有共享内核**。 - **libvirt 快照**允许在每次运行后立即恢复到干净状态。 - **仅主机网络**防止 VM 访问真实的互联网 (所有外部流量均被 INetSim 拦截)。 - **宿主机仅运行受信任的 Python 代码** — 用于静态分析和 报告生成 — 而样本在客户机中执行。 请参阅 [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) 了解深入了解。 ## 快速开始 ### 前置条件 - **Python 3.11+**、**Node.js 20+**、**Docker + Compose**(用于整个技术栈) - **libvirt + KVM** 以及准备好的 Windows/Linux VM 快照(用于引爆) - 运行在隔离网络网关(10.0.0.2)上的 **INetSim** ### 1. 克隆并安装 Python 依赖 ``` git clone https://github.com/Dev9269/malware-sandbox.git cd malware-sandbox python -m venv .venv source .venv/bin/activate # or .venv\Scripts\activate on Windows pip install -r requirements.txt ``` ### 2. 启动支持技术栈 ``` docker compose up -d redis # Celery broker + backend ``` ### 3. 配置 libvirt 和沙箱 VM ``` # 定义隔离的 host-only 网络 virsh net-define infra/isolated-network.xml virsh net-start sandbox-net virsh net-autostart sandbox-net # 导入 VM(例如 Windows 10 或 Ubuntu Desktop 镜像) # 并创建一个干净的快照 virsh snapshot-create-as my-vm clean "Clean state after install" ``` ### 4. 启动编排器 ``` # 终端 1 — API server uvicorn orchestrator.api:app --host 0.0.0.0 --port 8000 --reload # 终端 2 — Celery worker celery -A orchestrator.celery_app worker --loglevel=info ``` ### 5. 启动前端 ``` cd frontend npm install npm run dev # http://localhost:5173 — proxies API to :8000 ``` API 也可以直接使用: ``` curl -X POST -F "file=@eicar.com" http://localhost:8000/submit # → {"job_id": "...", "status": "queued"} curl http://localhost:8000/status/ # → {"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, 云安全监控, 恶意软件分析, 搜索引擎查询, 无后门, 沙箱, 自动化分析, 请求拦截, 跨站脚本, 逆向工具, 静态分析