Skip to content

Commit 6676bad

Browse files
committed
Driver-eBPF: remove debug in make and Docs update
1 parent 3efec8d commit 6676bad

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

plugin/driver/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
# Hades Driver
1+
# Hades eBPF-Driver
22

3-
## 为何独立出 Driver 模块
3+
> Hades eBPF-Driver 是基于 eBPF 编写的 Hook 数据获取,是整个 Hades 最关键的部分。基于 tracee 做了大量的改造和修复,执行方式参考 Elkeid
44
5-
在一段时间的 eBPF 尝试之后, 发现了一些小问题:由于 BPF 的一些原因,我们无法像 LKM 一样任意操作锁等,导致其数据准确性会存在一定程度的偏差,同时在不同版本下的限制,让 BPF 在较低内核版本下会存在一定的兼容性问题。单独 driver 的原因,是希望 driver 这个模块的通用化,甚至可以作为插件直接下发到 Elkeid 中。
6-
7-
同样的,因为后续可能也会尝试去做 LKM 的方案,将 eBPF 从中剥离,而不是放在 Collector 模块中,我觉得会更加合理
5+
> Hades eBPF-Driver is a eBPF-driven kernel hooker which is the most important part of Hades. Driver is based on tracee and I do a lot of modification. Draw on Elkeid.
86
97
## eBPF 快速启动 (eBPF quick start)
108

119
> 环境要求:内核版本高于 4.18, golang 版本 >= 1.17。非常建议使用 ubuntu 21.04 或者以上版本, 可以减少环境配置的时间成本
1210
11+
> kernel version over 4.18 and >= 1.17 is required. OS like ubuntu 21.04 is recommanded since it's easier for testing
12+
1313
1. 下载 Hades 项目 (Download Hades)
14-
`git clone --recursive https://github.com/chriskaliX/Hades.git`
14+
15+
```bash
16+
git clone --recursive https://github.com/chriskaliX/Hades.git`
17+
```
1518

1619
2. 下载 Header,如果内核支持 BTF 可以跳过 (Download kernel header, skip if BTF is supported)
1720

@@ -30,21 +33,18 @@
3033

3134
- CORE 编译
3235

33-
`make core-debug`(结果输出至终端)
36+
`make core`
3437

3538
- 非 CO-RE 编译(从 kernel-header)
3639

37-
`make debug`(结果输出至终端)
40+
`make`
3841

3942
4. 运行(Run)
4043

41-
在 driver 目录下,会看见对应的 driver 文件,启动即可
42-
(driver file is generated in `Hades/plugin/driver`, or you can run `../driver`)
43-
44-
5. 过滤 id (Event filter)
44+
在 driver 目录下,会看见对应的 driver 文件,启动即可。
4545

46-
cmdline 支持 `-f` 选项,根据下面的 ID 可以指定 filter
47-
例如: `./driver -f 1031`, 只运行 `kprobe/security_file_ioctl` 即 anti_rootkit hook
46+
默认情况下不会有输出,指定 **`--env debug`** 可以看到输出
47+
(driver file is generated in `Hades/plugin/driver`, or you can run `../driver`, `--env debug` to get the output)
4848

4949
## 目前支持 Hook
5050

plugin/driver/eBPF/Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ EBPF_CO-RE_FLAG := core
33
EBPF_SOURCE_PATH = kern/hades_ebpf_driver.bpf.o
44
EBPF_SOURCE_CO-RE_PATH = kern/hades_ebpf_driver.bpf.core.o
55
EBPF_TARGET_PATH = user/hades_ebpf_driver.o
6-
GO_DEBUG_FLAG := -ldflags="-X hades-ebpf/user.Env=debug"
76
GO_TARGET_PATH := -o ../driver
87

98
no-core:
@@ -13,12 +12,4 @@ no-core:
1312
core:
1413
$(EBPF_BUILD) $(EBPF_CO-RE_FLAG)
1514
mv $(EBPF_SOURCE_CO-RE_PATH) $(EBPF_TARGET_PATH)
16-
go build $(GO_TARGET_PATH) .
17-
debug:
18-
$(EBPF_BUILD)
19-
mv $(EBPF_SOURCE_PATH) $(EBPF_TARGET_PATH)
20-
go build $(GO_DEBUG_FLAG) $(GO_TARGET_PATH) .
21-
core-debug:
22-
$(EBPF_BUILD) $(EBPF_CO-RE_FLAG)
23-
mv $(EBPF_SOURCE_CO-RE_PATH) $(EBPF_TARGET_PATH)
24-
go build $(GO_DEBUG_FLAG) $(GO_TARGET_PATH) .
15+
go build $(GO_TARGET_PATH) .

plugin/driver/eBPF/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
)
1717

1818
func main() {
19-
share.EventFilter = flag.String("filter", "0", "set filter to specific the event id")
19+
flag.StringVar(&share.EventFilter, "filter", "0", "set filter to specific the event id")
20+
flag.StringVar(&share.Env, "env", "prod", "specific the env, debug print the output to console")
2021
// parse the log
2122
flag.Parse()
2223
// zap configuration pre-set
@@ -37,7 +38,7 @@ func main() {
3738
zap.ReplaceGlobals(logger)
3839
zap.S().Info("Hades eBPF driver start")
3940
// allow init
40-
decoder.SetAllowList(*share.EventFilter)
41+
decoder.SetAllowList(share.EventFilter)
4142
// generate the main driver and run
4243
driver, err := user.NewDriver()
4344
if err != nil {
@@ -64,7 +65,7 @@ func main() {
6465
<-time.After(time.Second * 5)
6566
return
6667
case <-share.GContext.Done():
67-
if user.Env == "debug" {
68+
if share.Env == "debug" {
6869
// just for testing
6970
time.Sleep(5 * time.Second)
7071
continue

plugin/driver/eBPF/user/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func (d *Driver) dataHandler(cpu int, data []byte, perfmap *manager.PerfMap, man
167167
return
168168
}
169169
rawdata["data"] = result
170-
// TODO: just for debug
171-
if Env == "debug" {
170+
// for debug
171+
if share.Env == "debug" {
172172
fmt.Println(rawdata["data"])
173173
}
174174
// send the record

plugin/driver/eBPF/user/share/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var (
2121
)
2222

2323
var (
24-
EventFilter *string
24+
EventFilter string
25+
Env string
2526
)
2627

2728
func gtimeCron() {
@@ -36,8 +37,10 @@ func gtimeCron() {
3637
}
3738
}
3839

39-
// TODO: TEST FOR NOW
4040
func taskCron() {
41+
if Env == "debug" {
42+
return
43+
}
4144
for {
4245
task, err := Client.ReceiveTask()
4346
if err != nil {

0 commit comments

Comments
 (0)