Commit graph

1621 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
5877e6c6d0
deb: warn about buggy python3-grpcio version (1.30.2-3build6)
Ubuntu jammy package python3-grpcio, version 1.30.2-3build6, has a bug
which causes applications to use 100% of the CPU.

If after installing we detect that the buggy version is installed,
display a warning to the user with instructions on how to solve the
problem and links to the bug reports.

More information:
 - https://bugs.launchpad.net/ubuntu/+source/grpc/+bug/1971114
 - https://github.com/evilsocket/opensnitch/issues/647

(cherry picked from commit c89b4908ce)
2024-07-02 00:17:20 +02:00
Gustavo Iñiguez Goia
a6fe895a67
ui,ruleseditor: add rules correctly to the db
Operator list was not converted to JSON string when saving the rule to
the DB.

Related: #1047
(cherry picked from commit 67149269cd)
2024-06-27 14:07:45 +02:00
Gustavo Iñiguez Goia
ae9aa40c37
deserialize rules operator list correctly
In b93051026e we disabled sending/parsing
list operators as JSON strings. Instead, now it's sent/parsed as
protobuf Rule, and saved to disk as JSON array, which ease the task of
manually creating new rules if needed.

This change was missing in the previous commit.

(cherry picked from commit 2fc9ed276b)
2024-06-21 14:35:15 +02:00
Gustavo Iñiguez Goia
987a227a42
updated rules tests
(cherry picked from commit 40b738ffea)
2024-06-21 14:11:54 +02:00
Gustavo Iñiguez Goia
fe66f9aa17
rules: improved operator list parsing and conversion
Previously when creating a new rule we followed these steps:
 - Create a new protobuf Rule object from the ruleseditor or the
   pop-ups.
 - If the rule contained more than one operator, we converted the
   list of operators to a JSON string.
 - This JSON string was sent back to the daemon, and saved to the
   DB.
 - The list of operators were never expanded on the GUI, i.e., they
   were not saved as a list of protobuf Operator objects.
 - Once received in the daemon, the JSON string was parsed and
   converted to a protobuf Operator list of objects.
   Both, the JSON string and the list of protobuf Operator objects were
   saved to disk, but the JSON string was ignored when loading the
   rules.

Saving the list of operators as a JSON string was a problem if you
wanted to create or modify rules without the GUI.

Now when creating or modifying rules from the GUI, the list of operators
is no longer converted to JSON string. Instead the list is sent to the
daemon as a list of protobuf Operators, and saved as JSON objects.

Notes:
 - The JSON string is no longer saved to disk as part of the rules.
 - The list of operators is still saved as JSON string to the DB.
 - About not enabled rules:
   Previously, not enabled rules only had the list of operators as JSON
   string, with the field list:[] empty.
   Now the list of operators is saved as JSON objects, but if the rule
   is not enabled, it won't be parsed/loaded.

Closes #1047

(cherry picked from commit b93051026e)
2024-06-21 11:38:46 +02:00
Gustavo Iñiguez Goia
4e7f1aeae7
Bumped versions to v1.6.6 2024-06-20 00:45:33 +02:00
Gustavo Iñiguez Goia
31fc42a764
ui,prefs: fixed changing qspinbox values
When changing qspinbox values (density scale, refresh interval, etc),
we were unintentionally changing [x] Disable popups option.

(cherry picked from commit acdd2b34ec)
2024-06-20 00:41:04 +02:00
Gustavo Iñiguez Goia
1ec8a0213a
ui: fixed exporting/importing rules
When exporting rules, use rfc3339 format for the Created field.
We were exporting it as timestamp, which caused issues when
importing the rules.

Related:
 58aa979cae
 issue #1140
(cherry picked from commit 552aed5bc5)
2024-06-19 18:56:25 +02:00
Gustavo Iñiguez Goia
7519db7aeb
fixed loading rules when Created field is a timestamp
When exporting rules from the GUI, the Created field was exported as
timestamp. Importing rules worked fine, because json.Marshall() accepts
the timestamp format.

