Commit graph

21 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
5d33f41717
ebpf: fixed dns uprobes
We were not deleting DNS entries from the hash map, so when it reached
the maximum capacity (12k entries), we couldn't allocate new entries,
resulting in events not being sent to userspace.

(cherry picked from commit 1518cb39de)
2024-01-09 12:42:20 +01:00
Gustavo Iñiguez Goia
1ae20c3aa3
ebpf: fixed getting ppid, skip failed execve's
- Fixed getting ppid (precompiled .o won't probably work).
 - Skip failed execve* calls.

(cherry picked from commit 68c2c8ae1a)
2024-01-09 11:53:23 +01:00
Rasmus Moorats
122608bced
use temporary files instead of piping in ebpf Makefile 2023-07-07 13:28:58 +03:00
munix9
11baad083d
ebpf modules compilation fixes
- don't import hardcoded architecture.
- use generic cpu (-mcpu=generic)
- removed linux/version.h from modules.

related #954
2023-05-28 15:24:33 +02:00
Gustavo Iñiguez Goia
ba64379348
ebpf: new way of compiling the modules
- Don't rename libbpf's bpf_map_def struct, and distribute the needed bpf
  headers.
  The bpf_map_def struct has been deprecated for quite some time now,
  and it was been removed on >= 6.2 anyway.
  We still need it, because we use gobpf.
- Improved compilation behaviour:
  - We don't require the kernel sources anymore. We can just use the
    kernel headers from the distribution.
  - There's no need to copy the sources to the kernel tree, the modules
    can be compiled from the ebpf_prog/ dir.
- Compiling against kernels 6.x seems to solve the problem we had with
  VPNs, where connections were not intercepted with modules compiled
  against 5.8, on kernels >= 5.19.

The modules has been tested on kernels 4.17, 5.4, 5.10, 5.15, 6.1 and
6.2 (kernel connections included).

Closes: #939
2023-05-17 01:20:53 +02:00
Gustavo Iñiguez Goia
210e843aab
moved basic ebpf definitions to its own file
BPF_MAP_TYPE_PERCPU_ARRAY was introduced in kernel version 4.6, so with
latest changes to intercept processes we lost support for older kernels
< 4.6.

Now we work again for example on kernels 4.4.
2022-12-21 21:11:40 +01:00
Gustavo Iñiguez Goia
9e630d009d
ebpf: fixed loading modules on arm32 arch
Make use of kernel macros to decide for what architectures we compile
the modules.

On armv7l the connections module was failing due to iptunnel_xmit, so
exclude it from being compiled.

One can export ARCH=arm, ARCH=i386 or ARCH=arm64 to compile the modules
for these architectures, instead of hacing to edit the source files.
2022-12-13 23:59:54 +01:00
Gustavo Iñiguez Goia
71747ebed5
ebpf instructions updated 2022-11-18 21:50:42 +01:00
Gustavo Iñiguez Goia
7cbfca6b1f
ebpf: increased ring buffer size, hook execveat
Increased perf map buffer size to avoid lose events under heavy loads.

Hook execveat to intercept executions from memory.
2022-10-13 01:44:23 +02:00
Gustavo Iñiguez Goia
31c420ad60
ebpf dns module: fixed compilation warning 2022-10-05 14:33:05 +02:00
Gustavo Iñiguez Goia
fc3d7382de ebpf: get cmdline arguments from kernel
- Get cmdline arguments from kernel along with the absolute path to the
  binary.
  If the cmdline has more than 20 arguments, or one of the arguments is
  longer than 256 bytes, get it from ProcFS.
- Improved stopping ebpf monitor method.
2022-07-12 15:40:01 +02:00
Gustavo Iñiguez Goia
72483bdcde improved process detection
latest changes to detect short-lived processes caused undesired
behaviour (#694)

Closes #685
2022-07-08 17:15:57 +02:00
Nico Berlee
ab42752b6b
ebpf: fix compiler issue
Signed-off-by: Nico Berlee <nico.berlee@on2it.net>
2022-07-01 17:47:16 +02:00
Gustavo Iñiguez Goia
e7024e3fe0 ebpf: support for long paths
Added support to report absolute path to a binary up to 4096 characters,
defined here:

https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/limits.h#L13
2022-06-27 14:42:54 +02:00
Gustavo Iñiguez Goia
4ce8b0e57c ebpf: improved process detection/new events module
Improved process detections by monitoring new processes execution.
It allow us to know the path of a process before a socket is opened.

Closes #617

Other improvements:
 - If we fail to retrieve the path of a process, then we'll use the comm
   name of the connection/process.
 - Better kernel connections detection.
 - If debugfs is not loaded, we'll try to mount it, to allow to use
   eBPF monitor method.

Future work (help wanted):
 - Extract command line arguments from the kernel (sys_execve, or mm
   struct).
 - Monitor other functions (execveat, clone*, fork, etc).
 - Send these events to the server (GUI), and display all the commands
   an application has executed.
2022-06-24 01:09:45 +02:00
Gustavo Iñiguez Goia
a2f237aa1b updated ebpf modules compilation steps 2022-03-07 01:27:28 +01:00
calesanz
a4b7f57806
Add ebpf based dns lookup hooks (#582)
When using DoT or DoH opensnitch cannot intercept the dns packets.
Therefore the UI always shows IP addresses instead of hostnames. To fix
this issue an ebpf (uprobe) filter was created to hook getaddrinfo and
gethostbyname calls.

In order to be independent of libbcc an additional module was added to
ebpf_prog. Without libbcc the libc function offsets must be resolved
manually. In order to find the loaded glibc version some cgo code was
added.
2022-02-15 21:25:35 +01:00
Gustavo Iñiguez Goia
0526b84309
Allow to intercept more kernel connections (#513)
* Allow to intercept some kernel connections

Some connections are initiated from kernel space, like WireGuard
VPNs (#454), NFS or SMB connections (#502) and ip tunnels (#500).

Note: This feature is complete for x86_64, WIP for aarch64, and not supported for armhf and i386
https://github.com/evilsocket/opensnitch/pull/513#issuecomment-924400824

More information regarding this change: #493
2021-09-23 01:44:12 +02:00
Gustavo Iñiguez Goia
c66d5d6bf0 ebpf: updated dependencies list for compiling 2021-09-13 11:49:27 +02:00
Gustavo Iñiguez Goia
05f7e38f9d ebpf: added patch to compile ebpf module for arm 2021-04-21 20:49:31 +02:00
themighty1
9497cf8394
Use ebpf program to find PID of new connections. (#397)
* Use ebpf program to find PID of new connections.

    before running the branch you have to compile ebpf_prog/opensnitch.c
    opensnitch.c is an eBPF program. Compilation requires getting kernel source.

    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
    cp ebpf_prog/opensnitch.c ebpf_prog/Makefile linux-5.8/samples/bpf
    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
    sudo cp opensnitch.o /etc/opensnitchd
    cd ../../../daemon

    --opensnitchd expects to find opensnitch.o in /etc/opensnitchd/
    --start opensnitchd with:

    opensnitchd -rules-path /etc/opensnitchd/rules -process-monitor-method ebpf

Co-authored-by: themighty1 <you@example.com>
Co-authored-by: Gustavo Iñiguez Goia <gooffy1@gmail.com>
2021-04-05 11:28:16 +02:00