bwanox/malware-sandbox
GitHub: bwanox/malware-sandbox
一个基于容器化与多源情报的恶意软件自动化分析平台,解决样本安全隔离、分析流程化与报告生成难题。
Stars: 0 | Forks: 0
# 恶意软件沙箱
一个功能全面的基于网络的恶意软件分析平台,具备先进的静态和动态分析能力、威胁情报集成以及专业报告功能。
## 概述
这个增强型恶意软件沙箱提供企业级的恶意软件分析,具备以下关键特性:
- **高级静态分析**:19+ YARA 规则、PE 头分析、熵计算、字符串提取
- **动态分析**:容器化执行,带行为监控和网络分析
- **IOC 提取**:全面的妥协指标提取与分类
- **威胁情报**:多源集成(VirusTotal、Hybrid Analysis、AbuseIPDB、URLhaus)
- **PDF 报告**:带执行摘要的专业分析报告
- **监控**:实时系统监控、告警和健康检查
- **自动清理**:具有可配置保留策略的自我维护系统
- **配置管理**:带有验证的环境特定设置
## 架构
```
[Frontend - React + Vite]
|
[FastAPI Backend] <---> [SQLite Database]
| |
|<----> [Redis] <----|
|
[Celery Workers] <----> [Threat Intelligence APIs]
|
|----> [Enhanced Static Analyzer]
| - 19+ YARA rules
| - PE analysis
| - IOC extraction
|
|----> [Enhanced Dynamic Analyzer]
| - Docker containers
| - Behavior monitoring
| - Network analysis
|
|----> [PDF Report Generator]
|
|----> [Monitoring System]
|
|----> [Cleanup Manager]
```
## 项目结构
```
malware-sandbox/
|
|-- README.md # This file
documentation
|-- docker-compose.yml # Docker service configuration
|
|-- backend/ # FastAPI backend
| |-- main.py # FastAPI application entry point
| |-- database.py # Database configuration
| |-- models.py # SQLAlchemy models
| |-- config.py # Configuration management
| |-- requirements.txt # Python dependencies
| |
| |-- analysis/ # Analysis modules
| | |-- enhanced_static_analyzer.py # Advanced static analysis
| | |-- enhanced_dynamic_analyzer.py # Advanced dynamic analysis
| | |-- ioc_extractor.py # IOC extraction
| | |-- threat_intelligence.py # Threat intelligence integration
| | |-- pdf_report_generator.py # PDF report generation
| | |-- static_analyzer.py # Original static analyzer
| | |-- dynamic_analyzer.py # Original dynamic analyzer
| | |-- mitre_mapper.py # MITRE ATT&CK mapping
| | |-- report_generator.py # Report generation
| |
| |-- monitoring/ # Monitoring system
| | |-- monitor.py # Core monitoring functionality
| |
| |-- cleanup/ # Cleanup management
| | |-- cleanup_manager.py # Automated cleanup system
| |
| |-- config/ # Configuration management
| | |-- enhanced_config.py # Advanced configuration
| |
| |-- workers/ # Celery workers
| | |-- enhanced_celery_worker.py # Enhanced analysis pipeline
| | |-- celery_worker.py # Original worker
| |
| |-- routers/ # API routes
| | |-- upload.py # File upload endpoint
| | |-- analysis.py # Analysis endpoints
| | |-- reports.py # Report endpoints
| |
| |-- sandbox/ # Docker sandbox
| | |-- Dockerfile.sandbox # Sandbox container definition
| | |-- monitor.py # Container monitoring script
|
|-- frontend/ # React frontend
| |-- src/
| | |-- App.jsx # Main React component
| | |-- pages/ # React pages
| | |-- components/ # React components
| |-- package.json # Node.js dependencies
| |-- Dockerfile # Frontend Docker configuration
|
|-- uploads/ # File upload directory
|-- reports/ # Generated reports directory
```
## 快速开始
### 先决条件
- Docker 和 Docker Compose
- Git
- (可选)威胁情报服务的 API 密钥
### 1. 克隆仓库
```
git clone
cd malware-sandbox
```
### 2. 环境配置
在项目根目录创建 `.env` 文件:
```
# 基本配置
ENVIRONMENT=development
DEBUG=true
SECRET_KEY=your-secure-secret-key-here
# 数据库
DATABASE_URL=sqlite:///./malware_sandbox.db
# Redis
REDIS_URL=redis://redis:6379/0
# 威胁情报 API(可选但推荐)
VIRUSTOTAL_API_KEY=your-virustotal-api-key
HYBRID_ANALYSIS_API_KEY=your-hybrid-analysis-api-key
ABUSEIPDB_API_KEY=your-abuseipdb-api-key
URLHAUS_API_KEY=your-urlhaus-api-key
# 分析设置
ENABLE_DYNAMIC_ANALYSIS=true
ENABLE_NETWORK_ANALYSIS=false
ENABLE_THREAT_INTEL=true
ANALYSIS_TIMEOUT=60
# 监控
ENABLE_MONITORING=true
MONITORING_INTERVAL=60
# 清理
ENABLE_CLEANUP=true
CLEANUP_INTERVAL_HOURS=24
FILE_RETENTION_DAYS=30
# 报告
ENABLE_PDF_REPORTS=true
REPORTS_DIR=./reports
```
### 3. 构建沙箱镜像
```
cd backend/sandbox
docker build -t sandbox-base -f Dockerfile.sandbox .
cd ../../
```
### 4. 启动服务
```
docker-compose up --build
```
### 5. 访问应用
- **前端**: http://localhost:5173
- **后端 API**: http://localhost:8000
- **API 文档**: http://localhost:8000/docs
- **健康检查**: http://localhost:8000/api/health
## API 端点
### 文件分析
```
# 上传并分析文件
curl -X POST "http://localhost:8000/api/upload" \
-H "Content-Type: multipart/form-data" \
-F "file=@sample.exe"
# 获取分析结果
curl "http://localhost:8000/api/reports/{job_id}"
# 下载 PDF 报告
curl "http://localhost:8000/api/reports/{job_id}/pdf" \
--output report.pdf
```
### 监控
```
# 系统指标
curl "http://localhost:8000/api/monitoring/metrics"
# 运行状况
curl "http://localhost:8000/api/monitoring/health"
# 告警
curl "http://localhost:8000/api/monitoring/alerts"
```
### 清理
```
# 手动运行清理
curl -X POST "http://localhost:8000/api/cleanup/run"
# 获取清理统计信息
curl "http://localhost:8000/api/cleanup/stats"
```
## 开发指南
### 设置开发环境
1. **后端开发**
```
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
```
2. **前端开发**
```
cd frontend
npm install
npm run dev
```
3. **数据库设置**
```
# 开发环境下自动使用 SQLite
# 生产环境请在 .env 中配置 DATABASE_URL
```
### 添加新分析功能
1. **静态分析扩展**
将新分析方法添加到 `backend/analysis/enhanced_static_analyzer.py`:
```
def new_analysis_method(self, filepath: str) -> dict:
"""Add your new analysis method here"""
results = {}
# Your analysis logic
return results
def run_all(self, filepath: str) -> dict:
results = {
# Existing methods...
"new_analysis": self.new_analysis_method(filepath)
}
return results
```
2. **YARA 规则**
将新 YARA 规则添加到 `enhanced_static_analyzer.py` 中的 `yara_rules` 字符串:
```
rule New_Malware_Family {
meta:
description = "Detects new malware family"
family = "NewFamily"
strings:
$pattern1 = "suspicious_string"
$pattern2 = { 48 31 C0 }
condition:
any of them
}
```
3. **威胁情报集成**
将新威胁情报源添加到 `backend/analysis/threat_intelligence.py`:
```
async def query_new_source(self, indicator: str) -> Dict:
"""Query new threat intelligence source"""
# Implementation here
pass
```
### 配置
所有配置均通过环境变量管理。请参阅 `backend/config/enhanced_config.py` 了解所有可用选项。
### 测试
```
# 后端测试
cd backend
pytest
# 前端测试
cd frontend
npm test
```
## 安全考虑
### 隔离
- **容器隔离**:所有恶意软件分析在隔离的 Docker 容器中运行
- **网络隔离**:默认禁用网络访问
- **文件系统**:样本以只读方式挂载
- **资源限制**:强制执行 CPU 和内存限制
### API 安全
- **认证**:生产环境中配置 JWT 认证
- **CORS**:生产环境中配置允许的来源
- **速率限制**:对 API 端点实施速率限制
- **输入验证**:所有输入均经过验证和清理
### 数据保护
- **加密**:敏感数据应加密存储
- **访问控制**:实施适当的访问控制
- **审计日志**:记录所有操作以供审计
- **数据保留**:配置适当的数据保留策略
## 生产部署
### 环境配置
生产部署时,在 `.env` 中设置以下选项:
```
ENVIRONMENT=production
DEBUG=false
SECRET_KEY=your-production-secret-key
# 安全
ENABLE_AUTHENTICATION=true
JWT_SECRET=your-jwt-secret
CORS_ORIGINS=https://yourdomain.com
# 数据库(生产环境请使用 PostgreSQL)
DATABASE_URL=postgresql://user:password@localhost/malware_sandbox
# Redis(生产环境请使用集群 Redis)
REDIS_URL=redis://redis-cluster:6379/0
# 监控
ENABLE_MONITORING=true
MONITORING_INTERVAL=30
# 清理
ENABLE_CLEANUP=true
CLEANUP_INTERVAL_HOURS=12
FILE_RETENTION_DAYS=7
```
### Docker 生产配置
创建 `docker-compose.prod.yml`:
```
version: "3.8"
services:
redis:
image: redis:alpine
volumes:
- redis_data:/data
restart: unless-stopped
backend:
build:
context: ./backend
environment:
- ENVIRONMENT=production
volumes:
- ./uploads:/app/uploads
- ./reports:/app/reports
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
depends_on:
- redis
celery_worker:
build:
context: ./backend
command: celery -A workers.enhanced_celery_worker.celery_app worker --loglevel=info --concurrency=4
environment:
- ENVIRONMENT=production
volumes:
- ./uploads:/app/uploads
- ./reports:/app/reports
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
depends_on:
- redis
- backend
celery_beat:
build:
context: ./backend
command: celery -A workers.enhanced_celery_worker.celery_app beat --loglevel=info
environment:
- ENVIRONMENT=production
restart: unless-stopped
depends_on:
- redis
frontend:
build: ./frontend
restart: unless-stopped
volumes:
redis_data:
```
### 监控和告警
使用你偏好的监控系统进行设置:
```
# 运行状况检查端点
curl "http://localhost:8000/api/health"
# 指标端点
curl "http://localhost:8000/api/monitoring/metrics"
```
## 故障排除
### 常见问题
1. **Docker 套接字权限**
```
# 将用户添加到 docker 组
sudo usermod -aG docker $USER
# 登出并重新登录
```
2. **Redis 连接问题**
```
# 检查 Redis 状态
docker-compose logs redis
# 重启 Redis
docker-compose restart redis
```
3. **API 密钥问题**
```
# 检查 API 密钥是否已设置
env | grep _API_KEY
# 测试 API 连接性
curl -H "X-Apikey: YOUR_KEY" https://www.virustotal.com/vtapi/v2/ip-address/report?ip=8.8.8.8
```
4. **内存问题**
```
# 检查容器资源使用情况
docker stats
# 在 docker-compose.yml 中调整内存限制
```
### 调试模式
启用调试日志:
```
export LOG_LEVEL=DEBUG
export DEBUG=true
docker-compose up --build
```
### 日志
```
# 查看所有日志
docker-compose logs
# 查看特定服务日志
docker-compose logs backend
docker-compose logs celery_worker
# 查看实时日志
docker-compose logs -f
```
### 拉取请求流程
1. 叉取仓库
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
3. 提交更改 (`git commit -m 'Add amazing feature'`)
4. 推送到分支 (`git push origin feature/amazing-feature`)
5. 打开拉取请求
### 代码风格
- **Python**:遵循 PEP 8,使用 Black 格式化
- **JavaScript**:遵循 ESLint 规则,使用 Prettier 格式化
- **提交**:使用约定式提交消息
### 测试
- 为新功能添加测试
- 确保所有测试通过后再提交
- 为新功能添加文档
## 许可证
本项目根据 MIT 许可证授权 - 详情见 LICENSE 文件。
## 致谢
- **YARA**:提供模式匹配规则
- **VirusTotal**:提供威胁情报数据
- **Docker**:提供容器化支持
- **FastAPI**:提供 Web 框架
- **React**:提供前端框架
## 支持
如需支持和提问:
1. 查看 [ENHANCED_FEATURES.md](ENHANCED_FEATURES.md) 获取详细功能文档
2. 查阅上方的故障排除部分
3. 访问 API 文档 `http://localhost:8000/docs`
4. 在 GitHub 上提交错误报告或功能请求
**注意**:这是一个功能强大的恶意软件分析工具。请负责任地使用,并仅在专为恶意软件分析设计的隔离系统上使用。
标签:AbuseIPDB, AV绕过, Celery, DAST, DNS信息、DNS暴力破解, Docker, FastAPI, Hybrid Analysis, IOC提取, PDF报告, PE分析, React, Redis, SQLite, Syscalls, URLhaus, Vite, YARA规则, 云安全监控, 代理支持, 健康检查, 告警, 威胁情报, 字符串提取, 安全防御评估, 容器化执行, 开发者工具, 恶意软件分析, 搜索引擎查询, 沙箱, 熵计算, 病毒总览, 系统分析, 网络分析, 自动化清理, 行为监控, 请求拦截, 逆向工具, 静态分析