Scorpio21Sec/Sentinel-Go
GitHub: Scorpio21Sec/Sentinel-Go
一款基于 eBPF 与 Isolation Forest 的内核级实时安全监测系统,用于检测异常系统行为。
Stars: 2 | Forks: 0
# SentinelGo 🛡️
**OS-Level AI Security System** — eBPF + Go + Python Isolation Forest
## 架构
```
┌─────────────────────────────────────────────────────────┐
│ Linux Kernel │
│ │
│ execve ──┐ │
│ openat ──┤── eBPF tracepoints ──► Ring Buffer │
│ connect ─┤ (C/BPF) │
│ clone ──┘ │
└─────────────────────┬───────────────────────────────────┘
│ BpfEvent (binary)
▼
┌─────────────────────────────────────────────────────────┐
│ Go Pipeline │
│ │
│ Collector ──► channel ──► Extractor ──► channel │
│ (ring buf (buf=512) (5s window) (buf=20) │
│ reader) │
│ FeatureVector │
│ │ │
│ HTTP POST ▼ │
└────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Python FastAPI │
│ │
│ POST /predict ──► IsolationForest.predict() │
│ │ │
│ ▼ │
│ {"anomaly_score": -0.35, │
│ "is_anomaly": true} │
└─────────────────────────────────────────────────────────┘
│
▼
🚨 ALERT printed to terminal
```
## 仓库结构
```
sentinelgo/
├── cmd/sentinel/ # Main Go binary entry point
├── internal/
│ ├── collector/ # eBPF loader + ring buffer reader
│ ├── extractor/ # Feature extraction (5s windows)
│ └── sender/ # HTTP client + alert display
├── ebpf/
│ └── sentinel.bpf.c # eBPF C program (syscall hooks)
├── ml/
│ ├── server.py # FastAPI + Isolation Forest server
│ ├── topic6_isolation_forest.py # standalone ML demo
│ └── requirements.txt
├── netsentry/
│ └── netsentry.py # Network-level anomaly detector (Scapy)
├── scripts/
│ └── simulate_attack.sh # Demo attack simulator
├── topic1_basics/ # Topic 1 mini-task
├── topic2_concurrency/ # Topic 2 mini-task
├── topic5_features/ # Topic 5 mini-task
├── topic7_http/ # Topic 7 mini-task
└── go.mod
```
## 快速启动
### 1. Python ML 服务
```
cd ml
pip install -r requirements.txt
python server.py
# 服务器运行在 http://localhost:8000
# 启动时在合成正常数据上自动训练
```
### 2. Go 管道(stub 模式 — 无需内核)
```
go build ./cmd/sentinel
sudo ./sentinel --stub --api=http://localhost:8000
```
### 3. 真实 eBPF 模式(Linux 内核 5.8+)
```
# 安装构建依赖项 (Ubuntu 22.04)
sudo apt install clang llvm libbpf-dev linux-headers-$(uname -r) linux-tools-common
# 为您的内核生成 vmlinux.h
bpftool btf dump file /sys/kernel/btf/vmlinux format c > ebpf/vmlinux.h
# 编译 eBPF 对象
clang -O2 -g -Wall -target bpf \
-D__TARGET_ARCH_x86 \
-I/usr/include/bpf \
-c ebpf/sentinel.bpf.c -o ebpf/sentinel.bpf.o
# 运行
go build ./cmd/sentinel
sudo ./sentinel --ebpf-obj=./ebpf/sentinel.bpf.o
```
### 4. 触发告警(演示)
在 SentinelGo 运行后,打开第二个终端执行:
```
bash scripts/simulate_attack.sh
```
你应该会在 SentinelGo 终端看到红色告警框。
## 提取的功能特性
| Feature | Description | Malware Signal |
|---|---|---|
| `exec_count` | 每窗口期新进程数 | 进程注入、恶意软件创建子进程 |
| `fork_rate` | clone/fork 调用频率 | 分叉炸弹、快速复制 |
| `unique_procs` | 不同进程名数量 | 异常二进制文件执行 |
| `unique_files_opened` | 访问的不同文件数 | 勒索软件文件枚举 |
| `sensitive_file_hits` | 访问 `/etc/`、`/root/`、`.ssh/` 等敏感路径 | 凭据窃取 |
| `total_open_calls` | openat 调用总数 | 批量文件扫描 |
| `new_connections` | 外部 connect() 调用 | C2 回连、数据外泄 |
## 运行小型任务
```
# 主题 1 — Go 基础
go run topic1_basics/main.go
# 主题 2 — Goroutines + 通道
go run topic2_concurrency/main.go
# 主题 5 — 特征提取
go run topic5_features/main.go
# 主题 6 — 孤立森林独立版 (Python)
python ml/topic6_isolation_forest.py
# 主题 7 — Go HTTP → Python 测试 (服务器必须运行)
go run topic7_http/main.go
# 主题 8 — NetSentry (存根模式)
python netsentry/netsentry.py --stub
```
## 为何选择 eBPF?
- 在内核空间运行 — 无法被用户态 rootkit 规避
- 微秒级精度 — 可捕获短暂存在的恶意进程
- 无需内核模块 — 通过内核验证器保证安全
- 对不匹配事件零开销
## 为何选择 Isolation Forest?
- **无监督** — 无需标记的恶意样本
- 学习正常行为并标记偏差
- 高效处理高维特征向量
- 可解释:每个特征贡献可被检查
- 快速:训练 O(n log n),推理 O(log n)
## 面试快速参考
**“30 秒项目介绍”**
**“为什么不直接轮询 /proc?”**
## 许可证
MIT
标签:0day挖掘, Apex, Caido项目解析, Docker镜像, EVTX分析, Go Pipeline, Go语言, Hpfeeds, Isolation Forest, Python, SEO: AI安全, SEO: eBPF安全, SEO: 内核监控, 事件采集, 内核安全, 安全态势感知, 异常检测, 操作系统安全, 无后门, 无监督学习, 日志审计, 机器学习, 特征向量, 环形缓冲区, 程序破解, 系统调用, 网络安全, 逆向工具, 隐私保护