Sam-k-001/covert-channel-detection-system
GitHub: Sam-k-001/covert-channel-detection-system
基于 FastAPI 和 Scapy 的实时网络隐蔽信道检测系统,通过熵分析和协议检查识别并可视化 ICMP、DNS、HTTP 协议中的数据外泄行为。
Stars: 0 | Forks: 0
# 🛡️ 实时隐蔽信道检测系统
一个可用于生产环境的系统,可实时检测 ICMP、DNS 和 HTTP 隐蔽信道,并配备了由 WebSocket 驱动的实时网络安全仪表板。
## 架构
```
┌─────────────────────────────────────────────────────────────┐
│ Browser → dashboard (HTML/CSS/JS) │
│ ↕ WebSocket (ws://localhost:8000/ws) │
│ Backend → FastAPI + scapy sniffer │
│ ↕ │
│ Sender → ICMP / DNS / HTTP covert packets │
│ Receiver → HTTP server (port 8080) │
└─────────────────────────────────────────────────────────────┘
```
## 项目结构
```
project/
├── detector/
│ ├── main.py # FastAPI app + WebSocket endpoint
│ ├── packet_sniffer.py # Scapy sniffer (daemon thread, auto-restart)
│ ├── detection_engine.py # ICMP / DNS / HTTP detection logic
│ ├── logger.py # File + console alert logging
│ ├── websocket_server.py # ConnectionManager (broadcast to all clients)
│ ├── utils.py # Entropy, base64, fingerprint helpers
│ └── config.yaml # All configuration knobs
├── sender/
│ ├── icmp_sender.py # Interactive ICMP covert-channel sender
│ ├── dns_sender.py # Interactive DNS covert-channel sender
│ ├── http_sender.py # Interactive HTTP covert-channel sender
│ └── utils.py # Shared encoding utilities
├── receiver/
│ └── http_server.py # Flask HTTP endpoint (target for HTTP sender)
├── dashboard/
│ ├── index.html # Dashboard UI
│ ├── style.css # Dark cybersecurity theme
│ └── script.js # WebSocket client + live rendering
├── logs/
│ └── alerts.log # Auto-created JSON-lines log
├── requirements.txt
└── README.md
```
## 检测功能
| 协议 | 检测方法 |
|----------|-----------------|
| **ICMP** | 特征 ID `0xBEEF`,高 payload 熵,base64 payload 解码 |
| **DNS** | 高熵子域名,base64 编码标签,可疑关键词,单 IP 高查询率,从分片查询中重建完整消息 |
| **HTTP** | URL query 参数中的 base64,长 query 字符串,高熵路径,可疑路径前缀 |
## 设置
### 1 — 安装依赖项
```
cd project/
pip install -r requirements.txt
```
### 2 — 运行后端(需要 root 权限以进行 raw-socket 捕获)
```
sudo python3 -m detector.main
```
你应该会看到:
```
[HH:MM:SS] INFO ═══ Covert Channel Detection System starting ═══
[HH:MM:SS] INFO PacketSniffer thread started (iface=lo, filter=…)
[HH:MM:SS] INFO Backend ready – WebSocket: ws://localhost:8000/ws
INFO: Uvicorn running on http://0.0.0.0:8000
```
### 3 — 打开仪表板
打开浏览器并导航至:
```
http://localhost:8000/
```
你将看到深色网络安全仪表板,所有统计卡片均为零,表格为空,等待告警。
### 4 — (仅限 HTTP)启动 HTTP 接收器
在**单独的终端**中(无需 root 权限):
```
python3 receiver/http_server.py
```
### 5 — 发送隐蔽消息
#### ICMP 发送器(需要 root 权限)
```
sudo python3 sender/icmp_sender.py
```
```
Enter secret message: Hello from ICMP channel!
```
检测器将立即在仪表板上引发告警。
#### DNS 发送器
```
python3 sender/dns_sender.py
```
```
DNS Server IP [127.0.0.1]: 127.0.0.1
Enter secret message: Exfiltrating via DNS!
```
#### HTTP 发送器
```
python3 sender/http_sender.py
```
```
Receiver IP [127.0.0.1]: 127.0.0.1
Enter secret message: Hiding data in HTTP!
```
## 配置
编辑 `detector/config.yaml` 来调整系统:
```
network:
interface: "lo" # Change to eth0, wlan0, etc.
bpf_filter: "icmp or udp port 53 or tcp port 80 or tcp port 8080"
detection:
entropy_threshold: 3.5 # Alerts triggered above this bits/char
icmp:
enabled: true
magic_id: 48879 # 0xBEEF
dns:
enabled: true
max_query_frequency: 10 # queries per minute before rate alert
high_entropy_threshold: 3.8
http:
enabled: true
min_param_length: 16 # min chars in param value to inspect
```
## 仪表板面板
| 面板 | 描述 |
|-------|-------------|
| **统计卡片** | 实时计数:ICMP、DNS、总计、高熵、已解码 |
| **告警表格** | 时间戳、协议、IP、熵、原因、解码后的消息 |
| **实时信息流** | 右侧随告警到达实时显示的流 |
| **熵图表** | 每个 IP 的平均 Shannon 熵条形图可视化 |
## REST API
| Endpoint | 描述 |
|----------|-------------|
| `GET /api/alerts?limit=200` | 历史告警 JSON |
| `GET /api/stats` | 聚合计数 |
| `GET /api/entropy` | 每个 IP 的当前熵快照 |
| `DELETE /api/alerts` | 清除告警历史记录 |
| `WS /ws` | WebSocket 数据流 |
## 故障排除
| 问题 | 解决方案 |
|---------|-----|
| 嗅探器提示 `Permission denied` | 使用 `sudo` 运行后端 |
| 仪表板未连接 | 确保后端正在 8000 端口上运行 |
| 未出现 HTTP 告警 | 首先启动 `receiver/http_server.py` |
| 无 DNS 告警 | 确保接口为 `lo` 且发送器目标为 `127.0.0.1` |
| 未找到 Scapy | `pip install scapy` |
## 去重
每个告警都通过对关键数据包字段
(src IP、dst IP、seq number / qname / URL)进行 MD5 计算来生成指纹。
重复的数据包仅会产生一个告警。
## 日志记录
所有告警都将作为 JSON lines 写入 `logs/alerts.log`。
该文件在首次运行时自动创建。
```
{"id": "…", "timestamp": "…", "protocol": "ICMP", "src_ip": "127.0.0.1", …}
```
标签:AV绕过, FastAPI, IP 地址批量处理, Scapy, 多模态安全, 数据可视化, 流量检测, 网络安全, 逆向工具, 隐私保护, 隐蔽信道