2021-04-05 09:28:16 +00:00
|
|
|
opensnitch.c is an eBPF program. Compilation requires getting kernel source.
|
|
|
|
|
2021-09-13 11:49:27 +02:00
|
|
|
sudo apt install clang llvm libelf-dev libzip-dev flex bison libssl-dev bc rsync python3
|
2021-04-05 09:28:16 +00:00
|
|
|
cd opensnitch
|
|
|
|
wget https://github.com/torvalds/linux/archive/v5.8.tar.gz
|
|
|
|
tar -xf v5.8.tar.gz
|
|
|
|
patch linux-5.8/tools/lib/bpf/bpf_helpers.h < ebpf_prog/file.patch
|
2022-06-27 14:42:54 +02:00
|
|
|
cp ebpf_prog/opensnitch*.c ebpf_prog/common.h ebpf_prog/Makefile linux-5.8/samples/bpf
|
2021-04-05 09:28:16 +00:00
|
|
|
cd linux-5.8 && yes "" | make oldconfig && make prepare && make headers_install # (1 min)
|
|
|
|
cd samples/bpf && make
|
|
|
|
objdump -h opensnitch.o #you should see many section, number 1 should be called kprobe/tcp_v4_connect
|
|
|
|
llvm-strip -g opensnitch.o #remove debug info
|
2022-03-07 01:27:28 +01:00
|
|
|
sudo cp opensnitch*.o /etc/opensnitchd/
|
2021-04-05 09:28:16 +00:00
|
|
|
cd ../../../daemon
|
|
|
|
|
|
|
|
--opensnitchd expects to find opensnitch.o in /etc/opensnitchd/
|
|
|
|
--start opensnitchd with:
|
|
|
|
|
2021-04-21 20:49:31 +02:00
|
|
|
opensnitchd -rules-path /etc/opensnitchd/rules -process-monitor-method ebpf
|
|
|
|
|
|
|
|
The kernel where you intend to run it must have some options activated:
|
|
|
|
|
|
|
|
$ grep BPF /boot/config-$(uname -r)
|
|
|
|
CONFIG_CGROUP_BPF=y
|
|
|
|
CONFIG_BPF=y
|
|
|
|
CONFIG_BPF_SYSCALL=y
|
|
|
|
CONFIG_BPF_EVENTS=y
|
|
|
|
CONFIG_KPROBES=y
|
|
|
|
CONFIG_KPROBE_EVENTS=y
|
2022-06-27 14:42:54 +02:00
|
|
|
|
|
|
|
Also, in some distributions debugfs is not mounted automatically, so you need
|
|
|
|
to do it manually:
|
|
|
|
|
|
|
|
$ sudo mount -t debugfs none /sys/kernel/debug
|
|
|
|
|
|
|
|
In order to make it permanent add it to /etc/fstab:
|
|
|
|
|
|
|
|
debugfs /sys/kernel/debug debugfs defaults 0 0
|