Commit graph

1681 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
b096e664c7
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
2024-05-31 00:09:23 +02:00
Gustavo Iñiguez Goia
33c592007f
ui,prefs: allow to configure more options
Allow to configure from the preferences dialog:
 - max stats and events.
 - rules path (use default path if empty).
 - internal GC percentage, flush connections on start.

Disabled daemon's DefaultDuration option when the daemon is not
connected to the server (GUI). By default is "once".

Improved configuration parsing.
Minor improvements to display status messages.
2024-05-30 00:30:02 +02:00
Gustavo Iñiguez Goia
41690b2d2d
set default rules directory if empty
Use /etc/opensnitchd/rules as the default directory if it has not been
provided via configuration.
2024-05-29 23:43:46 +02:00
Gustavo Iñiguez Goia
5234df7513
Merge pull request #1139 from redanaheim/master
Remove duplicate regex in system.go for -check-requirements
2024-05-27 21:23:12 +00:00
redanaheim
fa2f1068f6
Remove duplicate regex in system.go for -check-requirements 2024-05-26 23:22:53 +00:00
Gustavo Iñiguez Goia
03747ea0e3
improved config file reloading behaviour
Start monitoring the config file every time we read the file, to survive:
 - malformed json file
 - intermediate file removal (when writing we receive 2 write events,
   one of0 bytes)

"A watch will be automatically removed if the watched path is deleted or
renamed"
"A path can only be watched once; watching it more than once is a no-op and
will not return an error"
https://pkg.go.dev/github.com/fsnotify/fsnotify#Watcher.Add
2024-05-23 01:47:59 +02:00
Gustavo Iñiguez Goia
2238e63892
updated go.mod, added go.sum 2024-05-22 01:39:19 +02:00
Gustavo Iñiguez Goia
c0d1da20d2
improved rules reloading, cli parameters
- When reloading rules from a path:
   stop existing (domains,ips,regexp) lists monitors, stop rules
   watcher and start watching the new dir for changes, delete existing
   rules from memory, etc.
 - Previously, cli parameters (queue number, log file, etc) were taking
   into account before loading the configuration.
   Now the configuration file is loaded first (default-config.json), and
   if any of the cli parameter has been specified, it'll overwrite the
   loaded configuration from file.

   This means for example that if you use "-process-monitor-method proc",
   and "ebpf" is configured in default-config.json, firstly "ebpf" will
   be configured, and later "proc".

   (-queue-num option for now requires to match config option
   cfg.FwOptions.QueueNumber)
2024-05-22 00:47:54 +02:00
Gustavo Iñiguez Goia
661e3da48f
kill established connections only on fw/monitor changes 2024-05-19 23:43:12 +02:00
Gustavo Iñiguez Goia
8c25c3f7df
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.
2024-05-18 21:56:17 +02:00
Gustavo Iñiguez Goia
427447574f
Merge pull request #1135 from ponychicken/patch-1
Improve wording in Top menu
2024-05-18 08:36:51 +00:00
Gustavo Iñiguez Goia
0c8935c6e8
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.
2024-05-18 10:33:16 +02:00
ponychicken
d6f3552fa0
Improve wording 2024-05-18 09:16:55 +02:00
Gustavo Iñiguez Goia
a21a316e34
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.
2024-05-18 00:51:54 +02:00
Gustavo Iñiguez Goia
0cc4d88e35
ui, prefs: improved loading auth options 2024-05-18 00:50:30 +02:00
Gustavo Iñiguez Goia
8cadf5316e
ui: fixed deleting rules
reverts 2ec37ed593

Closes: #1133
2024-05-18 00:03:48 +02:00
Gustavo Iñiguez Goia
1e6d2d464b
updated default-config.json with latest added opts
More info about these options:
https://github.com/evilsocket/opensnitch/wiki/Configurations
2024-05-16 00:51:30 +02:00
Gustavo Iñiguez Goia
eede54c525
allow to customize ebpf options
Allow to customize:

 - EventsWorkers: number of goroutines to handle kernel events.
   Default 8.

 - QueueEventsSize: max number of events in the queue.
   By default 0, meaning that it'll relay on the available goroutines to
   process the events. If it's > 0, and the daemon can't process the
   events fast enough, they'll be queued. Once the queue is full, it'll
   behave as it was of size 0.

If there're lost events, a message will be logged: "Lost ebpf events..."
2024-05-16 00:31:54 +02:00
Gustavo Iñiguez Goia
84361449f2
loggers, remote_syslog: check if we're connected
when writing, check if we're connected, or reconnecting.
2024-05-15 00:06:26 +02:00
Gustavo Iñiguez Goia
efc05663eb
fw: allow to configure interception queue number
- Added new configuration field to allow configure fw interception
   number queue (default to 0):
   "FwOptions": {
      "QueueNum": 0
   }
   (we still need to reconfigure nfqueue queues in order for this to
take effect).
 - If the fw configuration path is not supplied, default to
   /etc/opensnitchd/system-fw.json
2024-05-14 23:41:25 +02:00
Gustavo Iñiguez Goia
9afadcb009
fixed segfaults when loading fw/loggers
- The loggers were not being properly initialized.
 - The fw was only being load on reload, instead of on startup
   and reload.

