-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooked_seq_ops.go
55 lines (49 loc) · 1.59 KB
/
hooked_seq_ops.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package derive
import (
"github.com/aquasecurity/libbpfgo/helpers"
"github.com/nextlinux/tracee/pkg/errfmt"
"github.com/nextlinux/tracee/pkg/events"
"github.com/nextlinux/tracee/pkg/events/parse"
"github.com/nextlinux/tracee/pkg/utils"
"github.com/nextlinux/tracee/types/trace"
)
// Struct names for the interfaces HookedSeqOpsEventID checks for hooks
// The show,start,next and stop operation function pointers will be checked for each of those
var NetSeqOps = [6]string{
"tcp4_seq_ops",
"tcp6_seq_ops",
"udp_seq_ops",
"udp6_seq_ops",
"raw_seq_ops",
"raw6_seq_ops",
}
var NetSeqOpsFuncs = [4]string{
"show",
"start",
"next",
"stop",
}
func HookedSeqOps(kernelSymbols helpers.KernelSymbolTable) DeriveFunction {
return deriveSingleEvent(events.HookedSeqOps, deriveHookedSeqOpsArgs(kernelSymbols))
}
func deriveHookedSeqOpsArgs(kernelSymbols helpers.KernelSymbolTable) deriveArgsFunction {
return func(event trace.Event) ([]interface{}, error) {
seqOpsArr, err := parse.ArgVal[[]uint64](&event, "net_seq_ops")
if err != nil || len(seqOpsArr) < 1 {
return nil, errfmt.WrapError(err)
}
hookedSeqOps := make(map[string]trace.HookedSymbolData, 0)
for i, addr := range seqOpsArr {
// text segment check is done in kernel, marked as 0
if addr == 0 {
continue
}
hookingFunction := utils.ParseSymbol(addr, kernelSymbols)
seqOpsStruct := NetSeqOps[i/4]
seqOpsFunc := NetSeqOpsFuncs[i%4]
hookedSeqOps[seqOpsStruct+"_"+seqOpsFunc] =
trace.HookedSymbolData{SymbolName: hookingFunction.Name, ModuleOwner: hookingFunction.Owner}
}
return []interface{}{hookedSeqOps}, nil
}
}