面向Linux服务器的内核级安全与攻击响应。
面向 Linux 服务器的内核级流量智能与威胁修复。
KernelEye 是一个面向 Linux 服务器的自托管安全监控平台。它在 Go 代理中使用 eBPF、TC 和 XDP 来观测网络元数据、对可疑活动进行评分,并通过内核级 XDP 阻断和 ipset/iptables 规则实施修复。Go 后端负责存储和分析事件,React 仪表盘则提供服务管理、实时流量、威胁视图、已封禁 IP、白名单、报告和分析功能。
shared/scoring 中共享的 Go 评分逻辑进行威胁评分。Monitored Linux host
eBPF traffic probe + TC bandwidth hooks
XDP firewall and ipset/iptables remediation
Go agent (HMAC command verification, audit log)
|
| gRPC (TLS/mTLS) + HMAC-signed block commands
v
Go backend API
Fiber HTTP API
gRPC ingest/block services (TLS/mTLS, command signing)
analysis worker, block manager, retention, reports
integrity report handler
|
v
PostgreSQL
^
|
React dashboard
REST API + WebSocket live updates
Agent 位于 agent/ 目录,是 Linux 主机进程。
agent/main.go 启动注册、eBPF 加载、带宽跟踪、修复、评分、聚合以及阻断命令流式传输。agent/ebpf/traffic_probe.c 捕获流量元数据。agent/ebpf/xdp_firewall.c 实现 XDP 数据包过滤。agent/tc.go 配置 TC 带宽跟踪。agent/aggregator.go 批量聚合事件并将其刷新到后端。agent/history_store.go 和 agent/flush.go 处理本地持久化和重试行为。agent/remediation/ 包含分析器、自动阻断、XDP、ipset 和混合修复器。Agent 需要 Linux 环境以及执行 eBPF/XDP 操作所需的提升权限。
后端位于 backend/ 目录。
backend/cmd/api/main.go 启动 Fiber HTTP API 和 gRPC 服务。backend/internal/api/ 包含认证、仪表盘处理器、gRPC 处理器、阻断 API、白名单 API、WebSocket 处理和速率限制。backend/internal/analysis/ 包含评分工作器、阻断管理、数据保留和月度报告逻辑。backend/internal/database/ 包含 sqlc 生成的数据库访问代码。backend/internal/geoip/ 处理 GeoIP 富化。backend/internal/email/ 在配置后发送由 Mailtrap 支持的邮件。backend/migrations/ 包含 PostgreSQL 迁移。HTTP 默认端口为 8080;gRPC 默认端口为 9091。
仪表盘位于 dashboard/ 目录,是一个 Vite React 应用。
dashboard/src/pages/ 包含概览、服务器、服务器详情、威胁、告警、报告、可视化器、已阻断 IP、白名单、登录、个人资料和 OAuth 回调页面。dashboard/src/components/ 包含实时流量、阻断信息流、图表、服务器列表、配置器和共享布局组件。dashboard/src/api/client.ts 定义 REST API 客户端。dashboard/src/context/WebSocketContext.tsx 管理实时事件更新。开发服务器配置为 http://localhost:3000。
公开营销站点位于 kerneleye-landing-page/。生产前端镜像会同时构建落地页和仪表盘,然后通过 nginx 提供服务。
shared/scoring/ 包含 Agent 和后端共用的威胁评分模块。shared/cmdsigning/ 包含 HMAC-SHA256 命令签名和 nonce 重放防护模块。proto/kerneleye/v1/ 包含用于摄取和阻断服务的 protobuf 定义。proto/gen/go/ 包含生成的 Go protobuf 代码。KernelEye 不会检查数据包载荷或应用内容。
收集的元数据包括:
不收集:
威胁评分在 shared/scoring/scorer.go 中实现。当前评分器比单一线性公式更为精细:它会考虑 SYN 速率、唯一端口访问、失败握手、突发行为、服务滥用、方向、置信度以及随时间衰减的分数。
默认分类阈值:
< 20 normal
20-39 suspicious
>= 40 malicious
>= 40 eligible for auto-blocking when remediation is enabled
后端分析工作进程同样使用累积的流量窗口,并可对高风险来源触发封禁管理。
KernelEye 在 agent 上启用后支持主动修复。
| 层级 | 实现 | 用途 |
|---|---|---|
| XDP | agent/remediation/xdp_remediator.go | 在网络栈之前进行快速内核级丢弃 |
| IPSet | agent/remediation/ipset_remediator.go | ipset/iptables 封禁管理 |
| 混合 | agent/remediation/hybrid_remediator.go | 协调 XDP 与 ipset 行为 |
| 自动封禁器 | agent/remediation/auto_blocker.go | 封禁评分超过配置阈值的来源 |
| 后端封禁管理器 | backend/internal/analysis/block_manager.go | 协调后端生成的封禁状态与命令 |
仪表盘还提供被封禁 IP 和白名单管理功能。
cp .env.example .env
至少设置:
DATABASE_URL=postgres://kerneleye:<password>@localhost:5432/kerneleye?sslmode=disable
JWT_SECRET=<at-least-32-characters>
API_KEY_SECRET=<strong-secret>
CORS_ORIGINS=http://localhost:3000
可选集成包括 Redis 速率限制、Mailtrap 邮件、GitHub/Google OAuth 以及 MaxMind GeoIP。
cd backend
go mod download
go run cmd/api/main.go
后端启动:
http://localhost:8080localhost:9091cd dashboard
npm install
npm run dev
打开 http://localhost:3000。
登录仅支持 OAuth。设置 AUTH_OWNER_EMAIL 并配置至少一个 OAuth 提供方(GitHub 或 Google)以访问仪表盘。仅允许配置的所有者邮箱登录。
cd agent
bpftool btf dump file /sys/kernel/btf/vmlinux format c > ebpf/vmlinux.h
go generate ./...
go build -o kerneleye-agent
sudo KERNELEYE_API_KEY=<server-api-key> \
KERNELEYE_SERVER=localhost:8080 \
KERNELEYE_GRPC_URL=localhost:9091 \
./kerneleye-agent
有用的 agent 标志:
-enable-remediation enable active blocking and auto-blocking
-xdp enable XDP fast-path blocking
-interface <name> select XDP network interface
--read-only monitor and report only, never block
--insecure disable TLS (dev only)
--tls-ca-file <path> backend CA certificate for TLS verification
--tls-cert-file <path> agent client certificate for mTLS
--tls-key-file <path> agent client private key for mTLS
-list-blocked print current ipset state and exit
-flush-blocklists flush ipset and XDP blocklists and exit
-clear-data remove local agent SQLite stores and exit
-version print build version
当设置了 --enable-remediation 时,必须在 agent 和 backend 上都配置 CMD_SIGNING_KEY。使用 openssl rand -base64 32 生成。
kerneleye/
├── agent/ Go eBPF/XDP monitoring agent
│ ├── ebpf/ eBPF C programs and compiled objects
│ ├── remediation/ analyzer, XDP, ipset, hybrid remediation
│ ├── assets/ embedded XDP object assets
│ └── scripts/ ipset helper scripts and service files
├── backend/ Go Fiber API and gRPC backend
│ ├── cmd/api/ backend entrypoint
│ ├── internal/api/ HTTP, auth, WebSocket, gRPC, block APIs
│ ├── internal/analysis/ workers, blocking, retention, reports
│ ├── internal/database/ sqlc generated queries and helpers
│ ├── internal/email/ Mailtrap email service
│ ├── internal/geoip/ MaxMind GeoIP service
│ └── migrations/ PostgreSQL migrations
├── dashboard/ React dashboard app
├── kerneleye-landing-page/ React landing page app
├── proto/ protobuf definitions and generated Go code
├── shared/
│ ├── scoring/ shared threat scoring Go module
│ └── cmdsigning/ HMAC command signing and nonce tracking
├── docs/ additional project documentation
├── tests/ traffic simulation shell scripts
├── docker/ frontend nginx and install script templates
├── Dockerfile.backend backend container build
├── Dockerfile.frontend landing + dashboard + agent download image
├── docker-compose.yml production-oriented compose stack
└── Makefile generation, build, and docker targets
| 层级 | 技术 |
|---|---|
| Agent | Go、cilium/ebpf、XDP、TC、gRPC、SQLite 本地存储、zap |
| 后端 | Go、Fiber、gRPC、PostgreSQL、sqlc、Redis、Mailtrap |
| 仪表盘 | React、TypeScript、Vite、Ant Design、React Query、Recharts |
| 落地页 | React、TypeScript、Vite、Tailwind CSS |
| 协议 | Protobuf、gRPC |
| 部署 | Docker、Docker Compose、nginx、Traefik 标签 |
KernelEye agent 已在以下配置上完成测试。随着新环境通过验证,本表将持续更新。