1v4mp1r3/ebpf-rootkit-detector-lab
GitHub: 1v4mp1r3/ebpf-rootkit-detector-lab
Rootwatch 是一个基于 eBPF 和 Go 回放引擎的防御性 Linux rootkit 检测实验室,通过规则引擎从内核事件流中识别 rootkit 风格行为信号。
Stars: 0 | Forks: 0
# Rootwatch:eBPF Rootkit 检测实验室
Rootwatch 是一个防御性的 Linux 监控实验室,旨在从内核事件中发现 rootkit 风格的信号。它侧重于一个可以在任何地方进行测试的、简洁的用户态检测 pipeline,外加一个仅限 Linux 的 eBPF 探针草案,用于真实的 exec/open/connect 收集。
本项目刻意保持安全:没有隐匿行为,没有持久化,没有漏洞利用代码,没有未经授权的扫描。它专为蓝队学习、VM 实验室和检测工程实践而构建。
## 检测内容
- 遥测上报但在 procfs 中不可见的进程。
- 从临时文件系统(如 `/tmp` 或 `/dev/shm`)启动的可执行文件。
- 衍生出 shell 的服务进程。
- 针对敏感路径(如 `/etc/ld.so.preload`)的写入类 open 操作。
- 从配置的基线向可疑端口发起的出站连接。
## 快速开始
```
go test ./...
go run ./cmd/rootwatch replay --events examples/events.ndjson --rules examples/rules.json
go run ./cmd/rootwatch metrics --events examples/events.ndjson --rules examples/rules.json
```
编写报告:
```
go run ./cmd/rootwatch replay \
--events examples/events.ndjson \
--rules examples/rules.json \
--json report.json \
--html report.html \
--text report.txt
```
构建:
```
go build -o bin/rootwatch ./cmd/rootwatch
```
## CLI
```
rootwatch replay --events examples/events.ndjson [--rules examples/rules.json] [--json report.json] [--html report.html]
rootwatch metrics --events examples/events.ndjson [--rules examples/rules.json]
rootwatch version
```
`replay` 评估 NDJSON 事件流,并生成文本、JSON 或 HTML 输出。`metrics` 发出用于事件和发现计数的 Prometheus 文本展示格式。
## 事件格式
每一行都是一个 JSON 事件:
```
{"ts":"2026-06-24T09:16:10Z","type":"connect","pid":1555,"ppid":920,"uid":33,"comm":"bash","path":"/bin/bash","dst_ip":"203.0.113.10","dst_port":4444,"protocol":"tcp","container":"web"}
```
支持的事件类型:
- `exec`
- `open`
- `connect`
Linux 收集器应在将 ring-buffer 记录交给规则引擎之前,将其标准化为相同的结构。
## 架构
```
flowchart LR
A["Linux eBPF probes"] --> B["Ring buffer"]
B --> C["Userspace normalizer"]
C --> D["Rule engine"]
D --> E["JSON / HTML / text reports"]
D --> F["Prometheus metrics"]
```
该仓库内置了可移植的 replay 模式,因此测试和演示可以在 Windows、macOS 和 Linux 上运行。`bpf/rootwatch.bpf.c` 文档记录了实际 eBPF 收集器的 Linux tracepoint 方向。
## 示例输出
```
[critical] Process is not visible through procfs (hidden-process)
The event stream reports an executed process that does not appear in procfs.
Event: kworker[1777] exec /tmp/.cache/.kworker
```
## Linux eBPF 实验室
有关内核要求和推荐的 `clang`/`bpftool` 工作流,请参阅 [docs/linux-ebpf.md](docs/linux-ebpf.md)。
推荐环境:
- Ubuntu 24.04 或 Debian 12 VM
- 带有 BTF 的 Linux kernel 6.x
- clang/llvm
- bpftool
- libbpf 头文件或 cilium/ebpf 生成
## 仓库布局
```
cmd/rootwatch/ CLI entrypoint
internal/events/ NDJSON event model and reader
internal/rules/ Detection rules and baseline config
internal/report/ Text, JSON and HTML reports
internal/metrics/ Prometheus metric rendering
bpf/ Linux-only eBPF probe sketch
examples/ Fixture stream and baseline rules
docs/ Architecture and Linux notes
```
## 安全范围
请仅在您拥有或获得明确授权监控的主机、container 和 VM 上使用 Rootwatch。本项目是一个防御性检测实验室,不包含用于隐藏进程、加载未经授权的 kernel module、持久化、凭据访问或漏洞利用的代码。
## 开发
```
go test ./...
go run ./cmd/rootwatch replay --events examples/events.ndjson --rules examples/rules.json
go run ./cmd/rootwatch metrics --events examples/events.ndjson --rules examples/rules.json
```
## 许可证
MIT
标签:API接口, Docker镜像, EVTX分析, Go, Linux内核监控, Ruby工具, TLS, 日志审计, 网络信息收集, 自定义请求头, 防御工具