SamFrieman/c2-beacon-detector
GitHub: SamFrieman/c2-beacon-detector
一款完全在浏览器端运行的 C2 Beacon 检测工具,结合机器学习与威胁情报分析网络流量中的命令与控制通信行为。
Stars: 1 | Forks: 0
# C2 Beacon Detector v2.1
**专业级命令与控制(Command & Control)Beacon 检测工具,结合机器学习与多源威胁情报**
一款强大的客户端网络流量分析工具,结合行为模式识别、机器学习以及来自多个来源的实时威胁情报,以识别 C2 beacon 活动。非常适合安全分析师、事件响应人员和威胁猎人使用。
[](https://opensource.org/licenses/MIT)
[](https://github.com/SamFrieman/c2-beacon-detector)
[](https://threatfox.abuse.ch/)
[](https://attack.mitre.org/)
## v2.1 新特性
### 多源威胁情报
- **ThreatFox 集成** - 来自 Abuse.ch 的实时 IOC 查询
- **自定义检测规则** - 添加基于 IP/CIDR 的专属规则
- **综合评分** - 基于多源加权的置信度评估
- **规则管理** - 导入/导出自定义规则集
### 机器学习集成
- **Beacon 分类器** - 基于 Random Forest 的检测模型
- **异常检测** - 使用 Isolation Forest 识别离群点
- **Ensemble 预测** - 组合多模型输出以获得更高准确率
- **自适应学习** - 模型利用历史数据进行自我优化
### 高级报告
- **HTML 报告** - 专业的事件响应文档
- **PDF 导出** - 适合打印的分析报告
- **增强型 JSON** - 全面的结构化数据导出
- **执行摘要** - 为管理层提供的高层级概览
### 历史分析
- **自动追踪** - 在本地存储多达 100 次分析记录
- **百分位比较** - “得分高于过去 90% 的分析”
- **相似模式检测** - 查找具有相似特征的分析记录
- **趋势分析** - 查看特定时间段内的模式
- **CSV/JSON 导出** - 导出历史数据以供外部分析
### 自定义规则引擎
- **基于 IP 的规则** - 匹配特定 IP 地址
- **CIDR 范围** - 支持网段范围(例如:10.0.0.0/8)
- **置信度评分** - 可配置的威胁等级
- **标签与元数据** - 规则的组织与分类
- **持久化存储** - 规则跨会话保存
## 核心功能
### 行为分析
- **时间模式检测** - 识别规律性的 Beacon 间隔
- **Jitter 分析** - 计算时间方差与一致性
- **周期性评分** - 衡量连接的规律程度
- **熵值计算** - 检测自动化行为模式
- **Payload 一致性** - 分析数据大小的模式
- **端口多样性分析** - 识别单端口通信行为
- **活动时间模式** - 检测非正常工作时间的异常活动
### 框架识别
检测流行 C2 框架的特征签名:
- **Cobalt Strike** - 低 Jitter 的 60 秒 Beacon 间隔
- **Metasploit/Meterpreter** - 120 秒的 Beacon 模式
- **PowerShell Empire** - 具有周期性的短间隔通信
- **Sliver** - 一致的 Payload 模式
- **Covenant** - .NET C2 框架签名
- **自定义 C2** - 通用模式检测
### MITRE ATT&CK 映射
- **T1071** - 应用层协议 (Application Layer Protocol)
- **T1573** - 加密通道 (Encrypted Channel)
- **T1001** - 数据混淆 (Data Obfuscation)
- 基于检测到的行为自动进行技术映射
### 隐私与安全
- **100% 客户端运行** - 绝无数据离开您的浏览器
- **不上传数据** - 所有处理均在本地完成
- **私有 IP 过滤** - 自动跳过 RFC1918 地址
- **开源** - 完全透明
- **仅使用 LocalStorage** - 数据始终保留在您的设备上
## 快速开始
### 在线演示
访问[在线演示](https://samfrieman.github.io/c2-beacon-detector/)立即体验。
### 本地安装
```
# Clone the repository
git clone https://github.com/SamFrieman/c2-beacon-detector.git
cd c2-beacon-detector
# 本地运行 (Python 3)
python -m http.server 8000
# 或者使用 Node.js
npx http-server -p 8000
# 在浏览器中打开
open http://localhost:8000
```
### 使用示例数据
点击任意示例按钮即可查看工具的实际运行效果:
- **Cobalt Strike 示例** - 包含已知 IOC 的高置信度 C2 流量
- **Metasploit 示例** - 中等置信度的 Beacon 模式
- **正常流量示例** - 普通的网络活动
## 输入格式
### 预期的 JSON 结构
```
{
"connections": [
{
"timestamp": 1704646800000,
"bytes": 1024,
"dest_ip": "192.168.1.100",
"src_ip": "10.0.0.50",
"src_port": 49152,
"dest_port": 443
}
]
}
```
### 支持的字段名称
| 字段 | 备选名称 | 必需 | 描述 |
|-------|-------------|----------|-------------|
| `timestamp` | `time`, `ts`, `epoch` | ✅ 是 | Unix 时间戳(毫秒或秒) |
| `bytes` | `size`, `length` | ❌ 否 | Payload 大小(字节) |
| `dest_ip` | `dst`, `destination`, `dst_ip` | ✅ 是 | 目标 IP 地址 |
| `src_ip` | `src`, `source` | ❌ 否 | 源 IP 地址 |
| `dest_port` | `dport` | ❌ 否 | 目标端口号 |
| `src_port` | `sport` | ❌ 否 | 源端口号 |
### 最低要求
- 至少需要 **2 个连接**记录
- 必须包含 **timestamp** 字段
- 时间戳可以是 Unix epoch(秒或毫秒)
## 架构
本项目采用模块化设计,以保障可维护性与可扩展性:
```
c2-beacon-detector/
├── index.html # Main HTML structure
├── styles.css # All styling
├── utils.js # Utility functions
├── threat-intel.js # Multi-source threat intelligence
├── ml-detector.js # Machine learning models
├── history-manager.js # Historical analysis tracking
├── report-generator.js # HTML/PDF report generation
├── analyzer.js # Behavioral analysis engine
├── detector.js # Detection & scoring logic
├── ui.js # UI rendering controller
└── app.js # Main application controller
```
### 模块职责
#### `utils.js` - 核心工具
- JSON 解析与验证
- 统计计算(平均值、中位数、标准差)
- IP 提取与过滤(RFC1918 检测)
- 数据格式化(字节、时间戳、持续时间)
- 示例数据生成
#### `threat-intel.js` - 多源威胁情报
- ThreatFox API 客户端
- 自定义规则管理 (IP/CIDR)
- 多源 IOC 查询
- 综合置信度评分
- 恶意软件家族映射
- 规则导入/导出
#### `ml-detector.js` - 机器学习
- Beacon 分类模型
- 异常检测 (Isolation Forest)
- Ensemble 预测
- 特征归一化
- 基于历史数据的模型训练
- 预测结果解释
#### `history-manager.js` - 历史分析
- 分析记录存储(最多 100 条)
- 百分位计算
- 相似模式检测
- 趋势分析
- CSV/JSON 导出
- 历史记录导入
#### `report-generator.js` - 高级报告
- HTML 报告生成
- PDF 导出(通过打印)
- 增强型 JSON 格式
- 专业的 IR 文档
- 执行摘要
#### `analyzer.js` - 行为分析
- 特征提取(25+ 个特征)
- 熵值计算
- 模式检测
- 框架识别
- MITRE ATT&CK 映射
- 端口/时间分析
#### `detector.js` - 检测引擎
- 多因子评分算法
- 威胁分类
- IOC 优先级排序
- 报告生成
- 正常指标处理
#### `ui.js` - UI 控制器
- 结果渲染
- 错误处理
- 加载状态展示
- 动态更新
- 多格式导出按钮
#### `app.js` - 应用控制器
- 模块初始化
- 事件处理程序
- 状态管理
- 工作流协调
- 键盘快捷键
## 工作原理
### 分析流水线
```
┌─────────────┐
│ Upload JSON │
└──────┬──────┘
│
▼
┌─────────────────┐
│ Validate Format │
└──────┬──────────┘
│
▼
┌──────────────────────┐
│ Extract Behavioral │
│ Features (25+) │
│ • Timing patterns │
│ • Payload analysis │
│ • Network metadata │
│ • Entropy & jitter │
└──────┬───────────────┘
│
▼
┌──────────────────────┐
│ Multi-Source Threat │
│ Intelligence │
│ • ThreatFox API │
│ • Custom rules │
│ • CIDR matching │
│ • Combined scoring │
└──────┬───────────────┘
│
▼
┌──────────────────────┐
│ Machine Learning │
│ Prediction │
│ • Beacon classifier │
│ • Anomaly detector │
│ • Ensemble model │
└──────┬───────────────┘
│
▼
┌──────────────────────┐
│ Detection Engine │
│ • Multi-factor score │
│ • MITRE mapping │
│ • Classification │
└──────┬───────────────┘
│
▼
┌──────────────────────┐
│ Historical Compare │
│ • Percentile rank │
│ • Similar patterns │
│ • Trend analysis │
└──────┬───────────────┘
│
▼
┌──────────────────────┐
│ Generate Reports │
│ • HTML/PDF/JSON │
│ • Save to history │
│ • Update ML models │
└────────────────────────┘
```
### 检测评分
本工具采用多因子评分系统(0-100 分):
| 分数范围 | 分类 | ML 预测 | 建议操作 |
|-------------|---------------|---------------|-----------------|
| 80-100 | **严重 (CRITICAL)** | 恶意(高置信度) | 立即隔离并升级 IR |
| 65-79 | **可疑 (SUSPICIOUS)** | 恶意(中等置信度) | 需紧急调查 |
| 45-64 | **关注 (MONITOR)** | 可疑 | 建议加强监控 |
| 0-44 | **正常 (BENIGN)** | 正常 | 继续常规运营 |
### 评分因子
**威胁情报(+45-70 分)**
- 来自 ThreatFox 的 IOC 匹配
- 多源确认
- 高置信度恶意软件家族
- 自定义规则匹配
**机器学习(+20-35 分)**
- ML Ensemble:恶意预测
- 高异常得分
- 多种异常因子
**周期性(+15-35 分)**
- 极端周期性(>80%)
- 强周期性(>70%)
- 显著周期性(>60%)
**Jitter(抖动)(+10-30 分)**
- 极低 Jitter(<8%)
- 低 Jitter(<15%)
- 时间高度一致(<25%)
**Payload 一致性(+15-20 分)**
- 极一致的大小(>90%)
- 一致的 Payload(>80%)
**已知 C2 签名(+18-20 分)**
- 60秒 Cobalt Strike Beacon
- 120秒 Metasploit 模式
- Empire/Sliver 签名
**持久性(+12-15 分)**
- 持续 Beacon 活动(>2 小时)
- 延长模式(>1 小时)
**网络模式(+10-12 分)**
- 单一目标 IP
- 端口多样性低
- 低熵值模式
**正常指标(-10 到 -25 分)**
- 高时间方差
- 多个目标地址
- 极短的通信间隔
- 高时间多样性
## 输出示例
### 控制台输出
```
Initializing C2 Beacon Detector v2.1...
✓ ThreatFox: Loaded 1247 IOCs
✓ ML models initialized
✓ Loaded 23 historical analyses
✓ All systems initialized
- Threat Intel: 2 source(s) active
- ML Models: Enabled
- History: 23 record(s)
Found 2 threat intel matches
ML prediction: malicious
Analysis complete: CRITICAL (Score: 92)
```
### HTML 报告预览
HTML 报告包含:
- 包含威胁评分的执行摘要
- 威胁情报匹配(所有来源)
- 机器学习分析结果
- 网络数据统计
- 检测因子明细
- MITRE ATT&CK 技术映射
- 提取的特征表
- 适合打印的专业排版
### 导出报告结构 (JSON)
```
{
"metadata": {
"tool": "C2 Beacon Detector",
"version": "2.1.0",
"timestamp": "2024-01-11T10:30:00Z",
"analyzed_file": "traffic_capture.json",
"features_enabled": {
"threat_intel": true,
"machine_learning": true,
"historical_comparison": true
}
},
"summary": {
"score": 92,
"classification": "CRITICAL",
"severity": "critical",
"recommendation": "🚨 IMMEDIATE ACTION..."
},
"threat_intelligence": {
"matches": [...],
"total_iocs_matched": 2,
"sources_used": ["ThreatFox", "Custom Rules"]
},
"machine_learning": {
"ensemble": {
"prediction": "malicious",
"confidence": "high",
"score": 0.87
}
},
"behavioral_analysis": {...},
"network_data": {...},
"features": {...}
}
```
## 使用场景
### 事件响应
- 快速分流疑似 C2 流量
- 生成专业报告用于记录存档
- 与多源威胁情报进行关联
- 追踪分析历史以构建调查时间线
- 以多种格式导出分析结果
### 威胁狩猎
- 主动进行 Beacon 检测
- 建立模式基线
- 框架指纹识别
- 从多个来源丰富 IOC 信息
- 历史趋势分析
### 安全运营
- PCAP 分析
- SIEM 告警验证
- 网络监控
- 自定义规则部署
- 培训与教育
### 红队 / 紫队
- 验证 C2 规避技术
- 测试检测能力
- 改进防御姿态
- 评估工具有效性
- 记录演练结果
## 配置
### 威胁情报设置
位于 `threat-intel.js`:
```
config: {
threatfoxAPI: 'https://threatfox-api.abuse.ch/api/v1/',
cacheExpiry: 3600000, // 1 hour cache
maxIPs: 20, // Max IPs to check per analysis
enabledSources: {
threatfox: true,
customRules: true
}
}
```
### 机器学习设置
位于 `ml-detector.js`:
```
config: {
enabled: true,
confidenceThreshold: 0.65,
useEnsemble: true
}
```
### 检测阈值
位于 `detector.js` - 可根据需要调整评分:
```
// Periodicity thresholds
if (features.periodicity > 0.80) score += 35; // CRITICAL
if (features.periodicity > 0.70) score += 25; // HIGH
if (features.periodicity > 0.60) score += 15; // MODERATE
```
### 历史记录设置
位于 `history-manager.js`:
```
maxHistorySize: 100 // Maximum stored analyses
```
## 高级功能
### 自定义检测规则
通过 UI 添加您自己的 IOC:
```
// Add IP-based rule
ThreatIntel.addCustomRule({
type: 'ip',
value: '192.168.1.100',
malware: 'Custom C2',
confidence: 85,
threat_type: 'c2',
tags: ['internal', 'suspected'],
description: 'Suspected internal C2 server'
});
// Add CIDR range rule
ThreatIntel.addCustomRule({
type: 'cidr',
value: '10.0.0.0/8',
malware: 'Internal Range',
confidence: 70,
tags: ['network-scan']
});
```
### 导出自定义规则
```
// Export rules to JSON
const rulesJSON = ThreatIntel.exportRules();
// Save to file or share with team
// Import rules from JSON
ThreatIntel.importRules(rulesJSON);
```
### 历史分析
```
// View recent history
const history = HistoryManager.getHistory(20);
// Get trend analysis
const trends = HistoryManager.getTrends(7); // Last 7 days
// Export history as CSV
const csv = HistoryManager.exportHistory('csv');
// Compare current with historical
const comparison = HistoryManager.compareWithHistory(currentAnalysis);
```
### 报告生成
```
// Download JSON report
downloadReport('json');
// Download HTML report
downloadReport('html');
// Print to PDF
downloadReport('pdf');
```
### 键盘快捷键
- **Ctrl+H** / **Cmd+H** - 查看分析历史
- **Ctrl+E** / **Cmd+E** - 导出当前报告 (JSON)
## 开发
### 前置条件
- 现代网页浏览器 (Chrome, Firefox, Safari, Edge)
- 用于本地开发的 Web 服务器
- 互联网连接(用于威胁情报查询)
### 本地开发
```
# 安装一个简单的 web server
npm install -g http-server
# 运行服务器
http-server -p 8080
# 在浏览器中打开
open http://localhost:8080
```
### 测试
```
# 使用示例数据进行测试
# 点击 UI 中的 "Cobalt Strike Sample" 按钮
# 使用你自己的 JSON 进行测试
# 拖放一个格式正确的 JSON 文件
# 测试自定义规则
# 添加一个自定义 IP 规则并重新分析
```
### 添加新功能
1. **新的威胁情报源**
// In threat-intel.js
async lookupNewSource(ip) {
const response = await fetch(`https://api.example.com/lookup/${ip}`);
return await response.json();
}
2. **新的 ML 模型**
// In ml-detector.jscreateNewModel() {
return {
predict: (features) => {
// Your model logic
return { score: 0.85, prediction: 'malicious' };
}
};
}
3. **新的导出格式**
// In report-generator.js
generateMarkdown(analysis, fileName, connections) {
// Generate markdown format
}
## 贡献
欢迎您的贡献!请遵循以下准则:
1. **Fork** 本仓库
2. **创建** 功能分支 (`git checkout -b feature/amazing-feature`)
3. **提交** 您的更改 (`git commit -m 'Add amazing feature'`)
4. **推送** 到分支 (`git push origin feature/amazing-feature`)
5. **发起** Pull Request
### 代码规范
- 使用具有描述性的变量名
- 为复杂的逻辑添加注释
- 遵循现有的代码模式
- 保持函数功能专注且精简
- 及时更新文档
### Pull Request 模板
```
## 描述
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## 测试
How has this been tested?
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No new warnings generated
```
## 许可证
本项目基于 MIT 许可证授权 - 详情请参阅 [LICENSE](LICENSE) 文件。
```
MIT License
Copyright (c) 2024 Sam Frieman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
```
## 鸣谢
- **Abuse.ch** - ThreatFox API 及 IOC 数据
- **MITRE Corporation** - ATT&CK 框架
- **安全社区** - 研究与威胁情报
- **Font Awesome** - 图标库
- **开源贡献者** - 社区支持
## 免责声明
**仅限用于授权的安全分析**
本工具仅供合法的安全研究、事件响应及授权的渗透测试使用。用户在分析网络流量前,有责任确保已获得相关授权。未经授权拦截或分析网络通信在您所在的司法管辖区可能属于违法行为。
对于滥用本工具的行为,作者不承担任何责任。
## 支持与联系
- **问题反馈**: [GitHub Issues](https://github.com/SamFrieman/c2-beacon-detector/issues)
- **讨论**: [GitHub Discussions](https://github.com/SamFrieman/c2-beacon-detector/discussions)
- **安全问题**: 私下报告安全漏洞
## 路线图
### v2.1(当前版本)
- [x] 集成多源威胁情报
- [x] 机器学习模型集成
- [x] 高级报告 (PDF, HTML)
- [x] 历史分析比较
- [x] 自定义检测规则引擎
### v2.2(计划中)
- [ ] 实时数据包捕获支持 (WebRTC)
- [ ] Zeek/Suricata 日志解析
- [ ] 协同威胁狩猎功能
- [ ] 用于自动化的 REST API
- [ ] Docker 容器部署
- [ ] 高级 ML 模型(神经网络)
- [ ] 实时监控仪表盘
### v3.0(未来计划)
- [ ] 多会话关联分析
- [ ] 威胁行为者归因
- [ ] 自动化剧本响应
- [ ] 集成 SIEM 平台
- [ ] 移动应用版本
- [ ] 基于云的分析选项(选择性加入)
## 延伸阅读
### C2 检测资源
- [MITRE ATT&CK - 命令与控制](https://attack.mitre.org/tactics/TA0011/)
- [ThreatFox 文档](https://threatfox.abuse.ch/)
- [Cobalt Strike Beacon 分析](https://www.cobaltstrike.com/)
- [网络 Beacon 检测](https://www.sans.org/white-papers/)
### 安全领域的机器学习
- [网络流量中的异常检测](https://arxiv.org/abs/1901.03407)
- [用于网络安全的 ML](https://www.microsoft.com/security/blog/)
### 威胁情报
- [OSINT 框架](https://osintframework.com/)
- [Abuse.ch 项目](https://abuse.ch/)
## 统计数据




**为安全社区倾注 ❤️ 打造**
⭐ **如果本项目对您有帮助,请点个 Star!** ⭐
[报告 Bug](https://github.com/SamFrieman/c2-beacon-detector/issues) • [功能请求](https://github.com/SamFrieman/c2-beacon-detector/issues) • [文档](https://github.com/SamFrieman/c2-beacon-detector/wiki)
**版本 2.1.0** | 发布于 2025 年 1 月
标签:Apex, ATT&CK映射, C2检测, IP 地址批量处理, 多包管理, 多模态安全, 威胁情报, 开发者工具, 数据可视化, 机器学习, 网络安全, 自定义脚本, 速率限制处理, 隐私保护