forked from aquasecurity/tracee
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
107 lines (100 loc) · 2.36 KB
/
main.go
File metadata and controls
107 lines (100 loc) · 2.36 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/aquasecurity/tracee/tracee"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "Tracee",
Usage: "Trace OS events and syscalls using eBPF",
Action: func(c *cli.Context) error {
if c.Bool("list") {
printList()
return nil
}
cfg, err := tracee.NewConfig(
c.StringSlice("events-to-trace"),
c.Bool("container"),
c.Bool("detect-original-syscall"),
c.Bool("show-exec-env"),
c.String("output"),
)
if err != nil {
return fmt.Errorf("error creating Tracee config: %v", err)
}
t, err := tracee.New(*cfg)
if err != nil {
// t is being closed internally
return fmt.Errorf("error creating Tracee: %v", err)
}
return t.Run()
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Value: "table",
Usage: "output format: table (default)/json",
},
&cli.StringSliceFlag{
Name: "events-to-trace",
Aliases: []string{"e"},
Value: nil,
Usage: "trace only the specified events and syscalls",
},
&cli.BoolFlag{
Name: "list",
Aliases: []string{"l"},
Value: false,
Usage: "just list tracable events",
},
&cli.BoolFlag{
Name: "container",
Aliases: []string{"c"},
Value: false,
Usage: "trace only containers",
},
&cli.BoolFlag{
Name: "detect-original-syscall",
Value: false,
Usage: "when tracing kernel functions which are not syscalls (such as cap_capable), detect and show the original syscall that called that function",
},
&cli.BoolFlag{
Name: "show-exec-env",
Value: false,
Usage: "when tracing execve/execveat, show environment variables",
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func printList() {
const sep = ", "
var b strings.Builder
var i int32
for i = 0; i <= tracee.EventIDSyscallMax; i++ {
if name, ok := tracee.EventsIDToName[i]; ok {
b.WriteString(name)
b.WriteString(sep)
}
}
fmt.Println("System calls:")
fmt.Println(strings.TrimSuffix(b.String(), sep))
b.Reset()
fmt.Println()
for i = tracee.EventIDSyscallMax + 1; i <= tracee.EventIDMax; i++ {
if name, ok := tracee.EventsIDToName[i]; ok {
b.WriteString(name)
b.WriteString(sep)
}
}
fmt.Println("System events:")
fmt.Println(strings.TrimSuffix(b.String(), sep))
}