NNienn/Radm
GitHub: NNienn/Radm
RADM 是一个基于 eBPF 的内核原生容器入侵检测系统,通过时空图自编码器实时检测并自动隔离多租户容器化基础设施中的受损容器。
Stars: 0 | Forks: 0
# ردم
**面向多租户容器化基础设施的高效内核级 IDS**
有关该系统能够防范及无法防范的内容的完整描述,请参阅[详细分解](RADM_SPEC.md)。
*radm(阿拉伯语:ردم):意为巨大的、坚不可摧的障碍物、水坝或城墙。*
*这个名字完美地描述了本系统对受损容器的处置方式。*
## 概述
**RADM** 是一个面向容器化工作负载的内核原生入侵检测系统。它使用 eBPF 挂钩 Linux 内核——在零代理安装和零容器修改的情况下监控所有容器的 syscall 和网络活动——并在 160ms 内自主隔离受损容器。
该系统监控内存操作原语(`mprotect`、`mmap`、`ptrace`、`memfd_create`)以及容器间的网络流,跨所有工作负载构建实时时空行为图,并在宿主机层面而非孤立的单个容器层面检测入侵。
## 运行时模式
- **Linux(完整数据面)** — eBPF tracepoint、TC hook、XDP 和 Unix domain socket 全面激活。需要内核 5.15+,并支持 BTF/CO-RE 和 cgroup v2。
- **非 Unix(mock 模式)** — 用于本地开发和 pipeline 验证。Rust 服务启动后,会生成合成事件,并在不附加内核的情况下测试完整的 pipeline 逻辑。
## 架构
```
┌─────────────────────────────────────────────────────────────────┐
│ Linux Kernel │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ radm_tp │ │ radm_tc │ │ radm_xdp │ │
│ │ Syscall │ │ Network │ │ DDoS │ │
│ │ Probes │ │ Monitor │ │ Gate │ │
│ └────┬─────┘ └────┬─────┘ └──────────┘ │
│ │ │ │
│ └──────┬───────┘ │
│ ▼ │
│ ┌─────────────┐ ┌────────────────┐ │
│ │ Ring Buffer │ │ quarantine_map │ │
│ │ (16 MB) │ │ (BPF Hash) │ │
│ └──────┬──────┘ └───────▲────────┘ │
└───────────────┼──────────────────────┼──────────────────────────┘
│ │
════════╪══════════════════════╪════════ User / Kernel
▼ │
┌───────────────────────────┐ │
│ Aggregator (Rust) │ │
│ │ │
│ Ring Buffer Consumer │ │
│ Sliding-Window Graph │ │
│ Protobuf Serialization │ │
│ UDS Server │ │
└────────────┬──────────────┘ │
│ GraphSnapshot │
▼ │
┌───────────────────────────┐ │
│ Inference (Python) │ │
│ │ │
│ ST-GAE Encoder/Decoder │ │
│ GRU Temporal Layer │ │
│ Isolation Forest │ │
│ Threat Classification │ │
└────────────┬──────────────┘ │
│ AnomalyAlert │
▼ │
┌───────────────────────────┐ │
│ Mitigation (Rust) │──────────┘
│ │ Updates quarantine_map
│ TC Filter Quarantine │
│ Forensic Memory Dump │
│ AES-GCM Encryption │
└───────────────────────────┘
```
## 项目结构
```
ردم/
├── kernel/ # eBPF programs (C)
│ └── src/
│ ├── radm_tp.c # Syscall tracepoint monitors
│ ├── radm_tc.c # TC network monitor + quarantine enforcement
│ ├── radm_xdp.c # XDP early packet drop (DDoS gate)
│ ├── radm_types.h # Shared event struct (48 bytes, static-asserted)
│ ├── radm_maps.h # BPF map declarations
│ └── radm_helpers.h # Rate limiter, hash, event emission
│
├── aggregator/ # Ring buffer consumer + graph builder (Rust)
│ └── src/
│ ├── main.rs # Entry point, async runtime
│ ├── ring_reader.rs # BPF ring buffer consumer via aya
│ ├── graph_builder.rs # 5-second sliding-window graph construction
│ ├── uds_server.rs # Unix Domain Socket server for inference
│ ├── cgroup_resolver.rs # cgroup_id → container name resolution
│ ├── config.rs # Configuration schema
│ └── types.rs # Rust-side event types
│
├── inference/ # Detection engine (Python)
│ └── src/
│ ├── main.py # Entry point
│ ├── model.py # ST-GAE: GATv2 encoder + GRU temporal + decoder
│ ├── trainer.py # Offline training pipeline
│ └── detector.py # Online detection loop
│
├── mitigation/ # Quarantine + forensics (Rust)
│ └── src/
│ ├── main.rs # Entry point
│ ├── control.rs # Alert consumer, quarantine orchestration
│ ├── quarantine.rs # TC filter attachment, BPF map updates
│ └── forensics.rs # AES-GCM encrypted memory dump
│
├── proto/
│ └── radm.proto # Protobuf schema (all IPC messages)
│
├── scripts/
│ ├── radm-ctl.sh # Lifecycle manager (start/stop/status)
│ └── simulate-attack.sh # Multi-stage attack simulator
│
├── config/
│ └── radm.toml # Runtime configuration
│
├── tests/
│ ├── unit/
│ │ └── inference/
│ │ └── test_model.py
│ └── integration/
│ └── docker-compose.test.yml
│
├── Makefile # Build orchestration
└── RADM_SPEC.md # Full engineering specification (v1.0)
```
## 核心 Pipeline
1. **内核** — syscall tracepoint 在 `mprotect`、`mmap`、`ptrace` 和 `memfd_create` 上触发,向 16MB 的无锁 BPF ring buffer 中发送 48 字节的 `radm_event` 结构体。容器 veth 对上的 TC hook 捕获网络元数据,并通过 `TC_ACT_SHOT` 实施隔离。XDP 对宿主机网卡进行门控,以便尽早进行 DDoS 级别的丢弃。
2. **聚合器** — Rust 聚合器从 ring buffer 中消费事件,通过 `/proc` 将 `cgroup_id` 解析为容器身份,并维护一个 5 秒的滑动窗口行为图。快照被序列化为 Protobuf,并通过 Unix Domain Socket 流式传输到推理引擎。
3. **推理** — Python 引擎接收 `GraphSnapshot` protobuf,通过时空图自编码器(GATv2 空间编码器 + GRU 时间层)进行处理,计算每个节点的重建误差,并通过 Isolation Forest 对入侵进行分类。警报以 `AnomalyAlert` protobuf 的形式发出。
4. **缓解** — Rust 缓解面接收警报,将 TC BPF 过滤器附加到目标容器的 veth 对上,更新 `quarantine_map` 以丢弃所有流量,并可选择执行 AES-GCM 加密的取证内存转储。
## 要求
### Linux(完整数据面)
- Linux 内核 >= 5.15(BTF/CO-RE, cgroup v2)
- `clang` >= 15, `bpftool`, `tc`, `ip`
- Rust >= 1.70(`rustc`, `cargo`)
- Python >= 3.10,以及 PyTorch >= 2.0 和 PyTorch Geometric
- `protoc`(Protocol Buffers 编译器)
- 具有基于 veth 网络的容器运行时
### 本地开发(非 Unix)
- Rust 工具链
- Python 3.12
- `numpy`, `protobuf`, `pyyaml`, `scikit-learn`, `pytest`
代码库包含轻量级的推理兼容性垫片,以便测试可以在没有完整 PyTorch 安装的限制性宿主机上运行。
## 构建
```
# 完整 build (eBPF + Rust + Protobuf bindings)
make all
# 仅 Rust 组件
cargo build --manifest-path aggregator/Cargo.toml
cargo build --manifest-path mitigation/Cargo.toml
# Python 单元测试
python -m pytest tests/unit/inference -q
```
## 使用方法
```
# 启动完整 pipeline
sudo ./scripts/radm-ctl.sh start
# 检查状态
sudo ./scripts/radm-ctl.sh status
# 运行 attack simulator (需要 Docker)
sudo ./scripts/simulate-attack.sh
# 停止 pipeline
sudo ./scripts/radm-ctl.sh stop
```
在非 Unix 宿主机上,Rust 服务会自动以 mock 模式启动——聚合器会生成合成快照,缓解面会在不附加内核的情况下测试隔离流程。
## 配置
- `radm.toml` — 所有服务使用的运行时配置
- `config/radm.default.toml` — 打包的默认配置
- `proto/radm.proto` — 所有 IPC 消息 schema 的唯一事实来源
- `/var/radm` — 生产环境中推理 checkpoint 和基线数据的预期存放位置
## 威胁模型
RADM 旨在检测 **IPv4 cgroup v2 环境中的内存注入技术及异常的容器间网络行为**。有关系统检测的内容、明确无法防范的内容以及已知权衡的完整分解,请参阅 [RADM_SPEC.md](RADM_SPEC.md)。
## 注意事项
- 不支持 Cilium — 它拥有 eBPF datapath 并与 RADM 的 TC hook 冲突。
- 完整的数据面需要 Linux 宿主机。Windows/macOS 开发仅使用 mock 模式。
## 许可证
MIT 许可证。标签:Rust, Web截图, 凭据扫描, 可视化界面, 安全, 容器安全, 网络流量审计, 超时处理, 逆向工具