bastiaan365/iot-threat-detector
GitHub: bastiaan365/iot-threat-detector
基于 Isolation Forest 机器学习算法的 IoT 设备网络异常检测工具,可实时分析流量或读取 pcap 文件,并提供 Flask 仪表板和多种告警输出。
Stars: 0 | Forks: 0
# IoT 威胁检测器
基于机器学习的 IoT 设备网络异常检测。开发这个项目的起因是我经常在智能家居设备所在的 VLAN 上看到异常流量——随机的 DNS 查询、连接到可疑 IP 地址,以及不应该在摄像头或恒温器上发生的各种奇怪行为。
使用 Isolation Forest 学习您网络中"正常"的行为模式,并标记任何偏离正常的行为。同时还包含针对已知模式(如 Mirai 扫描、C2 信标、暴力破解尝试等)的签名规则。
## 功能特性
- 实时捕获网络流量或读取 pcap 文件
- 基于正常网络行为训练机器学习模型,然后标记异常行为
- 针对已知 IoT 攻击签名进行模式匹配(基于 YAML,易于添加自定义规则)
- 通过 JSON、syslog 或 webhooks 发送告警
- 提供简洁的 Flask 仪表板用于快速查看
- 使用 Click 构建的命令行界面
## 架构设计
```
[Network tap / pcap] → [Packet parser] → [Feature extraction]
↓
┌───────────┴────────────┐
│ │
Isolation Forest Signature engine
(anomaly scores) (YAML rules)
│ │
└───────────┬────────────┘
↓
Alert manager
(dedup + export)
```
## 快速开始
```
git clone https://github.com/bastiaan365/iot-threat-detector.git
cd iot-threat-detector
pip install -e .
```
在可信流量上训练模型,然后进行扫描:
```
# train on a clean capture
iotdetect train --pcap baseline.pcap --output model.pkl
# scan new traffic
iotdetect scan suspicious.pcap --model model.pkl --output results.json
# or go live
iotdetect monitor --interface eth0 --model model.pkl
```
运行 `iotdetect --help` 查看所有选项。
## 签名规则
攻击模式存储在 `signatures/` 目录下的 YAML 文件中。当前覆盖的类型包括:
- 端口扫描和服务发现
- SSH/Telnet 暴力破解
- C2 信标(定期回连)
- DNS 隧道
- ARP 欺骗
- Mirai 风格传播
添加自定义规则很简单——只需按照现有文件的格式即可。
## 项目结构
```
iotdetect/
├── cli.py # CLI entry point
├── capture/ # Packet sniffing and pcap parsing
├── detection/ # Anomaly scoring + signature matching
├── models/ # Model training and serialization
├── alerts/ # Alert dedup, syslog, webhook export
├── dashboard/ # Flask web UI
└── utils/
signatures/ # YAML attack patterns
tests/ # pytest suite
examples/ # Sample configs and synthetic data generator
```
## 技术栈
Python 3.10+、scapy、scikit-learn、Flask、Click、PyYAML、numpy。
开发工具:pytest、black、pylint。
## 运行测试
```
pytest
pytest --cov=iotdetect tests/
```
## 备注
这个项目最初是周末的实验,当时我发现我的一个涂鸦智能插座每隔几分钟就会连接到随机中国 IP 地址。后来添加了签名引擎,因为我想要在机器学习评分之外有更确定性的检测方式。
它并不是要替代 Suricata 或 Zeek——可以把它想象为一个轻量级的、专注于 IoT 的辅助层,与这些工具配合使用。我把它运行在树莓派上监控 IoT VLAN。
## 相关项目
- [Homelab 基础设施](https://github.com/bastiaan365/homelab-infrastructure) — 运行本项目的网络环境
- [DNS 安全配置](https://github.com/bastiaan365/dns-security-setup) — DNS 过滤和监控
- [Grafana 仪表板](https://github.com/bastiaan365/grafana-dashboards) — 告警可视化
## 许可证
MIT
标签:AMSI绕过, Apex, Flask, IoT安全, Isolation Forest, pcap分析, Python, WSL, 威胁检测, 安全规则引擎, 安全运营, 密码管理, 异常检测, 恶意代码分类, 恶意流量检测, 扫描框架, 攻击签名检测, 无后门, 机器学习, 网络威胁情报, 网络安全, 自动化响应, 逆向工具, 隐私保护