-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
50 lines (41 loc) · 1.21 KB
/
main.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
package main
import (
"log"
"os"
"github.com/tks98/snoopy/internal/util"
"github.com/tks98/snoopy/pkg/tls_trace"
)
func main() {
// Check if the user is running with root privileges
if os.Geteuid() != 0 {
log.Fatal("snoopy must be run as root!")
}
// Parse and command line options
opts := util.ParseCLIOptions()
// Read BPF program from source file
sources, err := util.ReadEbpfProgram("bpf/snoopy.c")
if err != nil {
log.Fatal(err)
}
// Get shared SSL library paths for Uprobes
binaryPaths, err := util.GetLibPaths()
if err != nil {
log.Fatal(err)
}
// Create new TLS tracer with parsed options
tracer := tls_trace.New(opts.JSONOutput, sources, binaryPaths, &opts.PID)
// Start tracing by obtaining the message channel
tlsMessages, err := tracer.TraceMessageChannel()
if err != nil {
log.Fatalf("Failed to start tls_trace: %s", err)
}
// Loop over messages from the TLS tracer
for message := range tlsMessages {
message.Print(opts.JSONOutput)
// If PID was provided and equals the message Pid, or if no PID was provided
// and the message has content, print the message.
if (opts.PID < 0 || opts.PID == int(message.Pid)) && message.HasContent() {
message.Print(opts.JSONOutput)
}
}
}