Kudos to @1fishe2fishe for reporting this problem and proposing a
fix in #1130!
2024-05-14 19:47:35 +02:00
Gustavo Iñiguez Goia
221955ecf0
Merge pull request #1126 from tioguda/master
i18n: updated Brazilian Portuguese translation
2024-05-14 11:57:53 +00:00
Gustavo Iñiguez Goia
c9ad9005e3
fw minor changes
use struct{} instead of bool for exit channels, func parms cosmetic
change.
2024-05-13 01:38:57 +02:00
Gustavo Iñiguez Goia
8935bfe6b0
do not flush conns when adding the inteception rules
part of previous commit.
2024-05-13 01:33:28 +02:00
Gustavo Iñiguez Goia
8e9c1d2178
make connections flushing configurable
By default when adding the interception rules, we were killing all
existing connections, to force them go to the netfilter queue.

However in some environments this is not acceptable, so now it's configurable.

Besides, we were doing this only for nftables, so now it also works for
iptables.
2024-05-13 00:27:41 +02:00
Gustavo Iñiguez Goia
c3bbb9250e
stop proc monitor when disabling interception
When disabling the interception from the server (GUI), the network
interception was stopped, but the procs monitor kept running.

Now the procs monitor in use is also stopped, not to interfere with
the rest of the system (except 'proc').
2024-05-12 10:46:11 +02:00
Gustavo Iñiguez Goia
bc32094945
removed fw rules initialization from main
now they're added after loading the configuration.
2024-05-12 00:59:48 +02:00
Gustavo Iñiguez Goia
64a698f221
loggers improvements
improvements to the loggers modules:

 - allow to specify a connection timeout (there was only a write
   timeout).
 - performance improvements when building the messages to be
   written/sent.
 - allow to restart the connection with remote servers if we fill up the
   messages queue.
   This can occur for example if we connect to a remote server, start
   sending messages, but we haven't allowed other connections yet.
   In this case the connections never recovered from this state, and we
   weren't prompted to allow the needed connections.
   (more work nd testing needed)
2024-05-11 18:39:04 +02:00
Gustavo Iñiguez Goia
0b67c1a429
more work on reloading configuration
continuation of previous commit bde5d34deb

 - Allow to reconfigure stats limits (how many events we keep on the
   daemon, number of workers, ...)
 - Allow to reconfigure loggers.
2024-05-11 18:23:20 +02:00
tioguda
df6c7d53f3 i18n: updated Brazilian Portuguese translation 2024-05-06 09:52:27 -03:00
Gustavo Iñiguez Goia
7d08b2b4a0
changed ui/client/configuration tests
In order to test ebpf<->proc changes we'll need to have access to a
valid ebpf module.
2024-05-06 00:10:00 +02:00
Gustavo Iñiguez Goia
bde5d34deb
reload more config options without restarting the daemon
Reload the configuration without restarting the daemon when changing:
 - server authentication options.
 - GC percentage.
 - Rules path.
 - Loggers.
 - FW options.
 - eBPF modules path.

Also, try to avoid unnecessary changes.
2024-05-02 21:14:59 +02:00
Gustavo Iñiguez Goia
f5f30b1e58
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.

Closes: #1108
2024-05-01 00:23:48 +02:00
Gustavo Iñiguez Goia
be87bc538e
build parent process hierarchy of already running processes
We build the parent process tree of a process when it's executed
for the first time.
Now we also build the tree when an already running process opens a new
outbound connection by the first time.
2024-04-30 23:26:47 +02:00
Gustavo Iñiguez Goia
0a911ef791
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.

Closes: #1099 #1082
2024-04-30 00:51:41 +02:00
Gustavo Iñiguez Goia
7442bec96f
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.

cherry picked from 15fcf67535
2024-04-29 01:06:39 +02:00
Gustavo Iñiguez Goia
81dd625a1c
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

Closes: #1117
2024-04-27 23:36:04 +02:00
Gustavo Iñiguez Goia
bf9801f917
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

Closes: #1102
2024-04-27 19:02:54 +02:00
Gustavo Iñiguez Goia
2ec37ed593
ui: fixed deleting rules with list limits
Fixed deleting rules when the GUI is configured to display a maximum
number of rules.
2024-02-11 11:41:49 +01:00
Gustavo Iñiguez Goia
fbd17a29da
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:45:21 +01:00
Gustavo Iñiguez Goia
c3ec54efaf
Updated ebpf compilation instructions
kudos to @planetoryd for reporting it (#1080).
2024-02-06 00:30:44 +01:00
Gustavo Iñiguez Goia
51779e8b8d
updated ebpf makefile
- Added -fno-stack-protector:
   https://lore.kernel.org/bpf/194f38f2dc7d521375e5a660baaf1be31536be9a.camel@gmail.com/
   https://reviews.llvm.org/D142046

 - Added -Wno-unused-value, -Wunused to warn on unitialized/not used
   variables.

kudos to @planetoryd for reporting this (#1080).
2024-02-06 00:18:16 +01:00
Gustavo Iñiguez Goia
dddfdc924e
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
2024-02-02 14:16:16 +01:00
Gustavo Iñiguez Goia
785500cd08
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
2024-01-28 01:10:00 +01:00
Gustavo Iñiguez Goia
c118058dd8
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.
2024-01-26 20:58:07 +01:00
Gustavo Iñiguez Goia
27509d6fe0
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().
2024-01-26 20:50:50 +01:00
Gustavo Iñiguez Goia
55678b4d3b
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.
2024-01-26 14:48:44 +01:00
Gustavo Iñiguez Goia
d55e567dd8
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.
2024-01-26 14:16:43 +01:00
Gustavo Iñiguez Goia
c1ba2add20
fixed debug msg printing resolved IP 2024-01-25 16:00:49 +01:00
Gustavo Iñiguez Goia
016f4842ff
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.
2024-01-22 12:54:10 +01:00