However, when the daemon was loading a rule with the Created field as
timestamp, since the field was defined as time.Time, it expected a RFC3339
string (https://pkg.go.dev/time#Time.UnmarshalJSON)
so it failed to parse the timestamp and the rule was not loaded.

Now the field is defined as string, it's always saved as RFC3339, and if
we fail to parse these fields we'll use a temporary date instead of
failing loading the rule.

More info:
https://github.com/evilsocket/opensnitch/issues/1140#issuecomment-2140904847

(cherry picked from commit 58aa979cae)
2024-06-19 00:16:29 +02:00
Gustavo Iñiguez Goia
94e8156ce2
ui: keep working if pyinotify fails loading
pyinotify has stopped working in python3.12, it fails loading with the
error:
ModuleNotFoundError: No module named 'asyncore'

For now, ignore this error and keep working as usual.
Applications icons will be loaded on GUI startup, but we loose the
ability of discovering the icons of applications while the GUI is
running.

(cherry picked from commit ad8e2f5371)
2024-06-14 01:21:21 +02:00
Gustavo Iñiguez Goia
0fc4239453
ui: fixed exporting rules to the clipboard
We were not formatting the "created" date field properly.
More info: https://github.com/evilsocket/opensnitch/issues/1140#issuecomment-2140904847

(cherry picked from commit b096e664c7)
2024-06-14 01:19:32 +02:00
Gustavo Iñiguez Goia
496e9055a1
Remove duplicate regex in system.go for -check-requirements
(cherry picked from commit fa2f1068f6)
2024-06-14 01:18:39 +02:00
Gustavo Iñiguez Goia
ff407e72af
ui,prefs: node auth settings improvements
- Added "More information" label to the preferences dialog, and open a
   link to our wiki with more information.
 - Allow to configure node auth settings from the GUI:
   When we added the authentication options (12b4cf3104,
   6556eed1ae, f63d9dce72)
   we allowed to configure auth options from the GUI, but only if the
   nodes already had the options configured. If the auth options
   received were empty, we simply disabled the auth options on the
   preferences dialog.

   Now we build the configuration in this scenario, and sent it back to
   the nodes.

(cherry picked from commit 8c25c3f7df)
2024-06-14 01:17:39 +02:00
Gustavo Iñiguez Goia
03439f4f9c
ui, prefs: ignore SameFile error when enabling autostart
When clicking [x] Autostart the GUI upon login, ignore the exception if
src and dst (opensnitch_ui.desktop) are the same file.

(cherry picked from commit 0c8935c6e8)
2024-06-14 01:08:31 +02:00
Gustavo Iñiguez Goia
7653a0a1c1
Improve wording
(cherry picked from commit d6f3552fa0)
2024-06-14 01:06:06 +02:00
Gustavo Iñiguez Goia
c5409755bc
ui, prefs: improved loading auth options
(cherry picked from commit 0cc4d88e35)
2024-06-14 01:05:14 +02:00
Gustavo Iñiguez Goia
93a3fb7eb6
added more kernel config paths for checking system requirements
On Fedora Silverblue the kernel config of the current kernel is under
/usr/lib/modules/<kernel>/config

(cherry picked from commit 81dd625a1c)
2024-06-13 22:13:56 +02:00
Gustavo Iñiguez Goia
f4084d763c
updated workflow compilation deps
google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2 generates
protobuffers incompatible with go1.17, it fails with the error:
"ui/protocol/ui.pb.go:2716:47: predeclared any requires go1.18 or later
(-lang was set to go1.17; check go.mod)"

Notes:
 - consider using go1.18 as min required version if there's no problem
   compiling the daemon on Debian <= 13 and other distros.
 - github.com/golang/protobuf is deprecated and we should get rid of
it.
2024-06-13 13:21:39 +02:00
Gustavo Iñiguez Goia
ead45b062c
bumped minimum require go version to 1.17 2024-06-13 00:49:35 +02:00
Gustavo Iñiguez Goia
cd2dc2535c
ui, prefs: load and conf daemon DefaultAction
In f5f30b1e58 we added the option to
reject connections as DefaultAction.

If configured, load and set it in the preferences dialog.

(cherry picked from commit a21a316e34)
2024-06-13 00:23:55 +02:00
Gustavo Iñiguez Goia
801e797ad6
use go-gen-grpc@v1.3.0 for compiling the daemon
With @1.4.0 fails with the error "undefined: grpc.StaticMethod"

(cherry picked from commit 68de35141b)
2024-06-13 00:22:17 +02:00
Gustavo Iñiguez Goia
91190c80aa
added Reject to the list of DefaultActions(s)
We only offered two options for the DefaultAction option: allow/deny.

Since a long time ago we support "reject"ing connections, but it was not
configurable as the DefaultAction.

(cherry picked from commit f5f30b1e58)
2024-06-13 00:09:00 +02:00
Gustavo Iñiguez Goia
8895d6f024
disable (process) ebpf events when to many errors
if an invalid opensnitch-procs.o module was loaded, we were flooding
the log with errors.
In these cases stop processing events after 20 errors (random, we should
have no errors).

This may occur if the module is malformed (valid .o ebpf module but
different structs, etc), or when loading modules from other versions.

(cherry picked from commit 0a911ef791)
2024-06-12 23:58:10 +02:00
Gustavo Iñiguez Goia
362c0da53f
ui: allow to configure screen/themes scale factor
Added new options to the Preferences dialog, to configure screens/themes
scale factor.

If the UI is using the System theme (default), configure Qt scale
options (needs UI restart):
QT_AUTO_SCREEN_SCALE_FACTOR (default True)
QT_SCREEN_SCALE_FACTORS (If auto scale is False, use this value(s))

The user can configure different scale factors for multiple screens, by
separating values with ; (1;1.5, etc...)

https://doc.qt.io/qt-5/highdpi.html#high-dpi-support-in-qt

If the UI is using a qt-material theme, you can configure the "density"
scale of the theme:
https://github.com/UN-GCPDS/qt-material?tab=readme-ov-file#density-scale

https://github.com/evilsocket/opensnitch/wiki/GUI-known-problems#gui-size-problems-on-4k-monitors

(cherry-picked from bf9801f917)
2024-06-12 22:04:50 +02:00
Gustavo Iñiguez Goia
15fcf67535
ebpf: performance improvement for opensnitch-procs
We were sending to userspace unnecessary exit events, consuming
unnecessary CPU cycles.

We only intercept execve and execveat, but sched_process_exit is invoked
by more functions (sched_process_exit, clone, ...), so we were receiving
on the daemon events that we did nothing with them, apart from consuming
CPU cycles.

On some scenarios like on servers running saltstack (as salt-master),
this caused to consume more CPU than needed.
2024-02-26 12:44:01 +01:00
Gustavo Iñiguez Goia
9a605d3ef3
ui: versions comparing improvements
When comparing UI/daemon versions to see if they're compatible, we only
use the first 2 components (1.7.xxx), so discard the rest to allow
different versions (1.6.5.1, 1.6.5-1, 1.6.5-rc1, etc)
2024-02-09 17:01:55 +01:00
Gustavo Iñiguez Goia
b05eace022
Bump GUI versions to 1.6.5.1 2024-02-09 14:51:17 +01:00
Gustavo Iñiguez Goia
6809776393
pop-ups: fixed regression for remote nodes
When a new pop-up is triggered from a remote node, the GUI crashed.
This error was introduced by this commit 9fc1da5.

Thanks to @zero77 for reporting it super fast (#1093).
2024-02-09 13:21:01 +01:00
Gustavo Iñiguez Goia
1d2c0703ff
pop-ups: filter by absolute path+cmdline on some cases
If the pop-ups' target is to filter by cmdline, but the typed/launched
command is not absolute or it starts with /proc, also filter by the
absolute path to the binary.
2024-02-08 17:53:07 +01:00
Gustavo Iñiguez Goia
dd3aba1a6a
ui:use appimages pattern as default target if found
If the path of a process starts with /tmp/.mount_*, which is the common
path for appimages, use it as the default target on the popups.

Previously it was only added to the list of targets, but preselecting it
will help users to create rules for appimages.

(cherry picked from commit 016f4842ff)
2024-02-08 15:34:05 +01:00
Gustavo Iñiguez Goia
b99714ff59
pkgs: improved rpm upgrades
We were not handling configuration upgrades properly on rpm based
systems.

Now local changes to default-config.json and system-fw.json are kept,
and if the distributed files changes in the future, new files will be
created with the extension .rpmnew

(cherry picked from commit dddfdc924e)
2024-02-02 14:21:25 +01:00
Gustavo Iñiguez Goia
da99686ab0
clean dns ebpf hooks on exit
We were not reacting to common exit signals, only to kill/interrupt
signals, so the DNS uprobes were never properly removed. Each uprobe
has the PID of the daemon in the identifier, so in theory, there
shouldn't be conflicts, but better clean our probes on exit.

previous to this commit with the daemon running
(and lot of starts/stops):

~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
367

after stopping the daemon:
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
364

~ # > /sys/kernel/debug/tracing/uprobe_events
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0

~ # cp opensnitchd-new /usr/bin/opensnitchd ; service opensnitchd start
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
3
~ # service opensnitchd stop
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0

(cherry picked from commit 785500cd08)
2024-01-28 01:14:15 +01:00
Gustavo Iñiguez Goia
d2d89e2359 on aarch64 send exec events directly to userspace
On 68c2c8ae1a we excluded failed execve*
calls from being delivered to userspace, in order to get the binary that
was executed and avoid errors/confusion.

But on aarch64, it seems that we fail to save the exec event to a map,
so the event is never delivered to userspace.

So for the time being, send the exec events as soon as they arrive on
aarch64, without checking if the call failed.

(cherry picked from commit c118058dd8)
2024-01-26 21:10:56 +01:00
Gustavo Iñiguez Goia
9a6dfe7797 ebpf,dns: initialized structs
On the previus commit we just disabled dns uprobes for armhf/i386 to
avoid loading errors. A better fix is to initialized the structs used.
On armhf still fails after loading it, when attaching to the uprobes
(offsets?), and on i386 it doesn't seem to send anything to userspace
(more analysis needed).

- Increased the number of IPs associated with a domain that are
  delivered to userspace. (getfedora.org returns 30 ipv4+ipv6).
- Fixed getting the aliases of a domain when using gethostbyname().

(cherry picked from commit 27509d6fe0)
2024-01-26 20:55:07 +01:00
Gustavo Iñiguez Goia
0a8827d051 added more debug info to the dns ebpf hook
Added the path to the libc as well as the calculated offset for the
uprobe.
Don't return on the first error found loading a uprobe, instead try all
the uprobes and return if the loaded uprobes are 0.

(cherry picked from commit 55678b4d3b)
2024-01-26 14:53:43 +01:00
Gustavo Iñiguez Goia
c514946f61 fixed dns ebpf module for i386/arm architecture
The opensnitch-dns module was not loading on i386/arm architectures.
With the following changes it loads and some uprobes are attached.

for-loops unrolling doesn't still work though on i386/armhf (help
needed).

And on armhf the perf_output channel fails to load for some uprobes.

(cherry picked from commit d55e567dd8)
2024-01-26 14:24:41 +01:00
Gustavo Iñiguez Goia
2906470ea0
updated modules action to build 1.6.0 branch only 2024-01-24 23:56:41 +01:00
Gustavo Iñiguez Goia
34b595e50a
updated daemon/ui tests
They were failing when building the deb packages.
2024-01-24 20:22:34 +01:00
Gustavo Iñiguez Goia
5912b8e9d7
Bump packages versions to 1.6.5 2024-01-24 20:09:26 +01:00
Gustavo Iñiguez Goia
871238e07a
on errors stop established conns monitor
There's a long running task that monitors established connections every
~2s.

When a connection is not found via ebpf or proc, sometimes it's found
there so we can use the inode to search for the process.

However on some systems the netlink call to dump the sockets may fail
continuously, wasting resources. It'll also fail if you block connections
to port 0 (common case for ICMP packets).

So if there're too many errors dumpng the sockets, stop this task for
these cases.
2024-01-21 11:13:07 +01:00
Gustavo Iñiguez Goia
43477ebcbe
rules: fixed typo checking proc arguments 2024-01-15 21:56:55 +01:00
Gustavo Iñiguez Goia
b9ec5242f2
strings concatenation improvements
Use strings.Join() to concatenate strings, instead of Sprint*(), for
better performance.
2024-01-15 17:44:32 +01:00
Gustavo Iñiguez Goia
0340e77aa1
added go.sum 2024-01-14 19:15:53 +01:00
Gustavo Iñiguez Goia
fdba19c0c3
structs fields reorganized
Structs' fields reorganized based on fieldalignment tool feedback.
2024-01-13 22:15:23 +01:00
Gustavo Iñiguez Goia
60c6ac4aa8
Bump daemon and ui versions to 1.6.5 2024-01-10 01:05:34 +01:00
Gustavo Iñiguez Goia
4bff5c3037
ebpf: delete pid from exec maps if it exists
We track new processes execution by intercepting the enter and exit
of the functions, but sometimes the exit hook is not called, so the
corresponding entry was not being removed from the map.
In this situation the map becomes full and accepts no new entries.

Now the entry is deleted from the map once the process exits, if it
still exists in the map.

(cherry picked from commit 9446d191f0)
2024-01-09 12:42:48 +01:00
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
Gustavo Iñiguez Goia
eafb70fb55
fixed loading dns ebpf module
Closes #1076

(cherry picked from commit 159494d1e2)
2024-01-09 10:16:23 +01:00
Gustavo Iñiguez Goia
5c6da0a8ab
allow to configure ebpf modules path
Now it's possible to configure eBPF modules path from the
default-config.json file:
 "Ebpf": {
   "ModulesPath": "..."
 }

If the option is not provided, or if it's empty, we'll keep loading from
the default directories:

 - /usr/local/lib/opensnitchd/ebpf
 - /usr/lib/opensnitchd/ebpf
 - /etc/opensnitchd/ebpf (deprecated, will be removed in the future).

Closes #928

(cherry picked from commit ffb76683aa)
2024-01-08 23:49:36 +01:00