shuvo-halder/malware-behavior-sandbox
GitHub: shuvo-halder/malware-behavior-sandbox
一个用于安全研究的恶意软件行为分析沙箱,在隔离环境中监控样本运行并自动生成风险评分和分析报告。
Stars: 0 | Forks: 0
# 🛡️ 恶意软件行为沙箱 (MBS)
**用于网络安全研究和防御性分析的安全隔离恶意软件行为分析平台。**
## 📋 功能
| 功能 | 描述 | 技术 |
|---------|-------------|------------|
| **沙箱管理** | 创建、启动、停止、重置隔离环境 | Docker, cgroups |
| **文件监控** | 跟踪文件创建、删除、修改、权限 | inotifywait, Go |
| **进程监控** | 监控进程创建、终止、资源使用情况 | /proc, Go |
| **网络监控** | 跟踪 TCP/UDP/DNS 连接和流量 | /proc/net, Go |
| **行为分析** | 基于规则的风险评分和分类 | Python, scikit-learn |
| **报告生成** | JSON, PDF, HTML 分析报告 | reportlab, Jinja2 |
| **Web 仪表盘** | 实时监控、图表、过滤 | React, Recharts |
| **REST API** | 包含 JWT 认证和 RBAC 的完整 CRUD | FastAPI |
| **WebSocket** | 向仪表盘实时传输事件流 | FastAPI WS |
## 🏗️ 架构
```
┌─────────────────────────────────────────────────────┐
│ React Frontend │
│ Dashboard | Sandbox | Analytics │
└────────────────────┬────────────────────────────────┘
│ HTTP / WebSocket
┌────────────────────┴────────────────────────────────┐
│ Nginx Reverse Proxy │
└──────┬─────────────────────────────┬────────────────┘
│ │
┌──────┴──────────┐ ┌─────────────┴───────────────┐
│ FastAPI Backend│ │ Go Monitoring Service │
│ JWT Auth │ │ Process/File/Net Collect │
│ RBAC │ │ Goroutine Pipeline │
│ Rate Limiting │ └─────────────┬───────────────┘
└──────┬──────────┘ │
│ ┌────────┴────────┐
┌──────┴──────┐ ┌────────┴────────┐ │
│ PostgreSQL │ │ Docker Sandbox │ │
│ Redis Cache │ │ (Ubuntu 22.04) │ │
└─────────────┘ │ Isolated Network │ │
│ Resource Limits │ │
└──────────────────┘ │
```
## 🚀 快速开始
### 前置条件
- Docker Desktop (Windows/Mac) 或 Docker Engine (Linux)
- Docker Compose v2+
- 4GB+ 可用内存
### 开发环境设置
```
# 克隆和配置
git clone
cd malware-behavior-sandbox
cp .env.example .env
# 启动开发数据库服务
make setup-dev
# 启动 backend (terminal 1)
cd backend
pip install -r requirements.txt
python -m uvicorn api.main:app --reload --port 8000
# 启动 frontend (terminal 2)
cd frontend
npm install
npm start
```
### 生产环境部署
```
# 构建并启动所有服务
cp .env.example .env # Edit with production secrets!
make up-build
# 检查健康状态
make health
# 访问
# Dashboard: http://localhost:3000
# API Docs: http://localhost:8000/api/docs
```
### 默认凭据
| 用户名 | 密码 | 角色 |
|----------|----------|------|
| admin | admin123 | admin |
| analyst | analyst123 | analyst |
## 📁 项目结构
```
malware-behavior-sandbox/
├── backend/ # Python/FastAPI backend
│ ├── api/ # FastAPI application
│ │ ├── main.py # App entry point
│ │ ├── config.py # Settings from env vars
│ │ ├── middleware/ # Auth, audit, CORS
│ │ ├── routes/ # API endpoints (8 routers)
│ │ ├── schemas/ # Pydantic validation
│ │ ├── database/ # SQLAlchemy models + session
│ │ └── websocket/ # Real-time handlers
│ ├── analysis/ # Behavioral analysis engine
│ │ ├── engine.py # Orchestrator
│ │ ├── scoring.py # Risk score calculator
│ │ └── classifier.py # Behavior classification
│ └── requirements.txt
├── monitoring/ # Go monitoring service
│ ├── cmd/monitor/main.go # Entry point
│ ├── internal/
│ │ ├── collector/ # Process, file, network
│ │ ├── reporter/ # API client
│ │ ├── pipeline/ # Goroutine orchestrator
│ │ └── models/ # Event data structures
│ └── go.mod
├── frontend/ # React dashboard
│ ├── src/
│ │ ├── pages/ # 6 pages (Dashboard, Sandbox, etc.)
│ │ ├── components/ # Layout, charts, tables
│ │ ├── context/ # Auth context
│ │ └── api/ # Axios client
│ └── package.json
├── docker/ # Docker configuration
│ ├── Dockerfile.sandbox # Isolated execution env
│ ├── sandbox-entrypoint.sh # Container lifecycle
│ └── collect-events.sh # In-container collector
├── configs/ # Nginx, Redis, collector config
├── database/migrations/ # SQL schema
├── tests/ # Unit + integration tests
├── scripts/ # DB seeder, utilities
├── docs/ # Architecture, deployment, security
├── docker-compose.yml # Production orchestration
├── docker-compose.dev.yml # Development services
├── Makefile # 30+ commands
└── .env.example # Environment template
```
## 🔌 API 端点
### 认证
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| POST | `/api/v1/auth/register` | 注册用户 |
| POST | `/api/v1/auth/login` | 登录(返回 JWT) |
| POST | `/api/v1/auth/refresh` | 刷新 token |
| GET | `/api/v1/auth/me` | 获取个人资料 |
### 沙箱
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| GET | `/api/v1/sandboxes` | 列出沙箱 |
| POST | `/api/v1/sandboxes` | 创建沙箱 |
| POST | `/api/v1/sandboxes/{id}/start` | 启动沙箱 |
| POST | `/api/v1/sandboxes/{id}/stop` | 停止沙箱 |
| POST | `/api/v1/sandboxes/{id}/reset` | 重置沙箱 |
| POST | `/api/v1/sandboxes/{id}/snapshot` | 获取快照 |
### 分析
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| POST | `/api/v1/analytics/sessions` | 创建会话 |
| GET | `/api/v1/analytics/sessions` | 列出会话 |
| GET | `/api/v1/analytics/risk/{id}` | 风险评分 |
| GET | `/api/v1/analytics/summary/{id}` | 分析摘要 |
| GET | `/api/v1/analytics/timeline/{id}` | 事件时间线 |
### 事件
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| GET | `/api/v1/sessions/{id}/files` | 文件事件 |
| GET | `/api/v1/sessions/{id}/processes` | 进程事件 |
| GET | `/api/v1/sessions/{id}/network` | 网络事件 |
### 报告与仪表盘
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| POST | `/api/v1/reports/generate` | 生成报告 |
| GET | `/api/v1/reports` | 列出报告 |
| GET | `/api/v1/reports/{id}/download` | 下载报告 |
| GET | `/api/v1/dashboard` | 仪表盘概览 |
完整的交互式文档:`http://localhost:8000/api/docs`
## 📊 分析引擎
### 风险评分 (0-100)
- **0-25:** 良性
- **26-65:** 可疑
- **66-100:** 恶意
### 检测规则
| 类别 | 规则 | 严重程度 |
|----------|------|----------|
| 文件 | 过度修改 (>50) | 中/高 |
| 文件 | 系统目录更改 | 高 |
| 文件 | 权限更改 | 高 |
| 进程 | 过多子进程 (>30) | 高 |
| 进程 | 可疑进程名 | 中 |
| 网络 | 过多出站连接 (>10 个 IP) | 高 |
| 网络 | DNS 隧道特征 | 高 |
| 网络 | 大量数据外泄 (>10MB) | 高 |
| 资源 | 高 CPU 占用 (>80%) | 中 |
| 资源 | 高内存占用 (>500MB) | 中 |
## 🧪 测试
```
# 运行所有测试
make test
# 运行 coverage
make test-coverage
# 运行 Go 测试
make test-monitor
```
## 📖 文档
| 文档 | 描述 |
|----------|-------------|
| [架构](docs/architecture.md) | 系统设计与组件 |
| [部署](docs/deployment.md) | 设置与部署指南 |
| [安全](docs/security.md) | 安全措施与策略 |
## 🛠️ Make 命令
```
make help # Show all commands
make setup # Full project setup
make up-build # Build and start all services
make down # Stop all services
make logs # View service logs
make test # Run tests
make db-migrate # Run database migrations
make seed # Seed demo data
make health # Check service health
make clean # Clean build artifacts
```
## 📜 许可证
本项目仅供经授权的安全研究和防御性分析使用。
标签:DAST, Docker, Go, React, Ruby工具, Syscalls, 安全防御评估, 恶意软件分析, 搜索引擎查询, 日志审计, 沙箱, 测试用例, 网络信息收集, 请求拦截, 逆向工具