Commit graph

700 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
8c3fa40cf4
distribute default rules with the pkgs
Some checks failed
CI - build eBPF modules / build (6.0, 1.5.0) (push) Has been cancelled
CI - build eBPF modules / build (6.0, master) (push) Has been cancelled
Test resources validation / Install tools (push) Has been cancelled
Build status / Build (push) Has been cancelled
- distribute daemon/data/rules/ with the daemon packages.
 - added a new system fw rule to allow localhost connections (disabled
   by default).

Closes: #965.
2025-08-08 13:45:26 +02:00
Gustavo Iñiguez Goia
d513c9312a
updated predefined rules description 2025-08-08 01:33:53 +02:00
Gustavo Iñiguez Goia
d2fbdd9700
task pid monitor: fixed stopping the monitor 2025-08-08 01:27:00 +02:00
Gustavo Iñiguez Goia
3f63a0844e
bumped versions to v1.7.2 2025-08-06 20:51:27 +02:00
Gustavo Iñiguez Goia
f71f42b54e
fw,config: use context pkg instead of channels
Stop monitoring file changes using the context package instead of
channels.
2025-07-30 18:14:16 +02:00
Gustavo Iñiguez Goia
ca2c56d5cd cache: improved replacing processes
When replacing a process with the same PID (fork/clone),
and ebpf.QueueEventsSize is > 0 we may receive out or order events.
For example if the checksum calculation takes too much time.

Now we avoid updating the process in this scenario.
2025-07-30 16:57:32 +02:00
Gustavo Iñiguez Goia
53b948b11a
fixed exception loading outdated configuration
TODO: send the error to the GUI. It's important enough to warn the user
about it.

Issue: #1380
2025-07-19 18:49:15 +02:00
Andrew Voynov
c4285878f8
fixed empty host name not being matched 2025-07-19 02:24:49 +05:00
Gustavo Iñiguez Goia
14e306ecad Bumped cilium/ebpf version to 0.19.0
This version introduces a lot of improvements.

It's worth mentioning this one https://github.com/cilium/ebpf/pull/1755,
which reduces memory usage by ~25MB.

It also bumps go version to 1.23.
2025-07-07 23:06:19 +02:00
Gustavo Iñiguez Goia
1c94da7cb6
updated default-config.json
Added the default Authentication fields, to avoid detecting that the
config has changed.

It was causing the daemon to disconnect and reconnect on the first
config change made by the user.
2025-07-02 21:14:57 +02:00
Gustavo Iñiguez Goia
c82daddbae
ebpf dns improvements
- Better handling of burst messages.
 - Empty the queue if it gets full.
2025-06-25 00:57:07 +02:00
Gustavo Iñiguez Goia
7eb1cbf90d
improved proc monitors errors
- Avoid sending duplicated errors.
 - Fixed sending error message when the ebpf events module fails to
   load.
2025-06-22 22:23:36 +02:00
Gustavo Iñiguez Goia
e13b4b9f76
updated config tests 2025-06-19 23:49:45 +02:00
Gustavo Iñiguez Goia
a4d8d1bb27
improved daemon's connection logic with the server (GUI)
- New: if Server.Address is not set, stop the routine that attempts
   to connect with the remote server.
 - Spawn only one polling routine.
 - When changing the configuration:
   - if the new server.address changed and is not empty -> reconnect.
   - if the new server.address changed and is empty -> disconnect.
   - if previous server.address was empty and the new one is not -> connect.
   - if the authentication settings changed -> reconnect.

   If the server.address is not available, we'll try to connect
   indefinitely.
2025-06-19 01:59:30 +02:00
Gustavo Iñiguez Goia
acd5b8886b
Bumped versions to v1.7.1 2025-06-18 01:10:23 +02:00
Gustavo Iñiguez Goia
f1318ef12d
fixed loading config when the procmon fails
- Fixed configuration loading, when the Process Monitor Method
   selected failed to work (e.g.: when ebpf modules are missing,
   auditd is not configured, etc).
   In this scenario, on the first run, the daemon was not loading the
   configuration from disk, and was instead using the default values, which
   led to some glitches (unexpected reconnections to the GUI, checksums
   option ignored, etc).
 - added more tests.
2025-06-18 00:35:17 +02:00
Gustavo Iñiguez Goia
9f570ea9ad ebpf events improvements
Discard events from the queue if we can't send events to the channel.
It can happen if the case of a deadlock such as in ac3053af327e38acad4ff4024ed688ed68d6ae30

In this situation, reading from the ring buffer is blocked, which
eventually causes it to fill up.
When the ring buffer is full, bpf_ringbuf_output() fails with error -11.
2025-06-15 23:10:09 +02:00
Gustavo Iñiguez Goia
c198f0119f improved events cache
Under very high load of kernel events, combined with a
non-zero value for the ebpf.QueueEventsSize config option,
the cache could end up blocking the events workers if the option to
compute process checksums was enabled.
2025-06-15 23:10:09 +02:00
Gustavo Iñiguez Goia
f0b1173d9d added Process path+args tests 2025-06-12 23:43:59 +02:00
Gustavo Iñiguez Goia
376b06ef97
improved binary absolute path retrieval
When receiving the paths of a binary from kernel, the path can be a
symlink to the real binary on disk, and we were not obtaining the real
path to the binary.

