eBPF code to intercept WireGuard (/tunnels) connections #493
Replies: 4 comments 5 replies
-
|
You didnt zero out net_hdr. Im not saying that is the reason but ebpf code is very finicky. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @themighty1 for reviewing it. Also worth noting is that this function was included in kernel 3.8 with a different definition, later rewritten in 3.10 and 3.11 and 3.12 if included maybe we should load kprobes one by one, otherwise if this kprobe fails loading we wouldn't load the rest of kprobes. |
Beta Was this translation helpful? Give feedback.
-
|
hey @themighty1 , I'd like to know your opinion on the status of this issue #513 . Do you think that it could be merged as it is right now? On x86_64 it works on pretty much every kernel I've tried it out in. On arm64 works (with some limitations). And on i386/armhf I haven't managed to get sk_buff nor sock from registers, so the hook for these arquitectures is just ignored, or a .o module without this hook should be shipped. |
Beta Was this translation helpful? Give feedback.
-
|
I wanted to get similar wireguard connection tracking with IPv6 support, and looking at send4/send6 in more recent 6.12 drivers/net/wireguard/socket.c, best place to get saddr/daddr/sport/dport from seem to be udp_tunnel_xmit_skb and udp_tunnel6_xmit_skb functions that they're passed to. One quirk there is that sport/dport are passed as arguments 9/10, which need to be fetched from stack (as per System V AMD64 ABI calling convention), and with IPv6 version saddr/daddr are supposed to be set on return via pointers (e.g. saddr set to in6addr_any), so need similar cache for kretprobe as with socket connect calls. Implemented those probes towards the end here: https://github.com/mk-fg/linux-ebpf-connection-overseer/blob/master/ebpf.c |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Tested only on 5.10.x, 5.8.x, 5.4.x and 4.19.x, and only for x86_64 and IPv4 for now.
procmon/parse.go:FindProcess() must be edited in order to pass some checks, and in these cases maybe we could set the name (path of the process internally) as "Kernel connection", and arguments the value of /proc//comm.
Anyway, I think that the comm value should be set from the eBPF data, instead of reading it from disk again.
Beta Was this translation helpful? Give feedback.
All reactions