Now we'll try to obtain it. If we fail, we'll use the path received from
the kernel. And if it's empty, we'll fallback to read it from proc.

Closes #1357
2025-06-07 23:51:13 +02:00
Gustavo Iñiguez Goia
aa37ac3e3a loggers: changed log level from Warn to Debug
When the remote logger cannot connect to the server, avoid flooding the
logs with warnings.
2025-06-05 20:47:29 +02:00
Gustavo Iñiguez Goia
a3826c50c9
improved remote logger
- Added MaxConnectAttempts configuration option:
   If not specified, it defaults to 0, which means that we'll try to connect
   indefinitely to the remote server.

 - Improved connection retry behaviour:
   We were not reconnecting to the server if we failed to connect on the
   first attempt. Now we'll try to connect until MaxConnectAttempts, or
   indefinitely if not specified (default value 0).

 - If the logger is not connected to the remote server, don't send
   messages to the queue.

Closes #1350.
2025-06-02 23:25:43 +02:00
Gustavo Iñiguez Goia
ef926050c2
fixed listening for link changes (#1343)
netlink.AddrSubscribeWithOptions() was causing systemd-resolved not to
obtain DNS servers, and therefore the system was unable to resolve
domain names.

This ssue started happening on Fedora 42, with systemd-resolved 257 and
kernels 6.14.x.

Using netlink.AddrSubscribe() solves this issue for now.

Closes #1343
2025-05-23 12:53:29 +02:00
Gustavo Iñiguez Goia
e0c659992a
fixed leak reconfiguring rules monitor task 2025-05-23 11:40:43 +02:00
Gustavo Iñiguez Goia
b20fd15335
changed ebpf log levels
Changed Error to Warning log level when failing to load hooks.

Except for udp_tunnel6_xmit_skb, which depends on the module
ip6_udp_tunnel to be loaded, which by default is not the case.
In order not to flood the logs with this error, log level changed to
Debug.
2025-05-21 21:49:15 +02:00
Gustavo Iñiguez Goia
56b2d28b66
ebpf: added support for ipv6 tunnels
In order to intercept UDP tunnels traffic, we use iptunnel_xmit for IPv4
connections. The equivalent of IPv6 would be ip6tunnel_xmit, but
unfortunately it's not public.

So instead of ip6tunnel_xmit, we'll use udp_tunnel6_xmit_skb.

This function receives two parameters besides the struct sock*, in6_addr
*saddr and in6_addr *daddr. If these addresses are not set, usually the
connection is a localhost connection.

On the other hand, this function is defined in the module
ip6_udp_tunnel. If this module is not loaded when the daemon starts,
we'll fail to intercept the connections.

Closes: #1250
2025-05-05 00:34:25 +02:00
Gustavo Iñiguez Goia
568d69520f
fixed reporting connection UID
When getting a connection from the cache, use the UID of the connection,
instead of the process UID.

more info: https://github.com/evilsocket/opensnitch/issues/1315#issuecomment-2829072245

Closes: #1315
2025-04-27 23:54:52 +02:00
Gustavo Iñiguez Goia
aeb2018d27
log the UID of exec events 2025-04-24 23:55:42 +02:00
Gustavo Iñiguez Goia
12c21c7a26
removed debug line 2025-04-24 23:53:50 +02:00
Gustavo Iñiguez Goia
82b09c3ac6
removed not needed log line 2025-04-24 18:00:31 +02:00
Gustavo Iñiguez Goia
c8bec89d70
reorganized network aliases feature
- Moved to their own files/dirs.
 - Added Nolan Carouge as author and contributor.
2025-04-24 16:06:11 +02:00
Self Denial
056e2ec2ee
refactor: Update localhost rules and add IPv6
- Changed the local host rule from using regexp to network operator
- Updated destination IP check from specific addresses to CIDR notation (127.0.0.0/8)
- Added new rule for IPv6 localhost connections (::1/128)
- Added nolog property to prevent logging of localhost traffic
2025-04-23 12:48:28 -06:00
Gustavo Iñiguez Goia
2a8f13d439
process path parsing improvements
- Preprend the chroot of a process to the path:
   Even if a process is executed from a chroot (or a different mount
   namespace), the kernel reports the path as it were from the host.
   For chrooted processes, now we prepend the chroot to the path:
   Instead of /usr/bin/curl -> /var/cache/pbuilder/usr/bin/curl

   Note: if the process is emulated (with qemu for example), the
   checksum will be of the emulator.

 - For proceses launched from /proc, like /proc/self/exe or
   /proc/<pid>/fd/<number>, we were replacing in the cmdline "/proc/*"
   with the absolute path of the binary:

   Path: /usr/bin/curl
   Cmdline reported: /proc/<pid>/fd/<number> -L 1.1.1.1
   Cmdline "fixed": /usr/bin/curl -L 1.1.1.1

   Now we only do that for /proc/self/exe, and leave
   /proc/<pid>/fd/<number> as is, since Path is already the absolute
   path to the binary.

   Path: /usr/bin/spotify
   Cmdline reported: /proc/self/exe
   Cmdline "fixed": /usr/bin/spotify

   Path: /usr/bin/curl
   Cmdline reported: /proc/<pid>/fd/<number> -L 1.1.1.1
   Cmdline final: /proc/<pid>/fd/<number> -L 1.1.1.1
2025-04-18 13:30:51 +02:00
Gustavo Iñiguez Goia
8ec86c638c
ebpf: arm improvements
- better process interception on aarch64 and armhf.
 - on armhf getting proc arguments is ignored due to an error, but we
   were not marking the event as INCOMPLETE_ARGS, so we were not reading
   the compete cmdline.
2025-04-14 17:43:41 +02:00
Gustavo Iñiguez Goia
f99700076c
ebpf dns: better error handling
- Avoid crashes if the module is malformed.
 - Better error handling.
2025-04-11 21:07:31 +02:00
Gustavo Iñiguez Goia
452233901d
avoid printing in debug possible invalid var 2025-04-10 21:26:26 +02:00
Gustavo Iñiguez Goia
feafe87604
migrated ebpf lib from gobpf to cilium
Up until now we've been using https://github.com/iovisor/gobpf/ for
intercepting events from the kernel, and it has worked very well.

Unfortunately it's deprecated since 2021 (iovisor/gobpf#304), which means
that some of the known issues and limitations won't be fixed.

After evaluating some options, I've migrated the code from gobpf to
github.com/cilium/ebpf.

More info: #1222, #1312
2025-04-09 00:15:38 +02:00
Gustavo Iñiguez Goia
56eddafca8
loggers: handle errors properly
RemoteLogger: don't create the logger if we can't connect with the
server.
2025-03-29 17:21:19 +01:00
Gustavo Iñiguez Goia
aab65908c7
fixed condition checking operator Data field 2025-03-18 02:09:53 +01:00
Gustavo Iñiguez Goia
5828ba861c
fixed crash compiling unknown operator rules
If a rule contained an unknown rule type or unknown operand, the daemon
crashed.

Closes: #1295
2025-03-18 01:38:31 +01:00
Gustavo Iñiguez Goia
7b66e598b6
loggers: simplify structed data conversions
- unify conversion for rfc3164 and rfc5424 formats.
2025-03-11 20:18:34 +01:00
Gustavo Iñiguez Goia
98b8b06018
remote loggers improvements
- Convert remote syslog to remote. There's no real difference between
   both, and the code was the same.
    Maybe we could limit the logging formats allowed.
 - Remote logger: Added option to reopen the connection after n errors
   trying to send messages.
2025-03-11 17:57:13 +01:00
Gustavo Iñiguez Goia
da4761f1d6
log checksums and proctree for syslog formats
- Log the checksums and process tree when using rfc3164 and rfc5424
   formats.
 - Minor performance improvements.
2025-03-11 17:06:40 +01:00
Gustavo Iñiguez Goia
ac45c4103f
nftables tests: skip TestAddInterceptionChains
tested on several distros with different kernels, as well as in a
private fork and this test doesn't fail.

So until we figure out why it's failing here, let's skip it for now.
2025-03-10 17:02:38 +01:00
Gustavo Iñiguez Goia
221923da73
improved loggers , remote logger
- Fixed issue when configuring several loggers.
 - Remote logger:
    - open as many connections with the remote server as
      specified in the Workers field.
    - open and handle every connection in each own goroutine.
    - get rid of the locks.
2025-03-10 16:42:19 +01:00
Gustavo Iñiguez Goia
f23c1635ca
minor logging improvements
- Moved Info message to Trace.
 - When applying a default action on a connection (because the daemon is
   not connected to the GUI), log the connection details. It eases the
   task of creating rules without a GUI.
2025-03-04 22:19:07 +01:00
Gustavo Iñiguez Goia
8d1a7de0cc
moved some Debug msgs to Trace 2025-03-03 21:35:31 +01:00
Gustavo Iñiguez Goia
5fdb60dccb
ui,prefs: fixed QueueBypass option. 2025-02-18 23:40:56 +01:00
Gustavo Iñiguez Goia
c6b42890c0
proc.readEnv() improvements
- Minimize the risk of race conditions when we're prompting the user to
   allow/deny a connection, while we're still reading proc's environ file.
   (this was actually a leak).
 - Preallocate the Env map with the expected environ vars.
2025-02-17 14:15:28 +01:00
Gustavo Iñiguez Goia
ce006ee1ac
Bumped nftables lib to v0.2.0 2025-02-14 23:06:50 +01:00